GeoJSON:FeatureCollection中是否允许使用Properties?

8

我在规范中找不到任何相关信息:http://geojson.org/geojson-spec.html

一个FeatureCollection中是否允许有properties键?或者只有Feature才可以这样做?

如果是可能的话,如何在openlayers中访问属性呢? 提前感谢。

2个回答

11

规范并没有明确禁止,但是要素集合没有属性。GeoJSON规范只为FeatureCollection提到以下键:

  • type - 必须是 `FeatureCollection`。
  • features - 要素数组。
  • bbox - 整个要素集合的边界框。

从OpenLayers代码中可以看出,properties仅用于处理要素实例,而不是要素集合。


2021年还是这种情况吗? - seb007
同样的挑战对我来说,我们可以添加属性吗? - Santosh Singh
请阅读此处的答案和评论,以了解上面两位的问题 - https://gis.stackexchange.com/questions/25279/is-it-valid-to-have-a-properties-element-in-an-geojson-featurecollection - diggity

-2
切换到 Leaflet 更简单,并且它允许使用 FeatureCollection 的 GeoJSON 数据。当你点击对象时,你还可以在弹出窗口中获取属性信息。
然而,Openlayers 也可以访问 FeatureCollection。在移动端(使用 jQuery Mobile)的 Openlayers 示例中展示了访问属性的方法。

http://openlayers.org/dev/examples/mobile-jq.html#mappage

点击黑色图标,您将看到带有这些属性的弹出表单。

这是移动示例中GeoJSON的一部分。

{
    "type": "FeatureCollection",
    "features": [
        { "type": "Feature", 
          "geometry": {"type": "Point","coordinates": [1332700, 7906300]},
          "properties": {"Name": "Igor Tihonov","Country":"Sweden", "City":"Gothenburg"}
        },
        { "type": "Feature", 
          "geometry": {"type": "Point","coordinates": [790300, 6573900]},
          "properties": {"Name": "Marc Jansen","Country":"Germany", "City":"Bonn"}
        },
        { "type": "Feature", 
          "geometry": {"type": "Point","coordinates": [568600, 6817300]},
          "properties": {"Name": "Bart van den Eijnden","Country":"Netherlands", "City":"Utrecht"}
        },
        { "type": "Feature", 
          "geometry": {"type": "Point","coordinates": [-7909900, 5215100]}
        }
    ]
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接