Search code examples
pythongeojsonfolium

Issues with accessing GeoJSON fields


When I'm trying to add a GeoJson Tooltip:

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

And get an assertion error:

AssertionError: The field feature.properties.NTAName is not available in the data. Choose from: ('BoroCode', 'BoroName', 'CountyFIPS', 'NTACode', 'NTAName', 'Shape_Leng', 'Shape_Area').

The JSON in question looks like this:

{'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],
...

I think I might have syntax for accessing filed completely wrong, but every alternative I could think of, yielded the same result.


Solution

  • Turns out, I had to address exactly the name of the property, ignoring all hierarchy. Which is odd.

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