From 18409712038cc1214b0819603aea1d7512999115 Mon Sep 17 00:00:00 2001 From: snowman2 Date: Thu, 11 Jun 2020 10:05:58 -0500 Subject: [PATCH 1/2] Fix open_rasterio() for WarpedVRT with specified src_crs (pydata/xarray/pull/4104) --- docs/history.rst | 1 + rioxarray/_io.py | 7 +++++-- test/integration/test_integration__io.py | 13 +++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/docs/history.rst b/docs/history.rst index e8abdbc0..c4ebb6d4 100644 --- a/docs/history.rst +++ b/docs/history.rst @@ -7,6 +7,7 @@ History - ENH: Added optional `shape` argument to `rio.reproject` (pull #116) - Fix ``RasterioDeprecationWarning`` (pull #117) - BUG: Make rio.shape order same as rasterio dataset shape (height, width) (pull #121) +- Fix open_rasterio() for WarpedVRT with specified src_crs (pydata/xarray/pull/4104 & pull 120) 0.0.26 ------ diff --git a/rioxarray/_io.py b/rioxarray/_io.py index ea2d249c..6681eb46 100644 --- a/rioxarray/_io.py +++ b/rioxarray/_io.py @@ -651,14 +651,17 @@ def open_rasterio( 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, ) diff --git a/test/integration/test_integration__io.py b/test/integration/test_integration__io.py index f77cb2d5..d7d53fe4 100644 --- a/test/integration/test_integration__io.py +++ b/test/integration/test_integration__io.py @@ -857,6 +857,19 @@ def test_rasterio_vrt_network(self): assert_equal(actual_res, expected_res) assert_equal(expected_val, actual_val) + 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.from_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 rioxarray.open_rasterio(vrt) as da: + assert da.rio.crs == src_crs + def test_open_cog(): cog_file = os.path.join(TEST_INPUT_DATA_DIR, "cog.tif") From b5fe2862f90b246e60359499c26ff4b6a17fa61d Mon Sep 17 00:00:00 2001 From: snowman2 Date: Fri, 12 Jun 2020 08:41:49 -0500 Subject: [PATCH 2/2] remove unnecessary import --- test/integration/test_integration__io.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/integration/test_integration__io.py b/test/integration/test_integration__io.py index d7d53fe4..bcf901d8 100644 --- a/test/integration/test_integration__io.py +++ b/test/integration/test_integration__io.py @@ -859,8 +859,6 @@ def test_rasterio_vrt_network(self): 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.from_epsg(32618)