Skip to content

Module titiler.pgstac.mosaic

TiTiler.PgSTAC custom Mosaic Backend and Custom STACReader.

Variables

MAX_THREADS
WGS84_CRS
cache_config
retry_config

Functions

multi_points_pgstac

def multi_points_pgstac(
    asset_list: Sequence[Dict[str, Any]],
    reader: Callable[..., rio_tiler.models.PointData],
    *args: Any,
    threads: int = 20,
    allowed_exceptions: Optional[Tuple] = None,
    **kwargs: Any
) -> Dict

Merge values returned from tasks.

Custom version of rio_tiler.task.multi_values which use constructed item_id as dict key.

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

Methods

feature

def feature(
    self,
    shape: Dict,
    assets: Union[Sequence[str], str] = None,
    expression: Optional[str] = None,
    asset_indexes: Optional[Dict[str, Union[Sequence[int], int]]] = 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.

geographic_bounds

def geographic_bounds(
    ...
)

Return dataset bounds in geographic_crs.

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: Optional[str] = None,
    asset_indexes: Optional[Dict[str, Union[Sequence[int], int]]] = 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, 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: Optional[str] = None,
    asset_indexes: Optional[Dict[str, Union[Sequence[int], int]]] = 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: Optional[str] = None,
    asset_indexes: Optional[Dict[str, Union[Sequence[int], int]]] = 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: Optional[str] = None,
    asset_indexes: Optional[Dict[str, Union[Sequence[int], int]]] = 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: Optional[Dict[str, Union[Sequence[int], int]]] = None,
    asset_expression: Optional[Dict[str, str]] = 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: Optional[str] = None,
    asset_indexes: Optional[Dict[str, Union[Sequence[int], int]]] = 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.

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: Optional[rasterio.crs.CRS] = None,
    shape_crs: rasterio.crs.CRS = CRS.from_epsg(4326),
    max_size: int = 1024,
    scan_limit: Optional[int] = None,
    items_limit: Optional[int] = None,
    time_limit: Optional[int] = None,
    exitwhenfull: Optional[bool] = None,
    skipcovered: Optional[bool] = 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

geographic_bounds

def geographic_bounds(
    ...
)

Return dataset bounds in geographic_crs.

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: Optional[rasterio.crs.CRS] = None,
    bounds_crs: rasterio.crs.CRS = CRS.from_epsg(4326),
    scan_limit: Optional[int] = None,
    items_limit: Optional[int] = None,
    time_limit: Optional[int] = None,
    exitwhenfull: Optional[bool] = None,
    skipcovered: Optional[bool] = 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: Optional[int] = None,
    items_limit: Optional[int] = None,
    time_limit: Optional[int] = None,
    exitwhenfull: Optional[bool] = None,
    skipcovered: Optional[bool] = 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: Optional[int] = None,
    items_limit: Optional[int] = None,
    time_limit: Optional[int] = None,
    exitwhenfull: Optional[bool] = None,
    skipcovered: Optional[bool] = 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.