python - 访问 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],
...
我想我可能有完全错误的访问归档的语法,但我能想到的每一个替代方案都产生了相同的结果。
解决方案
事实证明,我必须准确地处理属性的名称,而忽略所有层次结构。这很奇怪。
choropleth.geojson.add_child(folium.features.GeoJsonTooltip(fields=['NTAName'], labels=False))
推荐阅读
- c++ - qt 切换中央小部件时出现分段错误的程序粉碎
- c++ - 我是否必须做一些特别的事情才能使文件成为 QT C++ 中的资源文件?
- python - 如何组合具有不同名称的 2 列以用第二个的值填充第一个的空值?
- javascript - 在路由模板中使用 Vue 方法需要帮助
- vba - 错误 1004:SaveAs 方法失败,accessMode:=xlShared
- html - Youtube 和 Twitter 的 HTML href “拒绝连接”
- unity3d - 我正在尝试将标准 URP(通用渲染管道)着色器提供给我制作的网格
- pandas - 如何在熊猫中格式化日期时间字段
- php - PHP 在 LAMP DigitalOcean 中返回任何内容
- vim - 字符串中的语法高亮