Skip to content

Module titiler.pgstac.mosaic

TiTiler.PgSTAC custom Mosaic Backend and Custom STACReader.

Variables

WGS84_CRS
cache_config
retry_config

Classes

CustomSTACReader

class CustomSTACReader(
    input: Dict[str, Any],
    tms: morecantile.models.TileMatrixSet = <TileMatrixSet title='Google Maps Compatible for the World' id='WebMercatorQuad' crs='http://www.opengis.net/def/crs/EPSG/0/3857>,
    minzoom: int = NOTHING,
    maxzoom: int = NOTHING,
    reader: Type[rio_tiler.io.base.BaseReader] = <class 'rio_tiler.io.rasterio.Reader'>,
    reader_options: Dict = NOTHING,
    ctx: Any = <class 'rasterio.env.Env'>
)

Simplified STAC Reader.

Inputs should be in form of: { "id": "IAMASTACITEM", "collection": "mycollection", "bbox": (0, 0, 10, 10), "assets": { "COG": { "href": "somewhereovertherainbow.io/cog.tif" } } }

Ancestors (in MRO)

  • rio_tiler.io.base.MultiBaseReader
  • rio_tiler.io.base.SpatialMixin

Instance variables

geographic_bounds

Return dataset bounds in geographic_crs.

Methods

feature

def feature(
    self,
    shape: Dict,
    assets: Union[Sequence[str], str] = None,
    expression: Union[str, NoneType] = None,
    asset_indexes: Union[Dict[str, Union[Sequence[int], int]], NoneType] = None,
    asset_as_band: bool = False,
    **kwargs: Any
) -> rio_tiler.models.ImageData

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

Parameters:

Name Type Description Default
shape dict Valid GeoJSON feature. None
assets sequence of str or str assets to fetch info from. None
expression str rio-tiler expression for the asset list (e.g. asset1/asset2+asset3). None
asset_indexes dict Band indexes for each asset (e.g {"asset1": 1, "asset2": (1, 2,)}). None
kwargs optional Options to forward to the self.reader.feature method. None

Returns:

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

info

def info(
    self,
    assets: Union[Sequence[str], str] = None,
    **kwargs: Any
) -> Dict[str, rio_tiler.models.Info]

Return metadata from multiple assets.

Parameters:

Name Type Description Default
assets sequence of str or str assets to fetch info from. Required keyword argument. None

Returns:

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

merged_statistics

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

Return array statistics for multiple assets.

Parameters:

Name Type Description Default
assets sequence of str or str assets to fetch info from. None
expression str rio-tiler expression for the asset list (e.g. asset1/asset2+asset3). None
asset_indexes dict Band indexes for each asset (e.g {"asset1": 1, "asset2": (1, 2,)}). None
categorical bool treat input data as categorical data. Defaults to False. False
categories list of numbers list of categories to return value for. None
percentiles list of numbers list of percentile values to calculate. Defaults to [2, 98]. [2, 98]
hist_options dict Options to forward to numpy.histogram function. None
max_size int Limit the size of the longest dimension of the dataset read, respecting bounds X/Y aspect ratio. Defaults to 1024. 1024
kwargs optional Options to forward to the self.preview method. None

Returns:

Type Description
Dict[str, rio_tiler.models.BandStatistics] bands statistics.

parse_expression

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

Parse rio-tiler band math expression.

part

def part(
    self,
    bbox: Tuple[float, float, float, float],
    assets: Union[Sequence[str], str] = None,
    expression: Union[str, NoneType] = None,
    asset_indexes: Union[Dict[str, Union[Sequence[int], int]], NoneType] = None,
    asset_as_band: bool = False,
    **kwargs: Any
) -> rio_tiler.models.ImageData

Read and merge parts from multiple assets.

Parameters:

Name Type Description Default
bbox tuple Output bounds (left, bottom, right, top) in target crs. None
assets sequence of str or str assets to fetch info from. None
expression str rio-tiler expression for the asset list (e.g. asset1/asset2+asset3). None
asset_indexes dict Band indexes for each asset (e.g {"asset1": 1, "asset2": (1, 2,)}). None
kwargs optional Options to forward to the self.reader.part method. None

Returns:

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

point

def point(
    self,
    lon: float,
    lat: float,
    assets: Union[Sequence[str], str] = None,
    expression: Union[str, NoneType] = None,
    asset_indexes: Union[Dict[str, Union[Sequence[int], int]], NoneType] = None,
    asset_as_band: bool = False,
    **kwargs: Any
) -> rio_tiler.models.PointData

