Skip to content

rio_tiler.experimental.rasterio

rio_tiler.experimental.rasterio

rio_tiler.experimental.rasterio: rio-tiler reader built on top of rasterio, without WarpedVRT.

This reader mirrors the logic of rio_tiler.io.geotiff.Reader (async-geotiff):

  1. Select the overview level matching the output resolution (GDAL's rule, rio_tiler._warp.get_overview_level)
  2. Read the native (overview) pixels for the requested window, in the dataset CRS
  3. Reproject/resample the result using rio_tiler._warp.warp

Instead of relying on GDAL's WarpedVRT to do everything in one pass.

Reader

Bases: Reader

Rio-tiler Experimental Reader for rasterio datasets.

Dataset opening (incl. GCPS), info and feature are inherited from rio_tiler.io.rasterio.Reader. All data access methods (read, tile, part, preview, point, statistics) are re-implemented to follow the rio_tiler.io.geotiff.Reader logic (no rio_tiler.reader / WarpedVRT).

Note: Only nodata and unscale are taken from options. Other low-level reader options (e.g padding, vrt_options) are not supported and will be ignored (with a warning).

_get_decimation

_get_decimation(desired_factor: float, resampling_method: RIOResampling = 'nearest') -> int

Return the overview decimation factor (1 = full resolution) for a downsampling factor.

desired_factor is the number of full resolution pixels for one output pixel (see rio_tiler._warp.get_downsampling_factor). The overview is selected with GDAL's rule (see rio_tiler._warp.get_overview_level).

_read

_read(indexes: Sequence[int] | None = None, window: Window | None = None, out_shape: tuple[int, int] | None = None, nodata: NoData | None = None, unscale: bool | None = None, out_dtype: str | dtype | None = None, resampling_method: RIOResampling = 'nearest') -> ImageData

Read data from the dataset (no reprojection).

Parameters:

  • indexes (sequence of int, default: None ) –

    Band indexes.

  • window (Window, default: None ) –

    Window to read, in full resolution pixel space.

  • out_shape (tuple of int, default: None ) –

    Output (height, width). Used to read from overviews.

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

    Overwrite dataset internal nodata value.

  • unscale (bool, default: None ) –

    Apply dataset's 'scales' and 'offsets' on output data value.

  • out_dtype (str or dtype, default: None ) –

    Output data type.

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

    Resampling method to use. Defaults to "nearest".

_warn_unsupported staticmethod

_warn_unsupported(kwargs: dict[str, Any]) -> None

Warn about options not supported by this reader.

part

part(bbox: BBox, dst_crs: Any | None = None, bounds_crs: Any = WGS84_CRS, indexes: Indexes | None = None, expression: str | None = None, max_size: int | None = None, height: int | None = None, width: int | None = None, buffer: float | None = None, nodata: NoData | None = None, unscale: bool | None = None, resampling_method: RIOResampling = 'nearest', reproject_method: WarpResampling = 'nearest', **kwargs: Any) -> ImageData

Read a Part of a Dataset.

Parameters:

  • bbox (tuple) –

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

  • dst_crs (CRS, default: None ) –

    Overwrite target coordinate reference system. Defaults to bounds_crs.

  • bounds_crs (CRS, default: WGS84_CRS ) –

    Coordinate reference system of the input bounds. Defaults to WGS84.

  • indexes (sequence of int or int, default: None ) –

    Band indexes.

  • expression (str, default: None ) –

    rio-tiler expression (e.g. b1/b2+b3).

  • 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.

  • buffer (float, default: None ) –

    Buffer on each side of the given aoi. It must be a multiple of 0.5. Output image size will be expanded to output imagesize + 2 * buffer (e.g 0.5 = 257x257, 1.0 = 258x258).

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

    Overwrite dataset internal nodata value.

  • unscale (bool, default: None ) –

    Apply dataset's 'scales' and 'offsets' on output data value. Defaults to False.

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

    GDAL Resampling method to use when resizing. Defaults to "nearest".

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

    GDAL Resampling method to use when reprojecting. 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: Any = WGS84_CRS, indexes: Indexes | None = None, expression: str | None = None, nodata: NoData | None = None, out_dtype: str | dtype | None = None, resampling_method: RIOResampling = 'nearest', interpolate: bool = False, unscale: bool | None = None, **kwargs: Any) -> PointData

