use geo_types::{Coord, LineString, Rect};
const EARTH_RADIUS_EQUATOR: f64 = 6_378_137_f64;
pub fn area_squaremeters_linearring(ring: &LineString<f64>) -> f64 {
ring.0
.windows(2)
.map(|coords| {
(coords[1].x - coords[0].x).to_radians()
* (2.0 + coords[0].y.to_radians().sin() + coords[1].y.to_radians().sin())
})
.sum::<f64>()
.abs()
* EARTH_RADIUS_EQUATOR.powi(2)
/ 2.0
}
pub fn area_squaremeters_rect(bounds: &Rect<f64>) -> f64 {
let ring = LineString::from(vec![
Coord {
x: bounds.min().x,
y: bounds.min().y,
},
Coord {
x: bounds.min().x,
y: bounds.max().y,
},
Coord {
x: bounds.max().x,
y: bounds.max().y,
},
Coord {
x: bounds.max().x,
y: bounds.min().y,
},
Coord {
x: bounds.min().x,
y: bounds.min().y,
},
]);
area_squaremeters_linearring(&ring)
}