在不借助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)
}
}
}