Skip to content

rio_tiler.io.rasterio

rio_tiler.io.rasterio

rio_tiler.io.rasterio: rio-tiler reader built on top Rasterio

ImageReader

Bases: Reader

Non Geo Image Reader

maxzoom property

maxzoom

Return dataset maxzoom.

minzoom property

minzoom

Return dataset minzoom.

__attrs_post_init__

__attrs_post_init__()

Define _kwargs, open dataset and get info.

feature

feature(shape: Dict, indexes: Optional[Indexes] = None, expression: Optional[str] = None, max_size: Optional[int] = None, height: Optional[int] = None, width: Optional[int] = None, force_binary_mask: bool = True, resampling_method: RIOResampling = 'nearest', unscale: bool = False, post_process: Optional[Callable[[MaskedArray], MaskedArray]] = None) -> ImageData

Read part of an Image defined by a geojson feature.

part

part(bbox: BBox, indexes: Optional[Union[int, Sequence]] = None, expression: Optional[str] = None, max_size: Optional[int] = None, height: Optional[int] = None, width: Optional[int] = None, force_binary_mask: bool = True, resampling_method: RIOResampling = 'nearest', unscale: bool = False, post_process: Optional[Callable[[MaskedArray], MaskedArray]] = None) -> ImageData

Read part of an Image.

Parameters:

  • bbox (tuple) –

    Output bounds (left, bottom, right, top).

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

  • force_binary_mask (bool, default: True ) –

    Cast returned mask to binary values (0 or 255). Defaults to True.

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

    RasterIO resampling algorithm. Defaults to nearest.

  • unscale (bool, default: False ) –

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

  • post_process (callable, default: None ) –

    Function to apply on output data and mask values.

Returns:

  • ImageData

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

point

point(x: float, y: float, indexes: Optional[Indexes] = None, expression: Optional[str] = None, unscale: bool = False, post_process: Optional[Callable[[MaskedArray], MaskedArray]] = None) -> PointData

Read a pixel value from an Image.

Parameters:

  • x (float) –

    X coordinate.

  • y (float) –

    Y coordinate.

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

    Band indexes.

  • expression (str, default: None ) –

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

  • unscale (bool, default: False ) –

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

  • post_process (callable, default: None ) –

    Function to apply on output data and mask values.

Returns:

tile

tile(tile_x: int, tile_y: int, tile_z: int, tilesize: int = 256, indexes: Optional[Indexes] = None, expression: Optional[str] = None, force_binary_mask: bool = True, resampling_method: RIOResampling = 'nearest', unscale: bool = False, post_process: Optional[Callable[[MaskedArray], MaskedArray]] = None) -> ImageData

Read a Web Map tile from an Image.

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.

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

    Band indexes.

  • expression (str, default: None ) –

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

  • force_binary_mask (bool, default: True ) –

    Cast returned mask to binary values (0 or 255). Defaults to True.

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

    RasterIO resampling algorithm. Defaults to nearest.

  • unscale (bool, default: False ) –

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

  • post_process (callable, default: None ) –

    Function to apply on output data and mask values.

Returns:

  • ImageData

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

LocalTileMatrixSet

Fake TMS for non-geo image.

_ul

_ul(*tile: Tile) -> Coords

Return the upper left coordinate of the (x, y, z) tile.

xy_bounds

xy_bounds(*tile: Tile) -> BoundingBox

Return the bounding box of the (x, y, z) tile

Reader

Bases: BaseReader

Rasterio Reader.

Attributes:

  • input (str) –

    dataset path.

  • dataset (DatasetReader or DatasetWriter or WarpedVRT) –

    Rasterio dataset.

  • tms (TileMatrixSet) –

    TileMatrixSet grid definition. Defaults to WebMercatorQuad.

  • colormap (dict) –

    Overwrite internal colormap.

  • options (dict) –

    Options to forward to low-level reader methods.

Examples:

>>> with Reader(src_path) as src:
    src.tile(...)
>>> # Set global options
    with Reader(src_path, options={"unscale": True, "nodata": 0}) as src:
        src.tile(...)
>>> with rasterio.open(src_path) as src_dst:
        with WarpedVRT(src_dst, ...) as vrt_dst:
            with Reader(None, dataset=vrt_dst) as src:
                src.tile(...)
>>> with rasterio.open(src_path) as src_dst:
        with Reader(None, dataset=src_dst) as src:
            src.tile(...)

maxzoom property

maxzoom

Return dataset maxzoom.

minzoom property

minzoom

Return dataset minzoom.

__attrs_post_init__

__attrs_post_init__()

Define _kwargs, open dataset and get info.

__exit__

__exit__(exc_type, exc_value, traceback)

Support using with Context Managers.

_get_colormap

_get_colormap()

Retrieve the internal colormap.

close

close()

Close rasterio dataset.

feature

feature(shape: Dict, dst_crs: Optional[CRS] = None, shape_crs: CRS = WGS84_CRS, indexes: Optional[Indexes] = None, expression: Optional[str] = None, max_size: Optional[int] = None, height: Optional[int] = None, width: Optional[int] = None, buffer: Optional[NumType] = None, **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.

  • 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 (int or 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).

  • kwargs (optional, default: {} ) –

    Options to forward to the Reader.part method.

Returns:

  • ImageData

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

info

info() -> Info

Return Dataset info.

part

part(bbox: BBox, dst_crs: Optional[CRS] = None, bounds_crs: CRS = WGS84_CRS, indexes: Optional[Union[int, Sequence]] = None, expression: Optional[str] = None, max_size: Optional[int] = None, height: Optional[int] = None, width: Optional[int] = None, buffer: Optional[float] = None, **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.

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

  • kwargs (optional, default: {} ) –

    Options to forward to the rio_tiler.reader.part function.

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, indexes: Optional[Indexes] = None, expression: Optional[str] = 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.

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

    Band indexes.

  • expression (str, default: None ) –

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

  • kwargs (optional, default: {} ) –

    Options to forward to the rio_tiler.reader.point function.

Returns:

preview

preview(indexes: Optional[Indexes] = None, expression: Optional[str] = None, max_size: int = 1024, height: Optional[int] = None, width: Optional[int] = None, **kwargs: Any) -> ImageData

Return 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).

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

  • kwargs (optional, default: {} ) –

    Options to forward to the self.read method.

Returns:

  • ImageData

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

read

read(indexes: Optional[Indexes] = None, expression: Optional[str] = None, **kwargs: Any) -> ImageData

Read the Dataset.

Parameters:

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

    Band indexes.

  • expression (str, default: None ) –

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

  • kwargs (optional, default: {} ) –

    Options to forward to the rio_tiler.reader.read function.

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, max_size: int = 1024, indexes: Optional[Indexes] = None, expression: Optional[str] = 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.

  • kwargs (optional, default: {} ) –

    Options to forward to self.read.

Returns:

tile

tile(tile_x: int, tile_y: int, tile_z: int, tilesize: int = 256, indexes: Optional[Indexes] = None, expression: Optional[str] = None, buffer: Optional[float] = 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.

  • indexes (int or sequence of 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 * tile_buffer (e.g 0.5 = 257x257, 1.0 = 258x258).

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