Skip to content

Fix TopoJson non-collection geometries#2250

Open
KhadeerBasha1232 wants to merge 1 commit into
python-visualization:mainfrom
KhadeerBasha1232:fix-topojson-polygon
Open

Fix TopoJson non-collection geometries#2250
KhadeerBasha1232 wants to merge 1 commit into
python-visualization:mainfrom
KhadeerBasha1232:fix-topojson-polygon

Conversation

@KhadeerBasha1232

Copy link
Copy Markdown

Fixes #1816

Problem

When a TopoJSON's objects entry had a type of Polygon or
MultiPolygon (instead of GeometryCollection), folium raised:

KeyError: 'geometries'

This happened because the code assumed every object had a geometries
key and didn't handle "bare" geometry objects that store their arcs
directly.

Fix

Updated the TopoJson handling in folium/features.py so it also
supports non-collection geometry types (Polygon, MultiPolygon,
etc.), not just GeometryCollection.

Testing

Reproduced the exact example from #1816 — it rendered without the
KeyError after this change. Ran the existing test suite locally with
python -m pytest tests --ignore=tests/selenium and all tests pass.

@KhadeerBasha1232

Copy link
Copy Markdown
Author

This fixes #1816 — TopoJson raised a KeyError('geometries') when the
topology object's type was Polygon or MultiPolygon instead of
GeometryCollection, since the code assumed every object had a
geometries key.

Fix checks type first and falls back to treating the object itself
as a single-item geometry list when it's not a GeometryCollection.

Added a parametrized test covering both Polygon and MultiPolygon cases.
All existing tests + pre-commit checks pass locally. Happy to make any
changes if needed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TopoJSON fails with Polygon/MultiPolygon objects

1 participant