Skip to content

Enabling rasterio.vrt.WarpedVRT with xr.open_rasterio #2588

@scottyhq

Description

@scottyhq

This is not a bug, but rather a feature request and discussion opener for changes to the open_rasterio function

Currently open_rasterio (xarray version 0.11) only accepts filepath strings and does not work with In-memory rasterio.vrt.WarpedVRT objects. I have a solution (see pull request), but it's likely not the best one (Many context managers can feel odd), see example below:

# Lazy in-memory warping from UTM to WGS84 lat/lon
with env:
    with rasterio.open(url) as src:
        da = xr.open_rasterio(src)
        print(da.crs, da.sizes)
        with WarpedVRT(src, crs='epsg:4326') as vrt:
            with xr.open_rasterio(vrt) as da:
                print(da.crs, da.sizes)

#+init=epsg:32610 (1, 7531, 7751)
#+init=epsg:4326 +no_defs (1, 5981, 9183)

More detailed gist here:
https://gist.github.com/scottyhq/ae90084adaf25e3b361b096d555c45f1

Problem description

In-memory “virtual” reprojection is a key feature of rasterio (see https://gist.github.com/sgillies/7e5cd548110a5b4d45ac1a1d93cb17a3), and it would be fantastic if this worked w/ xarray and dask distributed. Many workflows require warping between WGS84 lat/lon, UTM, Google Mercator, and rasterio can handle most any other projection.

related to: #1575, #2042, #2288
dask/dask#3255
Seems like some synergy here with geoxarray and salem
@mrocklin, @fmaussion, @geoxarray

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions