Skip to content

Commit

Permalink
Fix open_rasterio() for WarpedVRT with specified src_crs (#4104)
Browse files Browse the repository at this point in the history
* Test open_rasterio() support of WarpedVRT with specified src_crs

* Pass additional WarpedVRT params when recreating in open_rasterio()

* Add description to `whats-new.rst`

* Update doc/whats-new.rst

Co-authored-by: Deepak Cherian <[email protected]>
  • Loading branch information
dtpc and dcherian authored Jun 5, 2020
1 parent 09df5ca commit 274bd4b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ Bug fixes
By `Mathias Hauser <https://github.com/mathause>`_.
- Fix html repr in untrusted notebooks: fallback to plain text repr. (:pull:`4053`)
By `Benoit Bovy <https://github.com/benbovy>`_.
- Fix :py:func:`open_rasterio` for ``WarpedVRT`` with specified ``src_crs``. (:pull:`4104`)
By `Dave Cole <https://github.com/dtpc>`_.

Documentation
~~~~~~~~~~~~~
Expand Down
7 changes: 5 additions & 2 deletions xarray/backends/rasterio_.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
13 changes: 13 additions & 0 deletions xarray/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 274bd4b

Please sign in to comment.