首页 > 解决方案 > 访问 GeoJSON 字段的问题

问题描述

当我尝试添加 GeoJson 工具提示时:

choropleth.geojson.add_child(folium.features.GeoJsonTooltip(fields=['feature.properties.NTAName'], labels=False))

并得到一个断言错误:

AssertionError:字段 feature.properties.NTAName 在数据中不可用。选择:('BoroCode'、'BoroName'、'CountyFIPS'、'NTACode'、' NTAName '、'Shape_Leng'、'Shape_Area')。

有问题的 JSON 如下所示:

{'type': 'FeatureCollection',
 'crs': {'type': 'name',
  'properties': {'name': 'urn:ogc:def:crs:OGC:1.3:CRS84'}},
 'features': [{'type': 'Feature',
   'properties': {'BoroCode': 3,
    'BoroName': 'Brooklyn',
    'CountyFIPS': '047',
    'NTACode': 'BK43',
    'NTAName': 'Midwood',
    'Shape_Leng': 27996.5910663,
    'Shape_Area': 35799638.2503},
   'geometry': {'type': 'Polygon',
    'coordinates': [[[-73.94732672160579, 40.62916656720943],
...

我想我可能有完全错误的访问归档的语法,但我能想到的每一个替代方案都产生了相同的结果。

标签: pythongeojsonfolium

解决方案


事实证明,我必须准确地处理属性的名称,而忽略所有层次结构。这很奇怪。

choropleth.geojson.add_child(folium.features.GeoJsonTooltip(fields=['NTAName'], labels=False))

推荐阅读