gpt4 book ai didi

javascript - 从多个 GeoJSON 字符串创建 FeatureCollection

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

我有一个特征列表,我想创建一个 FeatureCollection 将它们分组到一个字符串中,这些特征来自不同的类型(多边形、线和点)。

它们是这样写的:

{
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [
[
-31.640625,
15.623036831528264
],
[
-2.8125,
-14.264383087562637
],
[
-22.5,
-30.751277776257812
],
[
-30.937499999999996,
-38.54816542304657
]
]
}
}

{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-24.960937499999996,
29.84064389983441
],
[
-2.109375,
21.616579336740603
],
[
2.4609375,
43.068887774169625
],
[
-31.289062500000004,
49.38237278700955
],
[
-24.960937499999996,
29.84064389983441
]
]
]
}
}

是否有处理此问题的 javascript 函数,我一直在研究它。

最佳答案

如果您有一个 GeoJSON 特征字符串数组,您可以像这样创建一个 GeoJSON 特征集合字符串:

var features = [
'{ "type": "Feature", "properties": {}, ... }',
'{ "type": "Feature", "properties": {}, ... }'
];
var collection = JSON.stringify({
features: features.map(JSON.parse),
type: 'FeatureCollection'
});

关于javascript - 从多个 GeoJSON 字符串创建 FeatureCollection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39856959/

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