Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix open_rasterio() for WarpedVRT with specified src_crs #4104

Merged
merged 4 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,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 open_rastario() for WarpedVRT with specified src_crs. (:pull:`4104`)
dcherian marked this conversation as resolved.
Show resolved Hide resolved
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