Skip to content

fix(s2): compute spatial:bbox and spatial:transform from pixel edges - #275

Merged
emmanuelmathot merged 1 commit into
mainfrom
fix/266-spatial-bbox-pixel-edges
Sep 24, 2026
Merged

emmanuelmathot merged 1 commit into
mainfrom
fix/266-spatial-bbox-pixel-edges

Conversation

@emmanuelmathot

Copy link
Copy Markdown
Contributor

Fixes #266.

The S2 converter calculated spatial:bbox and the spatial:transform origin from the x/y coordinates. These coordinates are pixel centres, but the groups declare spatial:registration: "pixel". The footprint was therefore half a pixel too small on each side.

Changes

  • _transform_from_coordinates: the origin is now the outer pixel edge. It now agrees with rio.transform, so _preferred_spatial_transform can select the rio transform again.
  • New _bbox_from_coordinates: calculates the bbox from that transform and the grid shape. If an axis has fewer than 2 pixels, it uses the coordinate extent, as before.
  • write_geo_metadata (each level) and add_multiscales_metadata_to_parent (pyramid parent) both use the new helper, so the parent bbox now agrees with its finest level.
  • Two tests that encoded the old centre-based origin are updated. They now also check spatial:bbox for one level and for the parent.

Notes for reviewers

🤖 Generated with Claude Code

Coordinates are pixel centres, but spatial:registration is "pixel", so the
bbox and the transform origin must be at the outer pixel edges. Calculate the
bbox in one helper and use it for each level and for the multiscale parent,
so that the parent footprint agrees with its levels.

Fixes #266

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

Fix correct bounds for spatial:bbox attributes due to mismatch/offset between coords and bounds

1 participant