Skip to content

rio_tiler.io.xarray

rio_tiler.io.xarray

rio_tiler.io.xarray: Xarray Reader.

XarrayReader

Bases: BaseReader

Xarray Reader.

Attributes:

  • dataset (DataArray) –

    Xarray DataArray dataset.

  • tms (TileMatrixSet) –

    TileMatrixSet grid definition. Defaults to WebMercatorQuad.

Examples:

>>> ds = xarray.open_dataset(
        "https://pangeo.blob.core.windows.net/pangeo-public/daymet-rio-tiler/na-wgs84.zarr",
        engine="zarr",
        decode_coords="all",
        consolidated=True,
    )
    da = ds["tmax"]
with XarrayReader(da) as dst:
    img = dst.tile(...)

band_names property

band_names: List[str]

Return list of band names in DataArray.

maxzoom property

maxzoom

Return dataset maxzoom.

minzoom property

minzoom

Return dataset minzoom.

__attrs_post_init__

__attrs_post_init__()

Set bounds and CRS.

feature

feature(shape: Dict, dst_crs: Optional[CRS] = None, shape_crs: CRS = WGS84_CRS, reproject_method: WarpResampling = 'nearest', auto_expand: bool = True, nodata: Optional[NoData] = None, max_size: Optional[int] = None, height: Optional[int] = None, width: Optional[int] = None, resampling_method: RIOResampling = 'nearest', **kwargs: Any) -> ImageData

Read part of a dataset defined by a geojson feature.

Parameters:

  • shape (dict) –

    Valid GeoJSON feature.

  • dst_crs (CRS, default: None ) –

    Overwrite target coordinate reference system.

  • shape_crs (CRS, default: WGS84_CRS ) –

    Input geojson coordinate reference system. Defaults to epsg:4326.

  • reproject_method (WarpResampling, default: 'nearest' ) –

    WarpKernel resampling algorithm. Defaults to nearest.

  • auto_expand (boolean, default: True ) –

    When True, rioxarray's clip_box will expand clip search if only 1D raster found with clip. When False, will throw OneDimensionalRaster error if only 1 x or y data point is found. Defaults to True.

  • nodata (int or float, default: None ) –

    Overwrite dataset internal nodata value.

  • max_size (int, default: None ) –

    Limit the size of the longest dimension of the dataset read, respecting bounds X/Y aspect ratio.

  • height (int, default: None ) –

    Output height of the array.

  • width (int, default: None ) –

    Output width of the array.

  • resampling_method (RIOResampling, default: 'nearest' ) –

    RasterIO resampling algorithm. Defaults to nearest.

Returns:

  • ImageData

    rio_tiler.models.ImageData: ImageData instance with data, mask and input spatial info.

info

info() -> Info

Return xarray.DataArray info.

part

part(bbox: BBox, dst_crs: Optional[CRS] = None, bounds_crs: CRS = WGS84_CRS, reproject_method: WarpResampling = 'nearest', auto_expand: bool = True, nodata: Optional[NoData] = None, max_size: Optional[int] = None, height: Optional[int] = None, width: Optional[int] = None, resampling_method: RIOResampling = 'nearest', **kwargs: Any) -> ImageData

Read part of a dataset.

Parameters:

  • bbox (tuple) –

    Output bounds (left, bottom, right, top) in target crs ("dst_crs").

  • dst_crs (CRS, default: None ) –

    Overwrite target coordinate reference system.

  • bounds_crs (CRS, default: WGS84_CRS ) –

    Bounds Coordinate Reference System. Defaults to epsg:4326.

  • reproject_method (WarpResampling, default: 'nearest' ) –

    WarpKernel resampling algorithm. Defaults to nearest.

  • auto_expand (boolean, default: True ) –

    When True, rioxarray's clip_box will expand clip search if only 1D raster found with clip. When False, will throw OneDimensionalRaster error if only 1 x or y data point is found. Defaults to True.

  • nodata (int or float, default: None ) –

    Overwrite dataset internal nodata value.

  • max_size (int, default: None ) –

    Limit the size of the longest dimension of the dataset read, respecting bounds X/Y aspect ratio.

  • height (int, default: None ) –

    Output height of the array.

  • width (int, default: None ) –

    Output width of the array.

  • resampling_method (RIOResampling, default: 'nearest' ) –

    RasterIO resampling algorithm. Defaults to nearest.

Returns:

  • ImageData

    rio_tiler.models.ImageData: ImageData instance with data, mask and input spatial info.

point

point(lon: float, lat: float, coord_crs: CRS = WGS84_CRS, nodata: Optional[NoData] = None, **kwargs: Any) -> PointData

Read a pixel value from a dataset.

Parameters:

  • lon (float) –

    Longitude.

  • lat (float) –

    Latitude.

  • coord_crs (CRS, default: WGS84_CRS ) –

    Coordinate Reference System of the input coords. Defaults to epsg:4326.

  • nodata (int or float, default: None ) –

    Overwrite dataset internal nodata value.

Returns:

preview

preview(max_size: int = 1024, height: Optional[int] = None, width: Optional[int] = None, nodata: Optional[NoData] = None, dst_crs: Optional[CRS] = None, reproject_method: WarpResampling = 'nearest', resampling_method: RIOResampling = 'nearest', **kwargs: Any) -> ImageData

Return a preview of a dataset.

Parameters:

  • max_size (int, default: 1024 ) –

    Limit the size of the longest dimension of the dataset read, respecting bounds X/Y aspect ratio. Defaults to 1024.

  • height (int, default: None ) –

    Output height of the array.

  • width (int, default: None ) –

    Output width of the array.

  • nodata (int or float, default: None ) –

    Overwrite dataset internal nodata value.

  • dst_crs (CRS, default: None ) –

    target coordinate reference system.

  • reproject_method (WarpResampling, default: 'nearest' ) –

    WarpKernel resampling algorithm. Defaults to nearest.

  • resampling_method (RIOResampling, default: 'nearest' ) –

    RasterIO resampling algorithm. Defaults to nearest.

Returns:

  • ImageData

    rio_tiler.models.ImageData: ImageData instance with data, mask and input spatial info.

statistics

statistics(categorical: bool = False, categories: Optional[List[float]] = None, percentiles: Optional[List[int]] = None, hist_options: Optional[Dict] = None, nodata: Optional[NoData] = None, **kwargs: Any) -> Dict[str, BandStatistics]

Return statistics from a dataset.

tile

tile(tile_x: int, tile_y: int, tile_z: int, tilesize: int = 256, reproject_method: WarpResampling = 'nearest', auto_expand: bool = True, nodata: Optional[NoData] = None, **kwargs: Any) -> ImageData

Read a Web Map tile from a dataset.

Parameters:

  • tile_x (int) –

    Tile's horizontal index.

  • tile_y (int) –

    Tile's vertical index.

  • tile_z (int) –

    Tile's zoom level index.

  • tilesize (int, default: 256 ) –

    Output image size. Defaults to 256.

  • reproject_method (WarpResampling, default: 'nearest' ) –

    WarpKernel resampling algorithm. Defaults to nearest.

  • auto_expand (boolean, default: True ) –

    When True, rioxarray's clip_box will expand clip search if only 1D raster found with clip. When False, will throw OneDimensionalRaster error if only 1 x or y data point is found. Defaults to True.

  • nodata (int or float, default: None ) –

    Overwrite dataset internal nodata value.

Returns:

  • ImageData

    rio_tiler.models.ImageData: ImageData instance with data, mask and tile spatial info.