Skip to content

Assign and map a CRS in one step #29

Open

Description

@benbovy

This might be a question out of the scope of the PR, but I'm wondering about the need to raise a warning or something if assign_crs is used without subsequently calling map_crs to avoid getting into logically inconsistent situations. Maybe link map_crs in the assign_crs API docs too?

For example, you can assign_crs without warning or error, but then as soon as you try to access one of the .crs values you hit:

ValueError: found multiple CRS in Dataset or DataArray:
spatial_ref: EPSG:32610
lat: EPSG:4326

Originally posted by @scottyhq in #27 (comment)

Activity

  1. benbovy commented on Jun 10, 2025

    @benbovy
    MemberAuthor

    (copied from the same comment thread)

    Maybe we could allow something like this:

    temp = ds_geo_wgs84.proj.assign_crs(
        spatial_ref=("epsg:4322", ["lat", "lon"]),
        allow_override=True
    )

    I.e., both the new CRS and the coordinates to map that CRS are passed together as a 2-length tuple to .proj.assign_crs(). Note that pyproj.CRS.from_user_input() may also accept a 2-length tuple in the form (‘epsg’, ‘4322’) but that's probably not a big deal.

    We could also try to track the CRSes in a Dataset that have been mapped from spatial reference coordinates to other coordinates (or even data variables #21) at the xproj accessor level, but that's tricky to do it right in a lossless way across Xarray operations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions