From 5776786cf4dfb5714d3c579cd55ecbbb39f3ef7d Mon Sep 17 00:00:00 2001 From: Dave Cole Date: Thu, 28 May 2020 15:04:35 +1000 Subject: [PATCH 1/4] Test open_rasterio() support of WarpedVRT with specified src_crs --- xarray/tests/test_backends.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index 49a39474b54..3642c1eb9b7 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -4160,6 +4160,19 @@ def test_rasterio_vrt_with_transform_and_size(self): assert actual_shape == expected_shape assert actual_transform == expected_transform + def test_rasterio_vrt_with_src_crs(self): + # Test open_rasterio() support of WarpedVRT with specified src_crs + import rasterio + + # create geotiff with no CRS and specify it manually + with create_tmp_geotiff(crs=None) as (tmp_file, expected): + src_crs = rasterio.crs.CRS({"init": "epsg:32618"}) + with rasterio.open(tmp_file) as src: + assert src.crs is None + with rasterio.vrt.WarpedVRT(src, src_crs=src_crs) as vrt: + with xr.open_rasterio(vrt) as da: + assert da.crs == src_crs + @network def test_rasterio_vrt_network(self): # Make sure loading w/ rasterio give same results as xarray From 1e258874416ef5aab3cc741406323e0e52154707 Mon Sep 17 00:00:00 2001 From: Dave Cole Date: Thu, 28 May 2020 15:08:47 +1000 Subject: [PATCH 2/4] Pass additional WarpedVRT params when recreating in open_rasterio() --- xarray/backends/rasterio_.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/xarray/backends/rasterio_.py b/xarray/backends/rasterio_.py index 77beffd09b1..661d5b5c6fc 100644 --- a/xarray/backends/rasterio_.py +++ b/xarray/backends/rasterio_.py @@ -221,14 +221,17 @@ def open_rasterio(filename, parse_coordinates=None, chunks=None, cache=None, loc vrt = filename filename = vrt.src_dataset.name vrt_params = dict( + src_crs=vrt.src_crs.to_string(), crs=vrt.crs.to_string(), resampling=vrt.resampling, + tolerance=vrt.tolerance, src_nodata=vrt.src_nodata, nodata=vrt.nodata, - tolerance=vrt.tolerance, - transform=vrt.transform, width=vrt.width, height=vrt.height, + src_transform=vrt.src_transform, + transform=vrt.transform, + dtype=vrt.working_dtype, warp_extras=vrt.warp_extras, ) From 01adae51560f5c7038fae29e8a828397f0c002a5 Mon Sep 17 00:00:00 2001 From: Dave Cole Date: Thu, 28 May 2020 20:05:26 +1000 Subject: [PATCH 3/4] Add description to `whats-new.rst` --- doc/whats-new.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index a32e0393bcf..27959f7f52c 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -140,6 +140,8 @@ Bug fixes By `Mathias Hauser `_. - Fix html repr in untrusted notebooks: fallback to plain text repr. (:pull:`4053`) By `Benoit Bovy `_. +- Fix open_rastario() for WarpedVRT with specified src_crs. (:pull:`4104`) + By `Dave Cole `_. Documentation ~~~~~~~~~~~~~ From 5096587e9d299cfdb2af19b69f380e4aa51d08c6 Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Fri, 29 May 2020 16:51:23 +0000 Subject: [PATCH 4/4] Update doc/whats-new.rst --- doc/whats-new.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 27959f7f52c..40844287d24 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -140,7 +140,7 @@ Bug fixes By `Mathias Hauser `_. - Fix html repr in untrusted notebooks: fallback to plain text repr. (:pull:`4053`) By `Benoit Bovy `_. -- Fix open_rastario() for WarpedVRT with specified src_crs. (:pull:`4104`) +- Fix :py:func:`open_rasterio` for ``WarpedVRT`` with specified ``src_crs``. (:pull:`4104`) By `Dave Cole `_. Documentation