Fix default bounds incorrect with Copernicus Marine EPSG:4326 data#32
Merged
Shane98c merged 1 commit intocarbonplan:mainfrom Mar 6, 2026
Merged
Conversation
|
@james-willis is attempting to deploy a commit to the carbonplan Team on Vercel. A member of the Team first needs to authorize it. |
When rendering Copernicus Marine data without explicit proj4 string, the western hemisphere was missing because coordinate arrays slightly exceed [-180, 180] due to half-pixel expansion (e.g., xMin: -180.04166). The lonToMercatorNorm() function was wrapping these values (e.g., -180.04 became +179.96), causing mercatorBounds to collapse to a tiny sliver. Fix: Change lonToMercatorNorm() to always clamp to [-180, 180] instead of wrapping. Wrapping doesn't make sense for real geographic data - values outside the range are due to half-pixel expansion or floating point precision, not actual wraparound. Fixes carbonplan#28
4862a94 to
317e8d9
Compare
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Shane98c
approved these changes
Mar 6, 2026
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
Fix rendering issue where western hemisphere was missing when displaying Copernicus Marine EPSG:4326 data without explicit
proj4string.Fixes #28
Root Cause
Copernicus Marine data has coordinates like
xMin: -180.04166due to half-pixel expansion at array edges. ThelonToMercatorNorm()function was wrapping these values (-180.04→+179.96), causingmercatorBoundsto collapse to a tiny sliver instead of spanning the full globe.Fix
Change
lonToMercatorNorm()to clamp to [-180, 180] instead of wrapping.Why removing wraparound is safe
The old wraparound logic (
lon > 180→lon - 360) was intended to handle datasets using 0-360° longitude conventions. However:It was already broken - wraparound only handled individual values, not the relationship between bounds. A dataset from 140° to 220° would produce
x0 > x1, breaking bounds entirely.No real use case - Zarr datasets are typically regional (well within ±180°), global with standard coordinates, or use projected CRS. Antimeridian-crossing data would be stored as separate regions or in a projected CRS, not with wrapped longitudes.
Clamping is correct - Values slightly outside [-180, 180] are due to half-pixel expansion or floating point precision, not actual wraparound.