pysepal.mapping.tiling#

Prepare a raster for fast tile serving.

rio-tiler reads full-resolution pixels for every tile when the source has no overviews, so low zooms are slow and each tile logs a NoOverviewWarning. prepare_for_tiles() returns a tiled COG with overviews, kept in a cache directory and reused on later calls, and is a fast no-op when the raster is already good enough.

Everything runs through rasterio’s own GDAL rather than the gdal_translate / gdaladdo / gdalwarp binaries: those cannot be declared as a dependency – they are not on PyPI – so a pip install would silently fall back to serving unprepared, unprojected rasters.

rasterio is imported inside the functions that need it. pysepal.mapping pulls this module in, and importing rasterio costs ~160ms, which an app that only draws Earth Engine layers should not pay to display a map.

Module Attributes

CACHE_DIR_ENV_VAR

Overrides where prepared rasters are cached, for a sandbox with a disk quota.

BLOCK_SIZE

Edge of a tile block, and the size overviews are built down to.

Functions

analyze_tif

Report the tiling-relevant properties of a raster.

default_cache_dir

The directory prepared rasters are cached in.

prepare_for_tiles

Return a tiling-optimized copy of a raster, building it if needed.