pub struct DensityGrid {
pub width: usize,
pub height: usize,
pub lon0: f64,
pub lat0: f64,
pub dlon: f64,
pub dlat: f64,
pub cells: Vec<f32>,
}Expand description
Population density (people/km²) on a coarse global lon/lat grid.
Row 0 is the northernmost; dlat is positive.
Fields§
§width: usizeThe grid’s column count.
height: usizeThe grid’s row count.
lon0: f64The west edge of cell (0,0).
lat0: f64The north edge of cell (0,0).
dlon: f64The cell width in degrees.
dlat: f64The cell height in degrees (positive; rows run north to south).
cells: Vec<f32>The row-major density samples in people/km².
Implementations§
Source§impl DensityGrid
impl DensityGrid
Sourcepub fn load(cache_dir: &Path) -> Result<Self>
pub fn load(cache_dir: &Path) -> Result<Self>
Loads the grid from the sidecar cache, building it from GHS-POP on
first use (downloading the zip via crate::download::fetch() if
needed).
§Errors
Returns an error on a corrupt sidecar, or, on the first build, a GHS-POP download failure, a zip extraction or TIFF decode failure, or an I/O failure writing the sidecar.
Sourcepub fn sample(&self, lon: f64, lat: f64) -> f64
pub fn sample(&self, lon: f64, lat: f64) -> f64
Returns the density at a point; outside the grid the density is 0.
Sourcepub fn max_along(&self, a: (f64, f64), b: (f64, f64)) -> f64
pub fn max_along(&self, a: (f64, f64), b: (f64, f64)) -> f64
Returns the maximum density over every grid cell the segment
a–b crosses (an Amanatides–Woo traversal in cell space). This,
not per-vertex sampling, is what boundary weighting uses: a long
straight edge can cross a metro area without placing a vertex in
it.
Sourcepub fn from_ghs_pop_tif(tif_path: &Path) -> Result<Self>
pub fn from_ghs_pop_tif(tif_path: &Path) -> Result<Self>
Decodes the GHS-POP GeoTIFF, summing 8×8 pixel blocks and
converting population counts to people/km².
§Errors
Returns an error on an I/O or TIFF decode failure, missing geotransform tags, or a sample format other than f32/f64.
§Panics
Panics if the source raster’s dimensions or chunk count exceed u32 (not reachable for GHS-POP).