read#

read(dst: typing.Union[str, tuple, rasterio.io.DatasetReader], resolution: typing.Union[tuple, list, float] = None, size: typing.Union[tuple, list] = None, resampling: rasterio.enums.Resampling = Resampling.nearest, masked: bool = True, **kwargs) -> (<class 'numpy.ma.core.MaskedArray'>, <class 'dict'>)[source]#

Read a raster dataset from a rasterio.Dataset or 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

Tip: Use index with a list of one element to keep a 3D array

>>> raster_path = "path/to/raster.tif"
>>> raster1, meta1 = read(raster_path)
>>> # or
>>> with rasterio.open(raster_path) as dst:
>>>    raster2, meta2 = read(dst)
>>> raster1 == raster2
True
>>> meta1 == meta2
True
Parameters
  • dst (PATH_ARR_DS) – Path to the raster, its dataset, its xarray or a tuple containing its array and metadata

  • 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 (nearest by default)

  • masked (bool) – Get a masked array, True by default (whereas it is False by default in rasterio)

  • **kwargs – Other dst.read() arguments such as indexes.

Returns

Masked array corresponding to the raster data and its meta data

Return type

np.ma.masked_array, dict