Skip to content
Open
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
14 changes: 12 additions & 2 deletions backend/services/grid/grid_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,22 @@ def _adapt_feature_geometry(feature: geojson.Feature) -> geojson.Feature:
:param feature: geojson.feature to be adapted
:return: feature with geometry adapted
"""
geometry = feature.geometry
if isinstance(geometry, geojson.geometry.LineString):
# A closed LineString (first/last coordinate match, at least 4
# points) is unambiguously a polygon outline. Tools like
# geojson.io convert a closed .osm way to a LineString rather
# than a Polygon, which otherwise gets rejected outright.
coordinates = geometry["coordinates"]
if len(coordinates) >= 4 and coordinates[0] == coordinates[-1]:
geometry = geojson.geometry.Polygon([coordinates])

if isinstance(
feature.geometry, (geojson.geometry.Polygon, geojson.geometry.MultiPolygon)
geometry, (geojson.geometry.Polygon, geojson.geometry.MultiPolygon)
):
# adapt the geometry for use as a shapely geometry
# http://toblerity.org/shapely/manual.html#shapely.geometry.asShape
feature.geometry = shapely.geometry.shape(feature.geometry)
feature.geometry = shapely.geometry.shape(geometry)
return feature
else:
return None
Expand Down