gpt4 book ai didi

javascript - 如何在 typescript 中访问geoJson坐标数组?

转载 作者:行者123 更新时间:2023-11-28 03:32:47 25 4
gpt4 key购买 nike

由于读取原因,我缩短了以下 GeoJSON 输出:

geoDefinition:
features: Array(1)
0:
geometry:
coordinates: Array(1)
0: Array(5)
0: (2) [5.39014, 43.279295]
1: (2) [5.393069, 43.279249]
2: (2) [5.391814, 43.278421]
3: (2) [5.390709, 43.278749]
4: (2) [5.39014, 43.279295]
length: 5

我的目标是获取坐标数组并将其存储在另一个更通用的数组中。我在代码中写道:

   this.locations.forEach(element => {
this.polygons = element.geoDefinition.features[0].geometry.coordinates;

虽然定义了 feature[0],

enter image description here

几何形状仍然未定义。我无法访问几何->类型/坐标。

坐标是数组的数组:

enter image description here

有人可以告诉我我做错了什么吗?

最诚挚的问候,

最佳答案

尝试这样的事情:

这是一个有效的证明:https://stackblitz.com/edit/js-puskp8

const locations = [
{
geoDefinition:
{
features:
[{
geometry:
{
coordinates: [

[5.39014, 43.279295],
[5.39014, 43.279295],
[5.39014, 43.279295],
[5.39014, 43.279295],


]
}
}]
}
}
]


const newArr = []
locations.forEach(obj => {
newArr.push(...obj.geoDefinition.features[0].geometry.coordinates)

})

console.log('copied array is', newArr)

关于javascript - 如何在 typescript 中访问geoJson坐标数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58024985/

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