Skip to main content

geolith_tiles_builder/terrain/
source.rs

1//! Elevation sources the terrain tiler can render: one in-memory [`Dem`] or
2//! a mosaic of `GeoTIFFs` read window by window ([`CogMosaic`]).
3//!
4//! [`CogMosaic`]: crate::terrain::mosaic::CogMosaic
5
6use std::borrow::Cow;
7
8use geolith::error::Result;
9
10use crate::terrain::dem::Dem;
11
12/// Geographic bounds as `(min_lon, min_lat, max_lon, max_lat)`.
13pub type Bounds = (f64, f64, f64, f64);
14
15/// Elevation data the terrain tiler samples per output tile.
16pub trait ElevationSource: Sync {
17    /// Geographic footprint of the data.
18    fn wgs84_bounds(&self) -> Bounds;
19
20    /// Minimum and maximum valid elevation, or `None` when fully nodata.
21    fn elevation_range(&self) -> Option<(f32, f32)>;
22
23    /// EPSG code recorded in the archive metadata.
24    fn source_epsg(&self) -> u32;
25
26    /// Rasters covering `bounds`, at about `metres_per_pixel` or finer.
27    ///
28    /// The tiler samples them in order and keeps the first valid value, so
29    /// overlapping sources resolve the same way on every run.
30    ///
31    /// # Errors
32    ///
33    /// Returns an error when a source raster cannot be read.
34    fn patches(&self, bounds: Bounds, metres_per_pixel: f64) -> Result<Vec<Cow<'_, Dem>>>;
35}
36
37impl ElevationSource for Dem {
38    fn wgs84_bounds(&self) -> Bounds {
39        Dem::wgs84_bounds(self)
40    }
41
42    fn elevation_range(&self) -> Option<(f32, f32)> {
43        Dem::elevation_range(self)
44    }
45
46    fn source_epsg(&self) -> u32 {
47        self.crs.epsg()
48    }
49
50    /// The whole in-memory raster, borrowed.
51    fn patches(&self, _bounds: Bounds, _metres_per_pixel: f64) -> Result<Vec<Cow<'_, Dem>>> {
52        Ok(vec![Cow::Borrowed(self)])
53    }
54}