geolith-tiles-builder 0.4.2

Builds tiles from OpenStreetMap and Overture Maps: protomaps-schema vector PMTiles, Terrain-RGB, raster archives and 3D Tiles from Gaussian splats
Documentation
//! Elevation sources the terrain tiler can render: one in-memory [`Dem`] or
//! a mosaic of `GeoTIFFs` read window by window ([`CogMosaic`]).
//!
//! [`CogMosaic`]: crate::terrain::mosaic::CogMosaic

use std::borrow::Cow;

use geolith::error::Result;

use crate::terrain::dem::Dem;

/// Geographic bounds as `(min_lon, min_lat, max_lon, max_lat)`.
pub type Bounds = (f64, f64, f64, f64);

/// Elevation data the terrain tiler samples per output tile.
pub trait ElevationSource: Sync {
    /// Geographic footprint of the data.
    fn wgs84_bounds(&self) -> Bounds;

    /// Minimum and maximum valid elevation, or `None` when fully nodata.
    fn elevation_range(&self) -> Option<(f32, f32)>;

    /// EPSG code recorded in the archive metadata.
    fn source_epsg(&self) -> u32;

    /// Rasters covering `bounds`, at about `metres_per_pixel` or finer.
    ///
    /// The tiler samples them in order and keeps the first valid value, so
    /// overlapping sources resolve the same way on every run.
    ///
    /// # Errors
    ///
    /// Returns an error when a source raster cannot be read.
    fn patches(&self, bounds: Bounds, metres_per_pixel: f64) -> Result<Vec<Cow<'_, Dem>>>;
}

impl ElevationSource for Dem {
    fn wgs84_bounds(&self) -> Bounds {
        Dem::wgs84_bounds(self)
    }

    fn elevation_range(&self) -> Option<(f32, f32)> {
        Dem::elevation_range(self)
    }

    fn source_epsg(&self) -> u32 {
        self.crs.epsg()
    }

    /// The whole in-memory raster, borrowed.
    fn patches(&self, _bounds: Bounds, _metres_per_pixel: f64) -> Result<Vec<Cow<'_, Dem>>> {
        Ok(vec![Cow::Borrowed(self)])
    }
}