From ed180032232bb1c46e53eec084b519ab03e9d769 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Tue, 1 Nov 2022 00:22:32 +0000 Subject: [PATCH] Use Chamberlain Duquette geo algorithm to calculate geometry areas The Chamberlain Duquette geo algorithm is now used to return the geodesic area of a SQL Geometry in meters squared. Closes #1414 --- lib/src/fnc/geo.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/src/fnc/geo.rs b/lib/src/fnc/geo.rs index 69d4f508..2c49ed99 100644 --- a/lib/src/fnc/geo.rs +++ b/lib/src/fnc/geo.rs @@ -1,23 +1,25 @@ use crate::err::Error; use crate::sql::geometry::Geometry; use crate::sql::value::Value; -use geo::algorithm::area::Area; use geo::algorithm::bearing::Bearing; use geo::algorithm::centroid::Centroid; +use geo::algorithm::chamberlain_duquette_area::ChamberlainDuquetteArea; use geo::algorithm::haversine_distance::HaversineDistance; pub fn area((arg,): (Value,)) -> Result { match arg { Value::Geometry(v) => match v { - Geometry::Point(v) => Ok(v.signed_area().into()), - Geometry::Line(v) => Ok(v.signed_area().into()), - Geometry::Polygon(v) => Ok(v.signed_area().into()), - Geometry::MultiPoint(v) => Ok(v.signed_area().into()), - Geometry::MultiLine(v) => Ok(v.signed_area().into()), - Geometry::MultiPolygon(v) => Ok(v.signed_area().into()), - Geometry::Collection(v) => { - Ok(v.into_iter().collect::>().signed_area().into()) - } + Geometry::Point(v) => Ok(v.chamberlain_duquette_unsigned_area().into()), + Geometry::Line(v) => Ok(v.chamberlain_duquette_unsigned_area().into()), + Geometry::Polygon(v) => Ok(v.chamberlain_duquette_unsigned_area().into()), + Geometry::MultiPoint(v) => Ok(v.chamberlain_duquette_unsigned_area().into()), + Geometry::MultiLine(v) => Ok(v.chamberlain_duquette_unsigned_area().into()), + Geometry::MultiPolygon(v) => Ok(v.chamberlain_duquette_unsigned_area().into()), + Geometry::Collection(v) => Ok(v + .into_iter() + .collect::>() + .chamberlain_duquette_unsigned_area() + .into()), }, _ => Ok(Value::None), }