Read a 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.

  • indexes (sequence of int or int, default: None ) –

    Band indexes.

  • expression (str | None, default: None ) –

    (str, optional): Expression to apply on the pixel values. Defaults to None.

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

    Overwrite dataset internal nodata value.

  • out_dtype (str or dtype, default: None ) –

    Output data type.

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

    Resampling method to use. Defaults to "nearest".

  • interpolate (bool, default: False ) –

    Interpolate the value if needed. Defaults to False.

  • unscale (bool | None, default: None ) –

    (bool, optional): Apply dataset's 'scales' and 'offsets' on output data value. Defaults to False.

Returns:

  • PointData ( PointData ) –

    Pixel value per bands/assets.

preview

preview(indexes: Indexes | None = None, expression: str | None = None, max_size: int = 1024, height: int | None = None, width: int | None = None, dst_crs: Any | None = None, nodata: NoData | None = None, unscale: bool | None = None, resampling_method: RIOResampling = 'nearest', reproject_method: WarpResampling = 'nearest', **kwargs: Any) -> ImageData

Read a preview of a Dataset.

Parameters:

  • indexes (sequence of int or int, default: None ) –

    Band indexes.

  • expression (str, default: None ) –

    rio-tiler expression (e.g. b1/b2+b3).

  • dst_crs (CRS, default: None ) –

    Target coordinate reference system. Defaults to None (same as input).

  • 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.

  • unscale (bool, default: None ) –

    Apply dataset's 'scales' and 'offsets' on output data value. Defaults to False.

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

    GDAL Resampling method to use when resizing. Defaults to "nearest".

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

    GDAL Resampling method to use when reprojecting. Defaults to "nearest".

Returns:

  • ImageData –

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

read

read(indexes: Indexes | None = None, expression: str | None = None, nodata: NoData | None = None, unscale: bool | None = None, **kwargs: Any) -> ImageData

Read the full Dataset at native resolution, in the dataset CRS.

Parameters:

  • indexes (sequence of int or int, default: None ) –

    Band indexes.

  • expression (str, default: None ) –

    rio-tiler expression (e.g. b1/b2+b3).

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

    Overwrite dataset internal nodata value.

  • unscale (bool, default: None ) –

    Apply dataset's 'scales' and 'offsets' on output data value. Defaults to False.

Returns:

  • ImageData –

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

statistics

statistics(categorical: bool = False, categories: list[float] | None = None, percentiles: list[int] | None = None, hist_options: dict | None = None, max_size: int = 1024, indexes: Indexes | None = None, expression: str | None = None, **kwargs: Any) -> dict[str, BandStatistics]

Return bands statistics from a dataset.

Parameters:

  • categorical (bool, default: False ) –

    treat input data as categorical data. Defaults to False.

  • categories (list of numbers, default: None ) –

    list of categories to return value for.

  • percentiles (list of numbers, default: None ) –

    list of percentile values to calculate. Defaults to [2, 98].

  • hist_options (dict, default: None ) –

    Options to forward to numpy.histogram function.

  • 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.

  • indexes (int or sequence of int, default: None ) –

    Band indexes.

  • expression (str, default: None ) –

    rio-tiler expression (e.g. b1/b2+b3).

  • kwargs (optional, default: {} ) –

    Options to forward to self.preview.

Returns:

  • dict[str, BandStatistics] –

    dict[str, rio_tiler.models.BandStatistics]: bands statistics.

tile

tile(tile_x: int, tile_y: int, tile_z: int, tilesize: int | None = None, indexes: Indexes | None = None, expression: str | None = None, buffer: float | None = None, nodata: NoData | None = None, unscale: bool | None = None, resampling_method: RIOResampling = 'nearest', reproject_method: WarpResampling = 'nearest', **kwargs: Any) -> ImageData

Read a Map tile from the 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: None ) –

    Output image size.

  • indexes (sequence of int or int, default: None ) –

    Band indexes.

  • expression (str, default: None ) –

    rio-tiler expression (e.g. b1/b2+b3).

  • buffer (float, default: None ) –

    Buffer on each side of the given tile. It must be a multiple of 0.5. Output tilesize will be expanded to tilesize + 2 * buffer (e.g 0.5 = 257x257, 1.0 = 258x258).

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

    Overwrite dataset internal nodata value.

  • unscale (bool, default: None ) –

    Apply dataset's 'scales' and 'offsets' on output data value. Defaults to False.

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

    GDAL Resampling method to use when resizing. Defaults to "nearest".

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

    GDAL Resampling method to use when reprojecting. Defaults to "nearest".

  • kwargs (optional, default: {} ) –

    Options to forward to the Reader.part method.

Returns:

  • ImageData –

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