gpt4 book ai didi

leaflet - 如何使用单点 + 多边形在 GeoJSON 中创建 GeometryCollection?

转载 作者:行者123 更新时间:2023-12-04 11:03:38 26 4
gpt4 key购买 nike

如何将点作为单个要素添加到多边形?根据 GeoJson 规范,这被称为“GeometryCollection”。

Example of a 'GeometryCollection':


{ "type": "GeometryCollection",
"geometries": [
{ "type": "Point",
"coordinates": [100.0, 0.0]
},
{ "type": "LineString",
"coordinates": [ [101.0, 0.0], [102.0, 1.0] ]
}
]
}

我尝试向多边形要素添加一个点,但无法将其显示在我的 map 框 map 上,因为我猜它是无效的 GeoJson。

有谁知道这样做的正确方法是什么?网络上没有很多例子可供引用。

My take: [jsfilddle]


var myRegions = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometries": [
{
"type": "Point",
"coordinates": [
61.34765625,
48.63290858589535
]
},
{
"type": "Polygon",
"coordinates": [
[
[
59.94140624999999,
50.65294336725709
],
[
54.931640625,
50.90303283111257
],
[
51.943359375,
51.04139389812637
],
[
50.9765625,
48.19538740833338
],
[
52.55859375,
46.46813299215554
],
[
52.998046875,
43.8028187190472
],
[
54.4921875,
42.391008609205045
],
[
57.041015625,
43.29320031385282
],
[
59.8974609375,
45.398449976304086
],
[
62.5341796875,
44.08758502824516
],
[
65.6982421875,
45.73685954736049
],
[
68.37890625,
48.3416461723746
],
[
65.8740234375,
49.18170338770663
],
[
63.720703125,
49.97948776108648
],
[
63.80859374999999,
52.348763181988076
],
[
61.4794921875,
52.32191088594773
],
[
59.9853515625,
51.86292391360244
],
[
61.9189453125,
51.09662294502995
],
[
60.5126953125,
50.51342652633956
],
[
59.94140624999999,
50.65294336725709
]
]
]
}
]
}
]
};

最佳答案

正如 GeoJSON 规范中所说, Feature object正好 geometry成员,这是一个 Geometry object (或 null)。

A feature object must have a member with the name "geometry". The value of the geometry member is a geometry object as defined above or a JSON null value.



其中可能 geometry你确实可以使用 GeometryCollection ,必须有成员 geometries .后者是其他几何图形的数组,即您的点、多边形等,甚至是另一个 GeometryCollection。

A geometry collection must have a member with the name "geometries". The value corresponding to "geometries" is an array. Each element in this array is a GeoJSON geometry object.



因此,在您的情况下,您可以简单地执行以下操作:

var myRegions = {
"type": "FeatureCollection",
"features": [{
"type": "Feature", // single feature
"properties": {},
"geometry": { // unique geometry member
"type": "GeometryCollection", // the geometry can be a GeometryCollection
"geometries": [ // unique geometries member
{ // each array item is a geometry object
"type": "Point",
"coordinates": [
61.34765625,
48.63290858589535
]
},
{
"type": "Polygon",
"coordinates": [
[
[
59.94140624999999,
50.65294336725709
],
// more points…
[
59.94140624999999,
50.65294336725709
]
]
]
}
]
}
}]
};

更新了 jsfiddle: http://jsfiddle.net/rh8ok5t8/18/

关于leaflet - 如何使用单点 + 多边形在 GeoJSON 中创建 GeometryCollection?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34044893/

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