SuperMap iClient3D for Cesium shortest path analysis

Author: Mei

foreword

   In traffic and firefighting business scenarios, if a fire or traffic accident occurs in a certain place, it is necessary to quickly plan the shortest rescue route, which requires the shortest path analysis function in network analysis. Next, follow the editor to see how to implement the shortest path analysis in a 3D scene.

Implementation ideas

   First, build a network dataset through two-dimensional lines in iDesktop, and then publish the network analysis service through iServer. The front-end calls the SuperMap.REST.FindPathService interface, and the result after successful return is the shortest path analysis result data.

Implementation steps

1. Construct a two-dimensional network dataset

   In the process of collecting and editing spatial data, some errors will inevitably occur. For example, the same node or the same line is digitized twice. These errors often produce topological errors such as false nodes, redundant nodes, dangling lines, and repeated lines, which lead to the inconsistency between the topological relationship between the collected spatial data and the topological relationship of the actual ground objects, which will affect the subsequent data processing and analysis work, and affect the quality and availability of data.

1.1 Topology check

   Function entry: data-topology-topology check.
   The first thing to do is to check the topology of the line data. The topology check is to check out the objects that do not conform to the topological rules between the point, line, and area datasets themselves and different types of datasets. This is the premise of building a network dataset, and it is also convenient for topology preprocessing later.
   For example, here the "no intersection within line" check is performed on the line dataset to check whether there is a line object in the line dataset that intersects with the line of the reference line dataset, that is, all line objects in the two line datasets must be separated from each other. Intersection points will be generated into the resulting dataset as topological errors. The line data is then processed according to the error results.
insert image description here

1.2 Line topology dataset processing

   Function entry: data-topology-line data topology processing.
Topology processing is the process of repairing topology errors or avoiding topology errors. Here, the topological processing is mainly performed on the line dataset, and the operation of constructing a surface dataset or a network dataset can be performed on the processed line dataset.
insert image description here

1.3 Constructing a two-dimensional network dataset

   Functional entry: traffic analysis - topology network construction - two-dimensional network construction.
insert image description here
insert image description here

2. Publish network analysis service

   Publish the workspace containing the two-dimensional network dataset in iServer, and select the traffic network analysis service as the service.
insert image description here

   After clicking Next, read the fields of the corresponding network dataset to fill in. Note that the weight field information needs to be selected, as an important parameter in network analysis, here is the geometric information of the dataset (the length of the 'Shape_leng' line segment, if there is no such attribute field in the data, you can add a field to the dataset on the desktop and calculate the length).
insert image description here

3. Implement the code

 let nodeArray = [];
          let startP = new SuperMap.Geometry.Point(coo1[0], coo1[1]);
          let endP = new SuperMap.Geometry.Point(coo2[0], coo2[1]);
          //最短路径起始点坐标数组
          nodeArray.push(startP);
          nodeArray.push(endP);
          var findPathService, parameter, analystParameter, resultSetting;
          resultSetting = new SuperMap.REST.TransportationAnalystResultSetting({
    
    
               returnEdgeFeatures: true,
               returnEdgeGeometry: true,
               returnEdgeIDs: true,
               returnNodeFeatures: true,
               returnNodeGeometry: true,
               returnNodeIDs: true,
               returnPathGuides: true,
               returnRoutes: true
          });
          analystParameter = new SuperMap.REST.TransportationAnalystParameter({
    
    
               resultSetting: resultSetting,
               weightFieldName: "Shape_leng"//权重字段
          });
          parameter = new SuperMap.REST.FindPathParameters({
    
    
               isAnalyzeById: false,
               nodes: nodeArray,
               hasLeastEdgeCount: false,
               parameter: analystParameter
          });
      let networkURL = 
'http://localhost:8090/iserver/services/transportationAnalyst-new_NETWORL/rest/networkanalyst/Dataset_0707netWorkData_Network_1@0707netWorkData';
          //最短路径分析
          findPathService = new SuperMap.REST.FindPathService(networkURL, {
    
    
               eventListeners: {
    
     "processCompleted": processCompleted, "processFailed": processFailed }
          });
          findPathService.processAsync(parameter);
function processFailed(e) {
    
    
               // console.log(e);
               alert(e.error.errorMsg);
          }
          //路径分析成功后的回调函数
          function processCompleted(findPathEventArgs) {
    
    
               let result = findPathEventArgs.result;
               let c3Position = [];
               // console.log(result.pathList[0].route.length);
               //规划路径长度
               let saveLength = Math.ceil(result.pathList[0].route.length - 400);
               console.log(saveLength);
          if (result != null && result.pathList[0].route.components[0].components.length > 0) {
    
    
                    let pComp = result.pathList[0].route.components[0].components;
                    console.log(pComp);
               for (let i = 0; i < pComp.length - 1; i++) {
    
    
                let c3Point = new Cesium.Cartesian3.fromDegrees(pComp[i].x, pComp[i].y, 2);
                         c3Position.push(c3Point); 
                    }
                    //路线展示
                    let bestRoute = viewer.entities.add(
                         new Cesium.Entity({
    
    
                              polyline: {
    
    
                                   show: true,
                                   positions: c3Position,
                                   clampToGround: true,
                                   width: 25,
                                   material: new Cesium.PolylineGlowMaterialProperty({
    
    
                                        glowPower: 0.1, //一个数字属性,指定发光强度,占总线宽的百分比。
                                        color: Cesium.Color.WHITE
                                   }),
                                   disableDepthTestDistance: 50000
                              }
                         })
                    );
             }}

Effect screenshot:
insert image description here

Guess you like

Origin blog.csdn.net/supermapsupport/article/details/131681536