[Python] Folium + GeoPandas plot rendering Issue: missing geometries (despite existing)

Discussão em 'Python' iniciado por Stack, Janeiro 27, 2025.

  1. Stack

    Stack Membro Participativo

    Can someone help me understand why my approach for creating a basemap in folium with geopandas is problematic?

    I have aggregated counts that I want to pass as a popup using folium and geopandas. I have a dummy example dataframe (gdf_raw) that has the 9 regions of interest, the geometry of the region (polygons), and a popup_info column with dummy entries. This one, while not clean, at least renders the base map.

    But when I try using it on my intended counts with agg_gdf, I get the following error: "Cannot render objects with any missing geometries" f": {data!r}"

    I don't understand why this is problematic though. The agg_gdf it has the same columns as the original, plus a column for date and a column for the count. Even if I remove those columns it errors as if geometry is missing, but from what I can tell the rows are populated with their appropriate polygons.

    Any insight as to what I'm doing wrong?

    Problematic Code:

    folium.GeoJson(
    agg_gdf,
    name='geojson',
    style_function=lambda feature: {
    'fillColor': region_colors[feature["properties"]["region"]],
    'color': 'black',
    'weight': 2,
    'fillOpacity': 0.5,
    },

    tooltip=folium.features.GeoJsonTooltip(
    fields=["region"],
    aliases=["Region:"],
    localize=True,
    ),
    popup=folium.features.GeoJsonPopup(
    fields=["popup_info"],
    aliases=["Region:"],
    localize=True,
    ),

    ).add_to(base_map)


    Code that works Fine:

    folium.GeoJson(
    gdf_raw,
    name='geojson',
    style_function=lambda feature: {
    'fillColor': region_colors[feature["properties"]["region"]],
    'color': 'black',
    'weight': 2,
    'fillOpacity': 0.5,
    },

    tooltip=folium.features.GeoJsonTooltip(
    fields=["region"],
    aliases=["Region:"],
    localize=True,
    ),
    popup=folium.features.GeoJsonPopup(
    fields=["region"],
    aliases=["Region:"],
    localize=True,
    ),
    ).add_to(base_map)


    [​IMG] [​IMG] [​IMG]

    Continue reading...

Compartilhe esta Página