Repository navigation
Only treat an axis-aligned rectangle as a bounding box - #52
Merged
Merged
Conversation
Feature.is_rectangle() counted distinct longitudes and latitudes, so a right triangle such as (0,0) (1,0) (0,1) -- two of each -- passed as a rectangle. osm_planet_extract --toolchain=osmium then cut its whole bounding box instead of the polygon. A Polygon is now a rectangle only if its single ring has exactly the four corners of its bounding box, walked edge by edge (not a bowtie), with no holes. A MultiPolygon is always cut as a polygon. Other geometries, including the LineString that set_bbox() builds, still stand for their bounding box; a LineString with three or more distinct coordinates used to fall through to an osmium config key osmium doesn't accept. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hv2rprxPj2ScEMwrNt7U7Y
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The implementation matches the stated behavior and has focused coverage; only a minor docstring correction remains.
Review effort: Balanced
Findings: 1
What changed in this PR
Fixes rectangle detection so osmium preserves non-rectangular polygon boundaries.
Changes:
- Validates exact axis-aligned polygon corners and traversal.
- Treats multipolygons as polygons and other geometries as bounding boxes.
- Adds comprehensive geometry tests.
| File | Description |
|---|---|
planetutils/bbox.py |
Implements robust rectangle detection. |
tests/test_bbox.py |
Covers rectangle and non-rectangle geometries. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hv2rprxPj2ScEMwrNt7U7Y
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.

Found by Copilot's review of #51.
Feature.is_rectangle()counted distinct longitudes and latitudes, so a right triangle such as(0,0) (1,0) (0,1), which has only two of each, passed as a rectangle.osm_planet_extract --toolchain=osmiumthen cut the triangle's whole bounding box instead of the polygon. (#51 works around this for SliceOSM by sending every polygon as GeoJSON. This fixes the underlying check.)New rule
LineStringthatset_bbox()builds for--bboxand CSV rows, and aPoint.A side effect for other geometries: a LineString with three or more distinct coordinates used to fail the old count, which produced an osmium config key (
linestring) that osmium doesn't accept. It now uses its bounding box.Errors only go one way now. A rectangle drawn with an extra vertex on an edge is treated as a polygon, which is correct, just not the bbox shortcut. A non-rectangle can no longer be cut as a box.
Testing
tests/test_bbox.py:is_rectangletests are unchanged and still pass.ruff checkis clean.examples/san-francisco-downtown.osm.pbfwith a right-triangle extent: 19,929 nodes, against 30,165 before the fix, when the bounding box was cut.🤖 Generated with Claude Code
https://claude.ai/code/session_01Hv2rprxPj2ScEMwrNt7U7Y