Skip to content

rio_tiler.models

rio_tiler.models

rio-tiler models.

BandStatistics

Bases: BaseModel

Band statistics

Bounds

Bases: BaseModel

Dataset Bounding box

ImageData

Image Data class.

Attributes:

  • array (MaskedArray) –

    image values.

  • assets (list) –

    list of assets used to construct the data values.

  • bounds (BoundingBox) –

    bounding box of the data.

  • crs (CRS) –

    Coordinates Reference System of the bounds.

  • metadata (dict) –

    Additional metadata. Defaults to {}.

  • band_names (list) –

    name of each band. Defaults to ["1", "2", "3"] for 3 bands image.

  • dataset_statistics (list) –

    dataset statistics [(min, max), (min, max)]

Note: mask should be considered as PER_BAND so shape should be similar as the data

count property

count: int

Number of band.

data property

data: ndarray

Return data part of the masked array.

height property

height: int

Height of the data array.

mask property

mask: ndarray

Return Mask in form of rasterio dataset mask.

transform property

transform: Affine

Returns the affine transform.

width property

width: int

Width of the data array.

__iter__

__iter__()

Allow for variable expansion (arr, mask = ImageData)

apply_color_formula

apply_color_formula(color_formula: Optional[str]) -> Self

Apply color-operations formula in place.

apply_colormap

apply_colormap(colormap: ColorMapType) -> ImageData

Apply colormap to the image data.

apply_expression

apply_expression(expression: str) -> ImageData

Apply expression to the image data.

clip

clip(bbox: BBox) -> ImageData

Clip data and mask to a bbox.

create_from_list classmethod

create_from_list(data: Sequence[ImageData]) -> Self

Create ImageData from a sequence of ImageData objects.

Parameters:

  • data (sequence) –

    sequence of ImageData.

data_as_image

data_as_image() -> ndarray

Return the data array reshaped into an image processing/visualization software friendly order.

(bands, rows, columns) -> (rows, columns, bands).

from_bytes classmethod

from_bytes(data: bytes) -> Self

Create ImageData from bytes.

Parameters:

  • data (bytes) –

    raster dataset as bytes.

get_coverage_array

get_coverage_array(shape: Dict, shape_crs: CRS = WGS84_CRS, cover_scale: int = 10) -> NDArray[floating]

Post-process image data.

Parameters:

  • shape (Dict) –

    GeoJSON geometry or Feature.

  • shape_crs (CRS, default: WGS84_CRS ) –

    Coordinates Reference System of shape.

  • cover_scale (int, default: 10 ) –

    Scale used when generating coverage estimates of each raster cell by vector feature. Coverage is generated by rasterizing the feature at a finer resolution than the raster then using a summation to aggregate to the raster resolution and dividing by the square of cover_scale to get coverage value for each cell. Increasing cover_scale will increase the accuracy of coverage values; three orders magnitude finer resolution (cover_scale=1000) is usually enough to get coverage estimates with <1% error in individual edge cells coverage estimates, though much smaller values (e.g., cover_scale=10) are often sufficient (<10% error) and require less memory.

Returns:

Note: code adapted from perrygeo/python-rasterstats!136 by @sgoodm

post_process

post_process(in_range: Optional[Sequence[IntervalTuple]] = None, out_dtype: Union[str, number] = 'uint8', color_formula: Optional[str] = None, **kwargs: Any) -> ImageData

Post-process image data.

Parameters:

  • in_range (tuple, default: None ) –

    input min/max bounds value to rescale from.

  • out_dtype (str, default: 'uint8' ) –

    output datatype after rescaling. Defaults to uint8.

  • color_formula (str, default: None ) –

    color-ops formula (see: vincentsarago/color-ops).

  • kwargs (optional, default: {} ) –

    keyword arguments to forward to rio_tiler.utils.linear_rescale.

Returns:

  • ImageData ( ImageData ) –

    new ImageData object with the updated data.

Examples:

>>> img.post_process(in_range=((0, 16000), ))
>>> img.post_process(color_formula="Gamma RGB 4.1")

render

render(add_mask: bool = True, img_format: str = 'PNG', colormap: Optional[ColorMapType] = None, **kwargs) -> bytes

Render data to image blob.

Parameters:

  • add_mask (bool, default: True ) –

    add mask to output image. Defaults to True.

  • img_format (str, default: 'PNG' ) –

    output image format. Defaults to PNG.

  • colormap (dict or sequence, default: None ) –

    RGBA Color Table dictionary or sequence.

  • kwargs (optional, default: {} ) –

    keyword arguments to forward to rio_tiler.utils.render.

Returns:

  • bytes ( bytes ) –

    image.

rescale

rescale(in_range: Sequence[IntervalTuple], out_range: Sequence[IntervalTuple] = ((0, 255)), out_dtype: Union[str, number] = 'uint8') -> Self

Rescale data in place.

resize

resize(height: int, width: int, resampling_method: RIOResampling = 'nearest') -> ImageData

Resize data and mask.

statistics

statistics(categorical: bool = False, categories: Optional[List[float]] = None, percentiles: Optional[List[int]] = None, hist_options: Optional[Dict] = None, coverage: Optional[ndarray] = None) -> Dict[str, BandStatistics]

Return statistics from ImageData.

Info

Bases: Bounds

Dataset Info.

PointData

Point Data class.

Attributes:

  • array (MaskedArray) –

    pixel values.

  • band_names (list) –

    name of each band. Defaults to ["1", "2", "3"] for 3 bands image.

  • coordinates (tuple) –

    Point's coordinates.

  • crs (CRS) –

    Coordinates Reference System of the bounds.

  • assets (list) –

    list of assets used to construct the data values.

  • metadata (dict) –

    Additional metadata. Defaults to {}.

count property

count: int

Number of band.

data property

data: ndarray

Return data part of the masked array.

mask property

mask: ndarray

Return Mask in form of rasterio dataset mask.

__iter__

__iter__()

Allow for variable expansion.

_validate_coordinates

_validate_coordinates(attribute, value)

coordinates has to be a 2d list.

_validate_data

_validate_data(attribute, value)

PointsData data has to be a 1d array.

apply_expression

apply_expression(expression: str) -> PointData

Apply expression to the image data.

create_from_list classmethod

create_from_list(data: Sequence[PointData]) -> Self

Create PointData from a sequence of PointsData objects.

Parameters:

  • data (sequence) –

    sequence of PointData.

masked_and_3d

masked_and_3d(array: ndarray) -> MaskedArray

Makes sure we have a 3D array and mask

rescale_image

rescale_image(array: MaskedArray, in_range: Sequence[IntervalTuple], out_range: Sequence[IntervalTuple] = ((0, 255)), out_dtype: Union[str, number] = 'uint8') -> MaskedArray

Rescale image data in-place.

to_coordsbbox

to_coordsbbox(bbox) -> Optional[BoundingBox]

Convert bbox to CoordsBbox nameTuple.

to_masked

to_masked(array: ndarray) -> MaskedArray

Makes sure we have a MaskedArray.