corteva / rioxarray

geospatial xarray extension powered by rasterio
https://corteva.github.io/rioxarray
Other
511 stars 81 forks source link

Xarray concat does not take into account different CRS data #568

Open gcaria opened 2 years ago

gcaria commented 2 years ago
import rasterio as rxr

da1 = xr.DataArray([[0,1], [1,0]], coords=dict(y=[1,0], x=[0,1]))
da1['time'] = 0

da2 = da1.copy()
da2['time'] = 1

da1 = da1.rio.write_crs(32610)
da2 = da2.rio.write_crs(32611)

xr.concat([da1, da2], dim='time').rio.crs # returns 32610

This snippet shows that when concatenating two DataArrays with different CRS, the result gets the CRS of the first DataArray. It seems this is due to the fact that the true CRS information is given as attributes of thespatial_ref coordinate, whose numerical value is the same for both CRSs and does not actually mean anything.

Is this a feature or a bug?

snowman2 commented 2 years ago

xarray is unaware of the spatial information during it's operations. You have to manage it yourself in the current state.

This is something that requires more changes to xarray to have either an error or automagically work.

For more information:

snowman2 commented 2 years ago

For now, I recommend using rio.reproject_match

snowman2 commented 1 year ago

Related #588