Skip to main content

DensityGrid

Struct DensityGrid 

Source
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: usize

The grid’s column count.

§height: usize

The grid’s row count.

§lon0: f64

The west edge of cell (0,0).

§lat0: f64

The north edge of cell (0,0).

§dlon: f64

The cell width in degrees.

§dlat: f64

The 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

Source

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.

Source

pub fn sample(&self, lon: f64, lat: f64) -> f64

Returns the density at a point; outside the grid the density is 0.

Source

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.

Source

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).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.