gpt4 book ai didi

javascript - geojson 文件格式问题,较大坐标数组内的迷你数组(坐标)

转载 作者:行者123 更新时间:2023-11-28 04:18:27 25 4
gpt4 key购买 nike

我的 geoJSON 文件:坐标键包含带有坐标的普通数组,但随后包含一个填充有更多坐标的迷你数组的数组。我无法循环遍历该文件来提取 route 心,以便将我的 Google 要素图层添加到我的 Google API 调用中。

当我尝试分解迷你数组并将其添加到整个数组中时,路线变得可见,但不正确。这条路线穿过水面,穿过建筑物,它不知道顺序。任何帮助都会很棒。粗体打破了整个功能的格局。

例如:{"type":"功能","properties":{"OBJECTID":3,"LENGTH":3919.4410000000003,"NAME":"Anacostia Riverwalk-SW","STATUS":"开放","MAINTENANC":"DDOT","Shape_Length":1194.6479669066844,"MILES":0.7423183712121213},"几何":{"类型":"MultiLineString","坐标":[[[-77.02215895389972,38.87673054256091],[-7 7.02186869854079,38.87653957420972],[ -77.02150193815677,38.87588299990856],[-77.0208280524279,38.874621556490816],[-77.02075697415529,38.87448850380858],[-77.0 2062323938105,38.874211704408985],[-77.02008845385471,38.87338800912766],[-77.01937789804083,38.87202111748801],[-77.017682 65826789,38.87204526498413]],

[[-77.02594024042205,38.87974434948391],[-77.02509229875858,38.87909983220277],[-77.0237707432032,38.8780375415248], [-77.02215132050688,38.87674248295079]]]}},

最佳答案

你所说的迷你数组只是geojson MultiLineStrings的规范。 http://geojson.org/geojson-spec.html#multilinestring

对于“MultiLineString”类型,“坐标”成员是 LineString 坐标数组的数组。

因此,每个数组都描述了一条线路的一部分,它们一起形成了最终的路线。您可以使用 2 个 for 循环(它是数组的数组)来迭代它们

var geojson = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "MultiLineString","coordinates":[
[[-77.02215895389972,38.87673054256091],[-77.02186869854079,38.87653957420972],[-77.02150193815677,38.87588299990856],[-77.0208280524279,38.874621556490816],[-77.02075697415529,38.87448850380858],[-77.02062323938105,38.874211704408985],[-77.02008845385471,38.87338800912766],[-77.01937789804083,38.87202111748801],[-77.01768265826789,38.87204526498413]],
[[-77.02594024042205,38.87974434948391],[-77.02509229875858,38.87909983220277],[-77.0237707432032,38.8780375415248],[-77.02215132050688,38.87674248295079]]
]
}
}
]
}

let coords = geojson.features[0].geometry.coordinates;
for (let i = 0; i < coords.length; i += 1) {
for (let j = 0; j < coords[i].length; j += 1) {
console.log(coords[i][j]);
}
}

关于javascript - geojson 文件格式问题,较大坐标数组内的迷你数组(坐标),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45643627/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com