Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geojson: allow null geometry objects #1858

Merged
merged 3 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions folium/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,8 @@ def warn_for_geometry_collections(self) -> None:
geom_collections = [
feature.get("properties") if feature.get("properties") is not None else key
for key, feature in enumerate(self._parent.data["features"])
if feature["geometry"]["type"] == "GeometryCollection"
if feature["geometry"]
and feature["geometry"]["type"] == "GeometryCollection"
]
if any(geom_collections):
warnings.warn(
Expand All @@ -1136,7 +1137,11 @@ def render(self, **kwargs) -> None:
"""Renders the HTML representation of the element."""
figure = self.get_root()
if isinstance(self._parent, GeoJson):
keys = tuple(self._parent.data["features"][0]["properties"].keys())
keys = tuple(
self._parent.data["features"][0]["properties"].keys()
if self._parent.data["features"]
else []
)
self.warn_for_geometry_collections()
elif isinstance(self._parent, TopoJson):
obj_name = self._parent.object_path.split(".")[-1]
Expand Down
14 changes: 11 additions & 3 deletions folium/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,18 @@ def iter_coords(obj: Any) -> Iterator[Tuple[float, ...]]:
if isinstance(obj, (tuple, list)):
coords = obj
elif "features" in obj:
coords = [geom["geometry"]["coordinates"] for geom in obj["features"]]
coords = [
geom["geometry"]["coordinates"]
for geom in obj["features"]
if geom["geometry"]
]
elif "geometry" in obj:
coords = obj["geometry"]["coordinates"]
elif "geometries" in obj and "coordinates" in obj["geometries"][0]:
coords = obj["geometry"]["coordinates"] if obj["geometry"] else []
elif (
"geometries" in obj
and obj["geometries"][0]
and "coordinates" in obj["geometries"][0]
):
coords = obj["geometries"][0]["coordinates"]
else:
coords = obj.get("coordinates", obj)
Expand Down