feat: accept closed LineStrings as AOI outlines on import - #7320
Open
dulcetberg wants to merge 2 commits into
Open
feat: accept closed LineStrings as AOI outlines on import#7320dulcetberg wants to merge 2 commits into
dulcetberg wants to merge 2 commits into
Conversation
Fixes hotosm#2285. GridService._adapt_feature_geometry() only accepted Polygon/MultiPolygon geometries, silently dropping (returning None) anything else - including LineStrings. This meant a closed area imported as a LineString (which is exactly what tools like geojson.io produce when converting a closed .osm way to GeoJSON) got rejected outright with "The AOI contains geometries which are not polygons or multipolygons", even though it's unambiguously a valid area outline. Now, a LineString whose first and last coordinates match (a closed ring) and has at least 4 points is converted into a Polygon using the same coordinates before the existing Polygon/MultiPolygon check runs. An open LineString (a real path, not a boundary) is still rejected, same as before - only genuinely closed rings get converted. Verified against 4 cases directly (couldn't import GridService in isolation - importing the backend package pulls in its full dependency tree beyond what this static method needs, same situation as PR hotosm#7319): - closed LineString -> now converted and accepted as a Polygon - open LineString -> still correctly rejected - existing Polygon input -> unchanged - a degenerate 3-point "closed" ring (below the 4-point minimum) -> still correctly rejected Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Signed-off-by: Brian Bergstrom <dulcetberg@gmail.com>
for more information, see https://pre-commit.ci
|
❌ The last analysis has failed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2285.
GridService._adapt_feature_geometry()(backend/services/grid/grid_service.py) only acceptedPolygon/MultiPolygongeometries, silently dropping (returningNone) anything else — includingLineStrings. This meant a closed area imported as aLineString(exactly what tools like geojson.io produce when converting a closed.osmway to GeoJSON) got rejected outright with"The AOI contains geometries which are not polygons or multipolygons", even though it's unambiguously a valid area outline.Now, a
LineStringwhose first and last coordinates match (a closed ring) and has at least 4 points is converted into aPolygonusing the same coordinates before the existingPolygon/MultiPolygoncheck runs. An openLineString(a real path, not a boundary) is still rejected, same as before — only genuinely closed rings get converted.Test plan
LineString→ now converted and accepted as aPolygon; openLineString→ still correctly rejected; existingPolygoninput → unchanged; a degenerate 3-point "closed" ring (below the 4-point minimum) → still correctly rejected.GridServicein isolation to run it against the real class — importing thebackendpackage pulls in its full dependency tree beyond what this static method needs, same situation noted in fix: recover polygon area from GeometryCollection intersections in grid trim #7319. The verification above exercises the exact logic added; deferring to CI for the full suite.🤖 Generated with Claude Code