Read pixel value from multiple assets.

Parameters:

Name Type Description Default
lon float Longitude. None
lat float Latitude. None
assets sequence of str or str assets to fetch info from. None
expression str rio-tiler expression for the asset list (e.g. asset1/asset2+asset3). None
asset_indexes dict Band indexes for each asset (e.g {"asset1": 1, "asset2": (1, 2,)}). None
kwargs optional Options to forward to the self.reader.point method. None

Returns:

Type Description
None PointData

preview

def preview(
    self,
    assets: Union[Sequence[str], str] = None,
    expression: Union[str, NoneType] = None,
    asset_indexes: Union[Dict[str, Union[Sequence[int], int]], NoneType] = None,
    asset_as_band: bool = False,
    **kwargs: Any
) -> rio_tiler.models.ImageData

Read and merge previews from multiple assets.

Parameters:

Name Type Description Default
assets sequence of str or str assets to fetch info from. None
expression str rio-tiler expression for the asset list (e.g. asset1/asset2+asset3). None
asset_indexes dict Band indexes for each asset (e.g {"asset1": 1, "asset2": (1, 2,)}). None
kwargs optional Options to forward to the self.reader.preview method. None

Returns:

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

statistics

def statistics(
    self,
    assets: Union[Sequence[str], str] = None,
    asset_indexes: Union[Dict[str, Union[Sequence[int], int]], NoneType] = None,
    asset_expression: Union[Dict[str, str], NoneType] = None,
    **kwargs: Any
) -> Dict[str, Dict[str, rio_tiler.models.BandStatistics]]

Return array statistics for multiple assets.

Parameters:

Name Type Description Default
assets sequence of str or str assets to fetch info from. None
asset_indexes dict Band indexes for each asset (e.g {"asset1": 1, "asset2": (1, 2,)}). None
asset_expression dict rio-tiler expression for each asset (e.g. {"asset1": "b1/b2+b3", "asset2": ...}). None
kwargs optional Options to forward to the self.reader.statistics method. None

Returns:

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

tile

def tile(
    self,
    tile_x: int,
    tile_y: int,
    tile_z: int,
    assets: Union[Sequence[str], str] = None,
    expression: Union[str, NoneType] = None,
    asset_indexes: Union[Dict[str, Union[Sequence[int], int]], NoneType] = None,
    asset_as_band: bool = False,
    **kwargs: Any
) -> rio_tiler.models.ImageData

Read and merge Wep Map tiles from multiple assets.

Parameters:

Name Type Description Default
tile_x int Tile's horizontal index. None
tile_y int Tile's vertical index. None
tile_z int Tile's zoom level index. None
assets sequence of str or str assets to fetch info from. None
expression str rio-tiler expression for the asset list (e.g. asset1/asset2+asset3). None
asset_indexes dict Band indexes for each asset (e.g {"asset1": 1, "asset2": (1, 2,)}). None
kwargs optional Options to forward to the self.reader.tile method. None

Returns:

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

tile_exists

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

Check if a tile intersects the dataset bounds.

Parameters:

Name Type Description Default
tile_x int Tile's horizontal index. None
tile_y int Tile's vertical index. None
tile_z int Tile's zoom level index. None

Returns:

Type Description
bool True if the tile intersects the dataset bounds.

PGSTACBackend

class PGSTACBackend(
    input: str,
    pool: psycopg_pool.pool.ConnectionPool,
    tms: morecantile.models.TileMatrixSet = <TileMatrixSet title='Google Maps Compatible for the World' id='WebMercatorQuad' crs='http://www.opengis.net/def/crs/EPSG/0/3857>,
    minzoom: int = NOTHING,
    maxzoom: int = NOTHING,
    reader_options: Dict = NOTHING,
    bounds: Tuple[float, float, float, float] = (-180, -90, 180, 90),
    crs: rasterio.crs.CRS = CRS.from_epsg(4326),
    geographic_crs: rasterio.crs.CRS = CRS.from_epsg(4326)
)

PgSTAC Mosaic Backend.

Ancestors (in MRO)

  • cogeo_mosaic.backends.base.BaseBackend
  • rio_tiler.io.base.BaseReader
  • rio_tiler.io.base.SpatialMixin

Instance variables

center

Return center from the mosaic definition.

geographic_bounds

