Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRS setting and copying #252

Closed
sehHeiden opened this issue Feb 22, 2021 · 3 comments
Closed

CRS setting and copying #252

sehHeiden opened this issue Feb 22, 2021 · 3 comments
Labels
bug Something isn't working wontfix This will not be worked on

Comments

@sehHeiden
Copy link

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
@sehHeiden sehHeiden added the bug Something isn't working label Feb 22, 2021
@snowman2
Copy link
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.

@snowman2 snowman2 added the wontfix This will not be worked on label Feb 22, 2021
@snowman2
Copy link
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)

@snowman2
Copy link
Member

snowman2 commented Jun 2, 2022

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
Labels
bug Something isn't working wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants