Skip to content

Conversation

wietzesuijker
Copy link
Contributor

TiTiler defaults to EPSG:4326 when ds.rio.crs returns None after Zarr I/O, causing validation errors on native UTM coordinates (e.g., treating 600000 meters as longitude degrees).

Solution
Embed proj:epsg and proj:code in dataset attrs so rioxarray reconstructs CRS after Zarr write/read cycle.

Changes

  • Add _embed_crs_in_attrs() helper
  • Call from prepare_dataset_with_crs_info()
  • Add validation test test_crs_fix.py

Impact

  • Fixes TiTiler 500 errors on UTM datasets
  • Enables correct tile rendering in STAC browser

Copy link

@j08lue j08lue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls use the existing tests dir and refactor this to use pytest.

test_crs_fix.py Outdated
Comment on lines 46 to 47
assert "proj:epsg" in ds_prepared.attrs, "proj:epsg not found in dataset attrs"
assert "proj:code" in ds_prepared.attrs, "proj:code not found in dataset attrs"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emmanuelmathot, do we have attribute validation implemented somewhere already, e.g. using pydantic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that I'm aware of. The focused assertions here work for CRS metadata validation, but if there's a project-wide schema validation approach, I'd be happy to align with that!

TiTiler defaults to EPSG:4326 when ds.rio.crs is None, causing validation
errors on UTM coordinates. Extract helper to embed proj:epsg in attrs so
rioxarray reconstructs CRS after Zarr I/O.
@emmanuelmathot
Copy link
Contributor

TiTiler defaults to EPSG:4326 when ds.rio.crs returns None after Zarr I/O, causing validation errors on native UTM coordinates (e.g., treating 600000 meters as longitude degrees).

How do you reproduce that? in titiler-eopf, the xarray open_dataset with decode_coordinates uses the grid_mapping and the crs is fine. I am curious to understand the context.

proj:epsg and proj:code are not standard, just copied from STAC. rioxarray does not read them: https://corteva.github.io/rioxarray/stable/getting_started/crs_management.html

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.

3 participants