The error compensation and suppression effects of traditional ultrawideband (UWB) ranging in non Line of Sight (NLOS) environments are limited. The contribution of specific occlusions to UWB spatial perception in NLOS is ignored. To achieve comprehensive sensing of spatial information by UWB, we initially analyze the channel impulse response (CIR) and the underlying parameters of registers during UWB communication. By comparing the difference between NLOS and line-of-sight (LOS) environments for each parameter on a continuous time series, a fast discriminative method for UWB environment conversion is proposed. Further, combining the ensemble learning XGBoost classifier, an efficient NLOS occlusion recognition method is proposed. At the same time, an algorithm optimization based on a discrete degree threshold is designed. It is based on loss function probability matrix-weighted predictive labeling. The prediction matrix of the loss function of the XGBoost algorithm is used as label weights. The UWB prediction labels of continuous time series are weighted, which mitigates the effect of low-probability data on the overall prediction results. Finally, UWB spatial sensing experiments are carried out to verify the reliability of the proposed method. The experimental results show that the mutation in the parameter profile can effectively perceive the LOS/NLOS transition. The recognition accuracy of the proposed occlusion recognition method in conditions of human, metal, and wall occlusion is 94.44%, 92.00%, and 95.87%, respectively. In contrast to the origin method, the suggested algorithm's average recognition accuracy has increased by 16.71%. Its precise recognition accuracy makes UWB spatial sensing more effective.