read(dst: Union[str, tuple,], resolution: Union[tuple, list, float] = None, size: Union[tuple, list] = None, resampling: rasterio.enums.Resampling = Resampling.nearest, masked: bool = True, indexes: Union[int, list] = None, chunks: Union[int, tuple, dict] = None, as_type: Any = None, **kwargs) Union[xarray.core.dataset.Dataset, xarray.core.dataarray.DataArray][source]#

Read a raster dataset from a :

  • xarray (compatibility issues)

  • rasterio.Dataset

  • rasterio opened data (array, metadata)

  • a path.

The resolution can be provided (in dataset unit) as:

  • a tuple or a list of (X, Y) resolutions

  • a float, in which case X resolution = Y resolution

  • None, in which case the dataset resolution will be used

Uses rioxarray.open_rasterio. For Dask usage, you can look at the rioxarray tutorial.

>>> raster_path = "path/to/raster.tif"
>>> xds1 = read(raster_path)
>>> # or
>>> with as dst:
>>>    xds2 = read(dst)
>>> xds1 == xds2
  • dst (PATH_ARR_DS) – Path to the raster or a rasterio dataset or a xarray

  • resolution (Union[tuple, list, float]) – Resolution of the wanted band, in dataset resolution unit (X, Y)

  • size (Union[tuple, list]) – Size of the array (width, height). Not used if resolution is provided.

  • resampling (Resampling) – Resampling method

  • masked (bool) – Get a masked array

  • indexes (Union[int, list]) – Indexes to load. Load the whole array if None. Starts at 1.

  • chunks (int, tuple or dict) – Chunk sizes along each dimension, e.g., 5, (5, 5) or {‘x’: 5, ‘y’: 5}. If chunks is provided, it used to load the new DataArray into a dask array. Chunks can also be set to True or “auto” to choose sensible chunk sizes according to dask.config.get(“array.chunk-size”).

  • as_type (Any) – Type in which to load the array

  • **kwargs – Optional keyword arguments to pass into rioxarray.open_rasterio().


Masked xarray corresponding to the raster data and its meta data

Return type