red*_*ift 7 geojson leaflet mapbox
如何将点作为单个要素添加到多边形?根据GeoJson规范,这被称为"GeometryCollection".
'GeometryCollection'的示例:
{ "type": "GeometryCollection",
"geometries": [
{ "type": "Point",
"coordinates": [100.0, 0.0]
},
{ "type": "LineString",
"coordinates": [ [101.0, 0.0], [102.0, 1.0] ]
}
]
}
Run Code Online (Sandbox Code Playgroud)
我尝试在多边形特征中添加一个点,但我无法在地图集地图上显示它,因为我猜它是无效的GeoJson.
任何人都知道这样做的正确方法是什么?网上没有太多的例子可供使用.
我的看法:[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
]
]
]
}
]
}
]
};
Run Code Online (Sandbox Code Playgroud)
如GeoJSON规范中所述,Feature对象只有一个 geometry成员,它是一个Geometry对象(或null).
要素对象必须具有名称的成员
"geometry".几何成员的值是上面定义的几何对象或JSON null值.
在可能geometry的情况下,你确实可以使用a 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
]
]
]
}
]
}
}]
};
Run Code Online (Sandbox Code Playgroud)
更新了jsfiddle:http://jsfiddle.net/rh8ok5t8/18/
我不确定您实际上想要完成什么,因为您说您想创建一个几何集合,但在您的示例中您正在创建一个到目前为止并不相同的特征集合。
特征集合是特征的集合:
类型为“FeatureCollection”的 GeoJSON 对象是要素集合对象。“FeatureCollection”类型的对象必须具有名为“features”的成员。“features”对应的值是一个数组。
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]]]
}
}]
}
Run Code Online (Sandbox Code Playgroud)
几何集合是单个要素(您可以将其包含在要素集合中):
类型为“Feature”的 GeoJSON 对象是要素对象。要素对象必须具有名为“geometry”的成员。几何成员的值是上面定义的几何对象或 JSON null 值。功能对象必须有一个名为“properties”的成员。Properties 成员的值是一个对象(任何 JSON 对象或 JSON null 值)。如果某个要素具有常用标识符,则该标识符应作为名称为“id”的要素对象的成员包含在内。
http://geojson.org/geojson-spec.html#feature-objects
具有多种几何形状:
类型为“GeometryCollection”的 GeoJSON 对象是表示几何对象集合的几何对象。几何集合必须有一个名为“geometry”的成员。“geometry”对应的值是一个数组。该数组中的每个元素都是一个 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]]]
}]
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9677 次 |
| 最近记录: |