Pipeline risk assessment is crucial for pipeline safety management and operation. The aim of this study is to develop a comprehensive assessment model that accurately evaluates pipeline risks and ensures the safe and reliable operation of the pipeline system. The model is based on multisource spatial data and is primarily applicable to long-distance oil and gas pipelines that traverse complex geological conditions in mountainous areas. The research is conducted using the example of the Jinliwen natural gas pipeline in Zhejiang Province, China. By analyzing the geological data of the study area and the potential risks that the pipeline may encounter, a comprehensive risk assessment indicator system for the pipeline was developed using slope units to divide pipeline sections. The pipeline risk levels are classified using the K-means clustering-entropy weighted-random forest algorithm. The model is evaluated using accuracy (Acc), precision (Pre), recall (R), F1-score, and the ROC curve. The results show that the model has an accuracy of 0.917, a precision of 0.92, a recall of 0.916, an F1-score of 0.914, and an AUC (Area Under Curve) of 0.93, indicating its strong predictive capability. The risk assessment results demonstrate a strong consistency when compared with actual incident events. This indicates that the constructed model effectively reflects the influencing factors of pipeline risk, providing a basis for pipeline risk assessment and disaster prevention and mitigation efforts in similar regions.