rio.crs seems to misbehave with geopandas.to_crs
What happened: Using rio.crs to reproject a GeoDataFrame throws an Exception, namely 'Warning 1: +init=epsg:XXXX syntax is deprecated. It might return a CRS with a non-EPSG compliant axis order.'.
What you expected to happen: Exception should not be thrown. This might be a underlying Proj issue.
Minimal Complete Verifiable Example:
# Open files
data = xr.open_dataset(path/to/file.nc)
gdf = geopandas.read_feather(path/to/feather)
# Reproject
gdf.to_crs(crs=data.rio.crs, inplace=True)
Anything else we need to know?: This might be a geopandas issue. Not exactly sure.
Environment:
Output of xr.show_versions()
<INSTALLED VERSIONS
commit: None python: 3.8.10 (default, Jun 2 2021, 10:49:15) [GCC 9.4.0] python-bits: 64 OS: Linux OS-release: 5.8.0-7642-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: 1.12.0 libnetcdf: 4.7.4
xarray: 0.19.0 pandas: 1.3.0 numpy: 1.21.0 scipy: 1.6.1 netCDF4: 1.5.7 pydap: None h5netcdf: 0.7.1 h5py: 3.1.0 Nio: None zarr: 2.4.0+ds cftime: 1.4.1 nc_time_axis: None PseudoNetCDF: None rasterio: 1.2.7 cfgrib: None iris: None bottleneck: 1.2.1 dask: 2021.03.0 distributed: 2021.03.0 matplotlib: 3.3.4 cartopy: None seaborn: 0.11.1 numbagg: None pint: 0.16.1 setuptools: 45.2.0 pip: 21.2.4 conda: None pytest: 4.6.9 IPython: 7.21.0 sphinx: None
Hi @dimzog. Thank you for taking time to report this issue. However, it seems to me that this would be better reported on the geopandas and/or rioxarray issue tracker.
@jhamman I'll be posting this in geopandas repo, thank you!
xr.open_rasterio() is being used earlier in the pipeline, i think traced back the issue in these lines of code https://github.com/pydata/xarray/blob/7bfee3eaa8fd731494cf6b406d6abb4bec061001/xarray/backends/rasterio_.py#L335-L342
There was a discussion in geopandas repo here https://github.com/geopandas/geopandas/issues/2104
@jhamman @dcherian
@dcherian adopting rioxarray breaks the code. It would be better off "fixing" crs in xarray.
This appears to not be an xarray issue since the code uses open_dataset and the rio.crs accessor. The rio.crs accessor is from rioxarray. From what I can tell, the issue has to do with the data is stored in the netCDF file: https://corteva.github.io/rioxarray/stable/getting_started/crs_management.html
My guess is that there is an attribute named crs with the contents +init=EPSG:XXXX. If that is the case, I recommend using rioxarray to do:
data.rio.write_crs("ESPG:XXXX", inplace=True)
Hopefully this is helpful.
xr.open_rasterio() is being used earlier in the pipeline
What issues do you have if you change to use rioxarray.open_rasterio?