0
点赞
收藏
分享

微信扫一扫

管线上下游关系获取

生态人 2022-04-19 阅读 43
node.js

在不借助GIS专业软件的情况下,根据管线属性中的起止点编号/名称/经纬度等获取完整的上下游管线编码/经纬度关系。

假设存在数据list,设定结果test初始值为空数组

list=[ {     ....
        "startLongitude": 111,
        "startLatitude": 38,
        "endLongitude": 111.3,
        "endLatitude": 39,
        "startCode": "",
        "endCode": "",
    },{ ....
        "startLongitude": 112,
        "startLatitude": 33,
        "endLongitude": 112,
        "endLatitude": 38,
        "startCode": "",
        "endCode": "",
    },{ ....
       "startLongitude": 111,
        "startLatitude": 40.8,
        "endLongitude": 111.1,
        "endLatitude": 39.6,
        "startCode": "",
        "endCode": "",
    },{ ....
        "startLongitude": 112.1,
        "startLatitude": 38.9,
        "endLongitude": 118,
        "endLatitude": 35,
        "startCode": "",
        "endCode": "",
    },{ ....
        "startLongitude": 114,
        "startLatitude": 32,
        "endLongitude": 115,
        "endLatitude": 36,
        "startCode": "",
        "endCode": "",
    }
]

则计算test如下

let test=[]
let length=[]//length为结果集合中数据属性中的length累积值
 for (let i = 0; i < list.length; i++) {
      test.push([
        [list[i].startLongitude, list[i].startLatitude],
        [list[i].endLongitude, list[i].endLatitude],
      ])
      // length.push(list[i].length)
    }
    for (let i = 0; i < list.length; i++) {
      for (let j = 0; j < test.length; j++) {
        if (
          list[i].startLongitude === test[j][test[j].length - 1][0] &&
          list[i].startLatitude === test[j][test[j].length - 1][1]
        ) {
          test[j].push([list[i].endLongitude, list[i].endLatitude])
          // length[j] += list[i].length
        }
        if (
          list[i].endLongitude === test[j][0][0] &&
          list[i].endLatitude === test[j][0][1]
        ) {
          test[j].unshift([list[i].startLongitude, list[i].startLatitude])
          // length[j] += list[i].length
        }
      }
    }
  })

  //去掉子集
  for (let i = 0; i < test.length; i++) {
    for (let j = i; j < test.length; j++) {
      if (test[i].join().includes(test[j].join())) {
       test.splice(j, 1)
     //length.splice(j, 1)
      }
    }
  }

//test=[
    [
        [
            111.60895809531212,
            38.80524030225348
        ],
        [
            111.60917401313782,
            38.80645260422193
        ],
        [
            111.61228135228157,
            38.80874233554218
        ],
        [
            111.61522641777992,
            38.81047081970374
        ],
        [
            111.61652058362961,
            38.810353777360035
        ],
        [
            111.61034345626831,
            38.80645051406384
        ]
    ]
]

 

举报

相关推荐

0 条评论