From 7212265decb742d2194d42d881f79e64f80eb24b Mon Sep 17 00:00:00 2001 From: snowman2 Date: Thu, 21 Apr 2022 20:37:08 -0500 Subject: [PATCH] BUG: Fix WarpedVRT param cache in open_rasterio --- docs/history.rst | 2 +- rioxarray/_io.py | 10 +++++----- test/integration/test_integration__io.py | 12 ++++++++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/docs/history.rst b/docs/history.rst index 48dea99c..102f0f3c 100644 --- a/docs/history.rst +++ b/docs/history.rst @@ -3,7 +3,7 @@ History Latest ------ - +- BUG: Fix WarpedVRT param cache in :func:`rioxarray.open_rasterio` (issue #515) 0.11.0 ------ diff --git a/rioxarray/_io.py b/rioxarray/_io.py index 5bd58dbb..86fa727b 100644 --- a/rioxarray/_io.py +++ b/rioxarray/_io.py @@ -811,15 +811,15 @@ def open_rasterio( filename = vrt.src_dataset.name vrt_params = dict( src_crs=vrt.src_crs.to_string() if vrt.src_crs else None, - crs=vrt.crs.to_string() if vrt.crs else None, + crs=vrt.dst_crs.to_string() if vrt.dst_crs else None, resampling=vrt.resampling, tolerance=vrt.tolerance, src_nodata=vrt.src_nodata, - nodata=vrt.nodata, - width=vrt.width, - height=vrt.height, + nodata=vrt.dst_nodata, + width=vrt.dst_width, + height=vrt.dst_height, src_transform=vrt.src_transform, - transform=vrt.transform, + transform=vrt.dst_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 74409231..6e087e61 100644 --- a/test/integration/test_integration__io.py +++ b/test/integration/test_integration__io.py @@ -932,6 +932,18 @@ def test_rasterio_vrt_gcps(tmp_path): ) +def test_rasterio_vrt_gcps__data_exists(): + # https://github.com/corteva/rioxarray/issues/515 + vrt_file = os.path.join(TEST_INPUT_DATA_DIR, "cint16.tif") + with rasterio.open(vrt_file) as src: + crs = src.gcps[1] + # NOTE: Eventually src_crs will not need to be provided + # https://github.com/mapbox/rasterio/pull/2193 + with rasterio.vrt.WarpedVRT(src, src_crs=crs) as vrt: + rds = rioxarray.open_rasterio(vrt) + assert rds.values.any() + + @pytest.mark.parametrize("lock", [True, False]) def test_open_cog(lock): cog_file = os.path.join(TEST_INPUT_DATA_DIR, "cog.tif")