Return dataset bounds in geographic_crs.

mosaicid

Return sha224 id of the mosaicjson document.

quadkey_zoom

Return Quadkey zoom property.

Methods

assets_for_bbox

def assets_for_bbox(
    self,
    xmin: float,
    ymin: float,
    xmax: float,
    ymax: float,
    coord_crs: rasterio.crs.CRS = CRS.from_epsg(4326),
    **kwargs: Any
) -> List[Dict]

Retrieve assets for bbox.

assets_for_point

def assets_for_point(
    self,
    lng: float,
    lat: float,
    coord_crs: rasterio.crs.CRS = CRS.from_epsg(4326),
    **kwargs: Any
) -> List[Dict]

Retrieve assets for point.

assets_for_tile

def assets_for_tile(
    self,
    x: int,
    y: int,
    z: int,
    **kwargs: Any
) -> List[Dict]

Retrieve assets for tile.

feature

def feature(
    self,
    shape: Dict,
    dst_crs: Union[rasterio.crs.CRS, NoneType] = None,
    shape_crs: rasterio.crs.CRS = CRS.from_epsg(4326),
    max_size: int = 1024,
    scan_limit: Union[int, NoneType] = None,
    items_limit: Union[int, NoneType] = None,
    time_limit: Union[int, NoneType] = None,
    exitwhenfull: Union[bool, NoneType] = None,
    skipcovered: Union[bool, NoneType] = None,
    **kwargs: Any
) -> Tuple[rio_tiler.models.ImageData, List[str]]

Create an Image from multiple items for a GeoJSON feature.

find_quadkeys

def find_quadkeys(
    self,
    tile: morecantile.commons.Tile,
    quadkey_zoom: int
) -> List[str]

Find quadkeys at desired zoom for tile

Parameters:

Name Type Description Default
tile morecantile.Tile Input tile to use when searching for quadkeys None
quadkey_zoom int Zoom level None

Returns:

Type Description
list List[str] of quadkeys

get_assets

def get_assets(
    *args: Any,
    **kwargs: Any
)

info

def info(
    self,
    quadkeys: bool = False
) -> cogeo_mosaic.models.Info

Mosaic info.

part

def part(
    self,
    bbox: Tuple[float, float, float, float],
    dst_crs: Union[rasterio.crs.CRS, NoneType] = None,
    bounds_crs: rasterio.crs.CRS = CRS.from_epsg(4326),
    scan_limit: Union[int, NoneType] = None,
    items_limit: Union[int, NoneType] = None,
    time_limit: Union[int, NoneType] = None,
    exitwhenfull: Union[bool, NoneType] = None,
    skipcovered: Union[bool, NoneType] = None,
    **kwargs: Any
) -> Tuple[rio_tiler.models.ImageData, List[str]]

Create an Image from multiple items for a bbox.

point

def point(
    self,
    lon: float,
    lat: float,
    coord_crs: rasterio.crs.CRS = CRS.from_epsg(4326),
    scan_limit: Union[int, NoneType] = None,
    items_limit: Union[int, NoneType] = None,
    time_limit: Union[int, NoneType] = None,
    exitwhenfull: Union[bool, NoneType] = None,
    skipcovered: Union[bool, NoneType] = None,
    **kwargs: Any
) -> List

Get Point value from multiple observation.

preview

def preview(
    self
)

PlaceHolder for BaseReader.preview.

statistics

def statistics(
    self
)

PlaceHolder for BaseReader.statistics.

tile

def tile(
    self,
    tile_x: int,
    tile_y: int,
    tile_z: int,
    scan_limit: Union[int, NoneType] = None,
    items_limit: Union[int, NoneType] = None,
    time_limit: Union[int, NoneType] = None,
    exitwhenfull: Union[bool, NoneType] = None,
    skipcovered: Union[bool, NoneType] = None,
    **kwargs: Any
) -> Tuple[rio_tiler.models.ImageData, List[str]]

Get Tile from multiple observation.

tile_exists

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

Check if a tile intersects the dataset bounds.

Parameters:

Name Type Description Default
tile_x int Tile's horizontal index. None
tile_y int Tile's vertical index. None
tile_z int Tile's zoom level index. None

Returns:

Type Description
bool True if the tile intersects the dataset bounds.

update

def update(
    self
) -> None

We overwrite the default method.

write

def write(
    self,
    overwrite: bool = True
) -> None

This method is not used but is required by the abstract class.