如何将点作为单一功能添加到多边形中?根据GeoJson规范,这被称为"GeometryCollection“。
“几何集合”的示例:
{ "type": "GeometryCollection",
"geometries": [
{ "type": "Point",
"coordinates": [100.0, 0.0]
},
{ "type": "LineString",
"coordinates": [ [101.0, 0.0], [102.0, 1.0] ]
}
]
}我试图在多边形特性中添加一个点,但是我无法让它显示在mapbox地图上,因为我猜它是无效的GeoJson。
,有人知道做这件事的正确方式吗?web上没有太多的示例可供参考。。
我的观点:[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
]
]
]
}
]
}
]
};发布于 2015-12-02 14:59:06
正如在GeoJSON规范中所说的那样,对象恰好有一个 geometry成员,即几何对象 (或null)。
功能对象必须有一个名为
"geometry"的成员。几何成员的值是上面定义的几何对象或JSON空值。
在可能的geometry中,您确实可以使用一个GeometryCollection,它必须有一个成员geometries,后者是一个其他几何图形的数组,比如点、多边形等,甚至还有另一个GeometryCollection。
几何集合必须有一个名为
"geometries"的成员。与"geometries"对应的值是一个数组。这个数组中的每个元素都是一个GeoJSON几何对象。
因此,在您的情况下,您可以简单地执行以下操作:
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/
发布于 2015-12-02 14:58:54
我不确定你到底想要完成什么,因为你说你想要创建一个几何集合,但在你的例子中,你正在创建一个特征回忆,这是不一样的。
特征回忆是特征的集合:
类型为“GeoJSON”的FeatureCollection对象是一个功能集合对象。类型为"FeatureCollection“的对象必须有一个名为”功能“的成员。与“功能”对应的值是一个数组。
http://geojson.org/geojson-spec.html#feature-collection-objects
下面是一个特征回忆的例子:
{
type: "FeatureCollection",
features: [{
"type": "Feature",
"properties": {
"value": "foo"
},
"geometry": {
"type": "Point",
"coordinates": [0,0]
}
}, {
"type": "Feature",
"properties": {
"value": "bar"
},
"geometry": {
"type": "Polygon",
"coordinates": [[[45, 45], [45, -45], [-45, -45], [-45, 45], [45,45]]]
}
}]
}几何集合是一个单一的特征(您可以在一个特征回忆中包含它):
具有"Feature“类型的GeoJSON对象是一个功能对象。一个功能对象必须有一个名为“几何图形”的成员。几何成员的值是上面定义的几何对象或JSON空值。feature必须有一个名为"properties“的成员。属性成员的值是一个对象(任何JSON对象或JSON空值)。如果一个特性具有一个常用的标识符,则应该将该标识符作为名称为"id“的feature的成员。
http://geojson.org/geojson-spec.html#feature-objects
具有多个几何图形:
类型为“GeoJSON”的GeometryCollection对象是表示几何对象集合的几何对象。几何集合必须有一个名为“几何图形”的成员。与“几何图形”对应的值是一个数组。这个数组中的每个元素都是一个GeoJSON几何对象。
http://geojson.org/geojson-spec.html#geometry-collection
下面是一个几何集合特性的例子:
{
"type": "GeometryCollection",
"properties": {
"value": "foo"
},
"geometries": [{
"type": "Point",
"coordinates": [0, 0]
}, {
"type": "Polygon",
"coordinates": [[[45, 45], [45, -45], [-45, -45], [-45, 45], [45,45]]]
}]
}https://stackoverflow.com/questions/34044893
复制相似问题