Skip to content

CRS setting and copying #252

Closed
Closed

Description

@sehHeiden

I try to set the crs, and than to copy the raster. Turns out the self set crs, isn't copied.:

The functions for copying I use are write_crs and set_crs. Both give different results.

raster = open_rasterio(r"PATH\FILENAME.xyz")  # No crs set
raster.rio.write_crs(32633)  # crs is None 
raster.rio.set_crs(32633)  # result: CRS.from_epsg(32633)

crs = CRS("EPSG:32633")
raster.rio.write_crs(crs.to_wkt())  #  None
raster.rio.set_crs(crs.to_wkt())  # result: CRS.from_epsg(32633)

# when copiing the raster
raster.rio.crs  # CRS.from_epsg(32633)
r1 = raster.copy()
r1.rio.crs  # None

Problem description

The copy method only copies the original data, not the changed?

Expected Output

Environment Information

rioxarray (0.2.0) deps:
rasterio: 1.2.0
xarray: 0.16.2
GDAL: 3.1.4

Other python deps:
scipy: 1.6.0
pyproj: 3.0.0.post1

System:
python: 3.8.6 | packaged by conda-forge | (default, Jan 25 2021, 22:54:47) [MSC v.1916 64 bit (AMD64)]
executable: C:\Users\remote\anaconda3\envs\PROJEKTNAME\python.exe
machine: Windows-10-10.0.19041-SP0

Installation method

  • conda-forge

Activity

  1. snowman2 commented on Feb 22, 2021

    @snowman2
    Member

    If you want to be able to copy and have the CRS persist, you need to use rio.write_crs. Nothing can be done in rioxarray if you use rio.set_crs. Hopefully that gets you where you need to be.

  2. snowman2 commented on Feb 22, 2021

    @snowman2
    Member

    I noticed you have raster.rio.write_crs(crs.to_wkt()), so my previous comment was only partially helpful.

    You need to either:

    1. Use inplace=True
    raster.rio.write_crs(crs, inplace=True)
    1. Set the new variable with the copy:
    raster = raster.rio.write_crs(crs)
  3. snowman2 commented on Jun 2, 2022

    @snowman2
    Member

    For those finding this issue, I recommend reading the Getting Started: Introductory Information references for rioxarray. The Coordinare Reference System Management section is relevant for this issue.

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

    bugSomething isn't workingwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions