Skip to content

rio_tiler.io.base

rio_tiler.io.base

rio_tiler.io.base: ABC class for rio-tiler readers.

BaseReader

Bases: SpatialMixin

Rio-tiler.io BaseReader.

Attributes:

  • input (any) –

    Reader's input.

  • tms (TileMatrixSet) –

    TileMatrixSet grid definition. Defaults to WebMercatorQuad.

__enter__

__enter__()

Support using with Context Managers.

__exit__

__exit__(exc_type, exc_value, traceback)

Support using with Context Managers.

feature abstractmethod

feature(shape: Dict) -> ImageData

Read a Dataset for a GeoJSON feature.

Parameters:

  • shape (dict) –

    Valid GeoJSON feature.

Returns:

  • ImageData

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

info abstractmethod

info() -> Info

Return Dataset's info.

Returns:

  • Info

    rio_tile.models.Info: Dataset info.

part abstractmethod

part(bbox: BBox) -> ImageData

Read a Part of a Dataset.

Parameters:

  • bbox (tuple) –

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

Returns:

  • ImageData

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

point abstractmethod

point(lon: float, lat: float) -> PointData

Read a value from a Dataset.

Parameters:

  • lon (float) –

    Longitude.

  • lat (float) –

    Latitude.

Returns:

  • PointData

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

preview abstractmethod

preview() -> ImageData

Read a preview of a Dataset.

Returns:

  • ImageData

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

statistics abstractmethod

statistics() -> Dict[str, BandStatistics]

Return bands statistics from a dataset.

Returns:

tile abstractmethod

tile(tile_x: int, tile_y: int, tile_z: int) -> 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.

Returns:

  • ImageData

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

MultiBandReader

Bases: SpatialMixin

Multi Band Reader.

This Abstract Base Class Reader is suited for dataset that stores spectral bands as separate files (e.g. Sentinel 2).

Attributes:

  • input (any) –

    input data.

  • tms (TileMatrixSet) –

    TileMatrixSet grid definition. Defaults to WebMercatorQuad.

  • minzoom (int) –

    Set dataset's minzoom.

  • maxzoom (int) –

    Set dataset's maxzoom.

  • reader_options ((dict, option)) –

    options to forward to the reader. Defaults to {}.

__enter__

__enter__()

Support using with Context Managers.

__exit__

__exit__(exc_type, exc_value, traceback)

Support using with Context Managers.

_get_band_url abstractmethod

_get_band_url(band: str) -> str

Validate band name and construct url.

feature

feature(shape: Dict, bands: Optional[Union[Sequence[str], str]] = None, expression: Optional[str] = None, **kwargs: Any) -> ImageData

Read and merge parts defined by geojson feature from multiple bands.

Parameters:

  • shape (dict) –

    Valid GeoJSON feature.

  • bands (sequence of str or str, default: None ) –

    bands to fetch info from.

  • expression (str, default: None ) –

    rio-tiler expression for the band list (e.g. b1/b2+b3).

  • kwargs (optional, default: {} ) –

    Options to forward to the self.reader.feature method.

Returns:

  • ImageData

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

info

info(bands: Optional[Union[Sequence[str], str]] = None, **kwargs: Any) -> Info

Return metadata from multiple bands.

Parameters:

  • bands (sequence of str or str, default: None ) –

    band names to fetch info from. Required keyword argument.

Returns:

  • dict ( Info ) –

    Multiple bands info in form of {"band1": rio_tile.models.Info}.

parse_expression

parse_expression(expression: str) -> Tuple

Parse rio-tiler band math expression.

part

part(bbox: BBox, bands: Optional[Union[Sequence[str], str]] = None, expression: Optional[str] = None, **kwargs: Any) -> ImageData

Read and merge parts from multiple bands.

Parameters:

  • bbox (tuple) –

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

  • bands (sequence of str or str, default: None ) –

    bands to fetch info from.

  • expression (str, default: None ) –

    rio-tiler expression for the band list (e.g. b1/b2+b3).

  • kwargs (optional, default: {} ) –

    Options to forward to the 'self.reader.part' method.

Returns:

  • ImageData

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

point

point(lon: float, lat: float, bands: Optional[Union[Sequence[str], str]] = None, expression: Optional[str] = None, **kwargs: Any) -> PointData

Read a pixel values from multiple bands.

Parameters:

  • lon (float) –

    Longitude.

  • lat (float) –

    Latitude.

  • bands (sequence of str or str, default: None ) –

    bands to fetch info from.

  • expression (str, default: None ) –

    rio-tiler expression for the band list (e.g. b1/b2+b3).

  • kwargs (optional, default: {} ) –

    Options to forward to the self.reader.point method.

Returns:

preview

preview(bands: Optional[Union[Sequence[str], str]] = None, expression: Optional[str] = None, **kwargs: Any) -> ImageData

Read and merge previews from multiple bands.

Parameters:

  • bands (sequence of str or str, default: None ) –

    bands to fetch info from.

  • expression (str, default: None ) –

    rio-tiler expression for the band list (e.g. b1/b2+b3).

  • kwargs (optional, default: {} ) –

    Options to forward to the self.reader.preview method.

Returns:

  • ImageData

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

statistics

statistics(bands: Optional[Union[Sequence[str], str]] = None, expression: Optional[str] = None, categorical: bool = False, categories: Optional[List[float]] = None, percentiles: Optional[List[int]] = None, hist_options: Optional[Dict] = None, max_size: int = 1024, **kwargs: Any) -> Dict[str, BandStatistics]

Return array statistics for multiple assets.

Parameters:

  • bands (sequence of str or str, default: None ) –

    bands to fetch info from. Required keyword argument.

  • expression (str, default: None ) –

    rio-tiler expression for the band list (e.g. b1/b2+b3).

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

  • kwargs (optional, default: {} ) –

    Options to forward to the self.preview method.

Returns:

  • dict ( Dict[str, BandStatistics] ) –

    Multiple assets statistics in form of {"{band}/{expression}": rio_tiler.models.BandStatistics, ...}.

tile

tile(tile_x: int, tile_y: int, tile_z: int, bands: Optional[Union[Sequence[str], str]] = None, expression: Optional[str] = None, **kwargs: Any) -> ImageData

Read and merge Web Map tiles multiple bands.

Parameters:

  • tile_x (int) –

    Tile's horizontal index.

  • tile_y (int) –

    Tile's vertical index.

  • tile_z (int) –

    Tile's zoom level index.

  • bands (sequence of str or str, default: None ) –

    bands to fetch info from.

  • expression (str, default: None ) –

    rio-tiler expression for the band list (e.g. b1/b2+b3).

  • kwargs (optional, default: {} ) –

    Options to forward to the self.reader.tile method.

Returns:

  • ImageData

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

MultiBaseReader

Bases: SpatialMixin

MultiBaseReader Reader.

This Abstract Base Class Reader is suited for dataset that are composed of multiple assets (e.g. STAC).

Attributes:

  • input (any) –

    input data.

  • tms (TileMatrixSet) –

    TileMatrixSet grid definition. Defaults to WebMercatorQuad.

  • minzoom (int) –

    Set dataset's minzoom.

  • maxzoom (int) –

    Set dataset's maxzoom.

  • reader_options ((dict, option)) –

    options to forward to the reader. Defaults to {}.

__enter__

__enter__()

Support using with Context Managers.

__exit__

__exit__(exc_type, exc_value, traceback)

Support using with Context Managers.

_get_asset_info abstractmethod

_get_asset_info(asset: str) -> AssetInfo

Validate asset name and construct url.

_get_reader

_get_reader(asset_info: AssetInfo) -> Tuple[Type[BaseReader], Dict]

Get Asset Reader and options.

_update_statistics

_update_statistics(img: ImageData, indexes: Optional[Indexes] = None, statistics: Optional[Sequence[Tuple[float, float]]] = None)

Update ImageData Statistics from AssetInfo.

feature

feature(shape: Dict, assets: Optional[Union[Sequence[str], str]] = None, expression: Optional[str] = None, asset_indexes: Optional[Dict[str, Indexes]] = None, asset_as_band: bool = False, **kwargs: Any) -> ImageData

Read and merge parts defined by geojson feature from multiple assets.

Parameters:

  • shape (dict) –

    Valid GeoJSON feature.

  • assets (sequence of str or str, default: None ) –

    assets to fetch info from.

  • expression (str, default: None ) –

    rio-tiler expression for the asset list (e.g. asset1/asset2+asset3).

  • asset_indexes (dict, default: None ) –

    Band indexes for each asset (e.g {"asset1": 1, "asset2": (1, 2,)}).

  • kwargs (optional, default: {} ) –

    Options to forward to the self.reader.feature method.

Returns:

  • ImageData

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

info

info(assets: Optional[Union[Sequence[str], str]] = None, **kwargs: Any) -> Dict[str, Info]

Return metadata from multiple assets.

Parameters:

  • assets (sequence of str or str, default: None ) –

    assets to fetch info from. Required keyword argument.

Returns:

  • dict ( Dict[str, Info] ) –

    Multiple assets info in form of {"asset1": rio_tile.models.Info}.

merged_statistics

merged_statistics(assets: Optional[Union[Sequence[str], str]] = None, expression: Optional[str] = None, asset_indexes: Optional[Dict[str, Indexes]] = None, categorical: bool = False, categories: Optional[List[float]] = None, percentiles: Optional[List[int]] = None, hist_options: Optional[Dict] = None, max_size: int = 1024, **kwargs: Any) -> Dict[str, BandStatistics]

Return array statistics for multiple assets.

Parameters:

  • assets (sequence of str or str, default: None ) –

    assets to fetch info from.

  • expression (str, default: None ) –

    rio-tiler expression for the asset list (e.g. asset1/asset2+asset3).

  • asset_indexes (dict, default: None ) –

    Band indexes for each asset (e.g {"asset1": 1, "asset2": (1, 2,)}).

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

  • kwargs (optional, default: {} ) –

    Options to forward to the self.preview method.

Returns:

parse_expression

parse_expression(expression: str, asset_as_band: bool = False) -> Tuple

Parse rio-tiler band math expression.

part

part(bbox: BBox, assets: Optional[Union[Sequence[str], str]] = None, expression: Optional[str] = None, asset_indexes: Optional[Dict[str, Indexes]] = None, asset_as_band: bool = False, **kwargs: Any) -> ImageData

Read and merge parts from multiple assets.

Parameters:

  • bbox (tuple) –

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

  • assets (sequence of str or str, default: None ) –

    assets to fetch info from.

  • expression (str, default: None ) –

    rio-tiler expression for the asset list (e.g. asset1/asset2+asset3).

  • asset_indexes (dict, default: None ) –

    Band indexes for each asset (e.g {"asset1": 1, "asset2": (1, 2,)}).

  • kwargs (optional, default: {} ) –

    Options to forward to the self.reader.part method.

Returns:

  • ImageData

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

point

point(lon: float, lat: float, assets: Optional[Union[Sequence[str], str]] = None, expression: Optional[str] = None, asset_indexes: Optional[Dict[str, Indexes]] = None, asset_as_band: bool = False, **kwargs: Any) -> PointData

Read pixel value from multiple assets.

Parameters:

  • lon (float) –

    Longitude.

  • lat (float) –

    Latitude.

  • assets (sequence of str or str, default: None ) –

    assets to fetch info from.

  • expression (str, default: None ) –

    rio-tiler expression for the asset list (e.g. asset1/asset2+asset3).

  • asset_indexes (dict, default: None ) –

    Band indexes for each asset (e.g {"asset1": 1, "asset2": (1, 2,)}).

  • kwargs (optional, default: {} ) –

    Options to forward to the self.reader.point method.

Returns:

preview

preview(assets: Optional[Union[Sequence[str], str]] = None, expression: Optional[str] = None, asset_indexes: Optional[Dict[str, Indexes]] = None, asset_as_band: bool = False, **kwargs: Any) -> ImageData

Read and merge previews from multiple assets.

Parameters:

  • assets (sequence of str or str, default: None ) –

    assets to fetch info from.

  • expression (str, default: None ) –

    rio-tiler expression for the asset list (e.g. asset1/asset2+asset3).

  • asset_indexes (dict, default: None ) –

    Band indexes for each asset (e.g {"asset1": 1, "asset2": (1, 2,)}).

  • kwargs (optional, default: {} ) –

    Options to forward to the self.reader.preview method.

Returns:

  • ImageData

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

statistics

statistics(assets: Optional[Union[Sequence[str], str]] = None, asset_indexes: Optional[Dict[str, Indexes]] = None, asset_expression: Optional[Dict[str, str]] = None, **kwargs: Any) -> Dict[str, Dict[str, BandStatistics]]

Return array statistics for multiple assets.

Parameters:

  • assets (sequence of str or str, default: None ) –

    assets to fetch info from.

  • asset_indexes (dict, default: None ) –

    Band indexes for each asset (e.g {"asset1": 1, "asset2": (1, 2,)}).

  • asset_expression (dict, default: None ) –

    rio-tiler expression for each asset (e.g. {"asset1": "b1/b2+b3", "asset2": ...}).

  • kwargs (optional, default: {} ) –

    Options to forward to the self.reader.statistics method.

Returns:

  • dict ( Dict[str, Dict[str, BandStatistics]] ) –

    Multiple assets statistics in form of {"asset1": {"1": rio_tiler.models.BandStatistics, ...}}.

tile

tile(tile_x: int, tile_y: int, tile_z: int, assets: Optional[Union[Sequence[str], str]] = None, expression: Optional[str] = None, asset_indexes: Optional[Dict[str, Indexes]] = None, asset_as_band: bool = False, **kwargs: Any) -> ImageData

Read and merge Wep Map tiles from multiple assets.

Parameters:

  • tile_x (int) –

    Tile's horizontal index.

  • tile_y (int) –

    Tile's vertical index.

  • tile_z (int) –

    Tile's zoom level index.

  • assets (sequence of str or str, default: None ) –

    assets to fetch info from.

  • expression (str, default: None ) –

    rio-tiler expression for the asset list (e.g. asset1/asset2+asset3).

  • asset_indexes (dict, default: None ) –

    Band indexes for each asset (e.g {"asset1": 1, "asset2": (1, 2,)}).

  • kwargs (optional, default: {} ) –

    Options to forward to the self.reader.tile method.

Returns:

  • ImageData

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

SpatialMixin

Spatial Info Mixin.

Attributes:

  • tms (TileMatrixSet) –

    TileMatrixSet grid definition. Defaults to WebMercatorQuad.

_dst_geom_in_tms_crs cached property

_dst_geom_in_tms_crs

Return dataset geom info in TMS projection.

_maxzoom cached property

_maxzoom: int

Calculate dataset maximum zoom level.

_minzoom cached property

_minzoom: int

Calculate dataset minimum zoom level.

get_geographic_bounds

get_geographic_bounds(crs: CRS) -> BBox

Return Geographic Bounds for a Geographic CRS.

tile_exists

tile_exists(tile_x: int, tile_y: int, tile_z: int) -> bool

Check if a tile intersects the dataset bounds.

Parameters:

  • tile_x (int) –

    Tile's horizontal index.

  • tile_y (int) –

    Tile's vertical index.

  • tile_z (int) –

    Tile's zoom level index.

Returns:

  • bool ( bool ) –

    True if the tile intersects the dataset bounds.