Skip to content

Commit

Permalink
Fix open_rasterio() for WarpedVRT with specified src_crs (pydata/xarr…
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 committed Jun 11, 2020
1 parent 31ee00f commit 1840971
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------
Expand Down
7 changes: 5 additions & 2 deletions rioxarray/_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
13 changes: 13 additions & 0 deletions test/integration/test_integration__io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 1840971

Please sign in to comment.