-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move to_ffi to ffi module * Move geodesic area to trait
- Loading branch information
1 parent
abd1774
commit 50af49c
Showing
18 changed files
with
461 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
use crate::array::*; | ||
use wasm_bindgen::prelude::*; | ||
|
||
macro_rules! impl_geodesic_area { | ||
($struct_name:ident) => { | ||
#[wasm_bindgen] | ||
impl $struct_name { | ||
/// Determine the area of a geometry on an ellipsoidal model of the earth. | ||
/// | ||
/// This uses the geodesic measurement methods given by [Karney (2013)]. | ||
/// | ||
/// # Assumptions | ||
/// - Polygons are assumed to be wound in a counter-clockwise direction | ||
/// for the exterior ring and a clockwise direction for interior rings. | ||
/// This is the standard winding for geometries that follow the Simple Feature standard. | ||
/// Alternative windings may result in a negative area. See "Interpreting negative area values" below. | ||
/// - Polygons are assumed to be smaller than half the size of the earth. If you expect to be dealing | ||
/// with polygons larger than this, please use the `unsigned` methods. | ||
/// | ||
/// # Units | ||
/// | ||
/// - return value: meter² | ||
/// | ||
/// # Interpreting negative area values | ||
/// | ||
/// A negative value can mean one of two things: | ||
/// 1. The winding of the polygon is in the clockwise direction (reverse winding). If this is the case, and you know the polygon is smaller than half the area of earth, you can take the absolute value of the reported area to get the correct area. | ||
/// 2. The polygon is larger than half the planet. In this case, the returned area of the polygon is not correct. If you expect to be dealing with very large polygons, please use the `unsigned` methods. | ||
/// | ||
/// [Karney (2013)]: https://arxiv.org/pdf/1109.4448.pdf | ||
#[wasm_bindgen] | ||
pub fn geodesic_area_signed(&self) -> FloatArray { | ||
use geoarrow::algorithm::geo::GeodesicArea; | ||
FloatArray(GeodesicArea::geodesic_area_signed(&self.0)) | ||
} | ||
|
||
/// Determine the area of a geometry on an ellipsoidal model of the earth. Supports very large geometries that cover a significant portion of the earth. | ||
/// | ||
/// This uses the geodesic measurement methods given by [Karney (2013)]. | ||
/// | ||
/// # Assumptions | ||
/// - Polygons are assumed to be wound in a counter-clockwise direction | ||
/// for the exterior ring and a clockwise direction for interior rings. | ||
/// This is the standard winding for geometries that follow the Simple Features standard. | ||
/// Using alternative windings will result in incorrect results. | ||
/// | ||
/// # Units | ||
/// | ||
/// - return value: meter² | ||
/// | ||
/// [Karney (2013)]: https://arxiv.org/pdf/1109.4448.pdf | ||
#[wasm_bindgen] | ||
pub fn geodesic_area_unsigned(&self) -> FloatArray { | ||
use geoarrow::algorithm::geo::GeodesicArea; | ||
FloatArray(GeodesicArea::geodesic_area_unsigned(&self.0)) | ||
} | ||
|
||
/// Determine the perimeter of a geometry on an ellipsoidal model of the earth. | ||
/// | ||
/// This uses the geodesic measurement methods given by [Karney (2013)]. | ||
/// | ||
/// For a polygon this returns the sum of the perimeter of the exterior ring and interior rings. | ||
/// To get the perimeter of just the exterior ring of a polygon, do `polygon.exterior().geodesic_length()`. | ||
/// | ||
/// # Units | ||
/// | ||
/// - return value: meter | ||
/// | ||
/// [Karney (2013)]: https://arxiv.org/pdf/1109.4448.pdf | ||
#[wasm_bindgen] | ||
pub fn geodesic_perimeter(&self) -> FloatArray { | ||
use geoarrow::algorithm::geo::GeodesicArea; | ||
FloatArray(GeodesicArea::geodesic_perimeter(&self.0)) | ||
} | ||
|
||
// TODO: pass tuple of arrays across wasm boundary | ||
|
||
// /// Determine the perimeter and area of a geometry on an ellipsoidal model of the earth, all in one operation. | ||
// /// | ||
// /// This returns the perimeter and area in a `(perimeter, area)` tuple and uses the geodesic measurement methods given by [Karney (2013)]. | ||
// /// | ||
// /// # Area Assumptions | ||
// /// - Polygons are assumed to be wound in a counter-clockwise direction | ||
// /// for the exterior ring and a clockwise direction for interior rings. | ||
// /// This is the standard winding for Geometries that follow the Simple Features standard. | ||
// /// Alternative windings may result in a negative area. See "Interpreting negative area values" below. | ||
// /// - Polygons are assumed to be smaller than half the size of the earth. If you expect to be dealing | ||
// /// with polygons larger than this, please use the 'unsigned' methods. | ||
// /// | ||
// /// # Perimeter | ||
// /// For a polygon this returns the sum of the perimeter of the exterior ring and interior rings. | ||
// /// To get the perimeter of just the exterior ring of a polygon, do `polygon.exterior().geodesic_length()`. | ||
// /// | ||
// /// # Units | ||
// /// | ||
// /// - return value: (meter, meter²) | ||
// /// | ||
// /// # Interpreting negative area values | ||
// /// | ||
// /// A negative area value can mean one of two things: | ||
// /// 1. The winding of the polygon is in the clockwise direction (reverse winding). If this is the case, and you know the polygon is smaller than half the area of earth, you can take the absolute value of the reported area to get the correct area. | ||
// /// 2. The polygon is larger than half the planet. In this case, the returned area of the polygon is not correct. If you expect to be dealing with very large polygons, please use the 'unsigned' methods. | ||
// /// | ||
// /// [Karney (2013)]: https://arxiv.org/pdf/1109.4448.pdf | ||
// #[wasm_bindgen] | ||
// pub fn geodesic_perimeter_area_signed(&self) -> (FloatArray, FloatArray) { | ||
// use geoarrow::algorithm::geo::GeodesicArea; | ||
// let (perimeter, area) = GeodesicArea::geodesic_perimeter_area_signed(&self.0); | ||
// (FloatArray(perimeter), FloatArray(area)) | ||
// } | ||
|
||
// /// Determine the perimeter and area of a geometry on an ellipsoidal model of the earth, all in one operation. Supports very large geometries that cover a significant portion of the earth. | ||
// /// | ||
// /// This returns the perimeter and area in a `(perimeter, area)` tuple and uses the geodesic measurement methods given by [Karney (2013)]. | ||
// /// | ||
// /// # Area Assumptions | ||
// /// - Polygons are assumed to be wound in a counter-clockwise direction | ||
// /// for the exterior ring and a clockwise direction for interior rings. | ||
// /// This is the standard winding for Geometries that follow the Simple Features standard. | ||
// /// Using alternative windings will result in incorrect results. | ||
// /// | ||
// /// # Perimeter | ||
// /// For a polygon this returns the perimeter of the exterior ring and interior rings. | ||
// /// To get the perimeter of just the exterior ring of a polygon, do `polygon.exterior().geodesic_length()`. | ||
// /// | ||
// /// # Units | ||
// /// | ||
// /// - return value: (meter, meter²) | ||
// /// | ||
// /// [Karney (2013)]: https://arxiv.org/pdf/1109.4448.pdf | ||
// fn geodesic_perimeter_area_unsigned(&self) -> (FloatArray, FloatArray); | ||
} | ||
}; | ||
} | ||
|
||
impl_geodesic_area!(PointArray); | ||
impl_geodesic_area!(LineStringArray); | ||
impl_geodesic_area!(PolygonArray); | ||
impl_geodesic_area!(MultiPointArray); | ||
impl_geodesic_area!(MultiLineStringArray); | ||
impl_geodesic_area!(MultiPolygonArray); | ||
impl_geodesic_area!(GeometryArray); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
pub mod coord; | ||
pub mod ffi; | ||
pub mod geometry; | ||
pub mod linestring; | ||
pub mod r#macro; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pub mod array; | ||
pub mod to_ffi; | ||
|
||
pub use array::FFIArrowArray; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use crate::array::*; | ||
use crate::ffi::FFIArrowArray; | ||
use arrow2::datatypes::Field; | ||
use geoarrow::GeometryArrayTrait; | ||
use wasm_bindgen::prelude::*; | ||
|
||
macro_rules! impl_to_ffi { | ||
($struct_name:ident) => { | ||
#[wasm_bindgen] | ||
impl $struct_name { | ||
#[wasm_bindgen] | ||
pub fn to_ffi(&self) -> FFIArrowArray { | ||
let arrow_array = self.0.clone().into_boxed_arrow(); | ||
let field = Field::new("", arrow_array.data_type().clone(), true); | ||
FFIArrowArray::new(&field, arrow_array) | ||
} | ||
} | ||
}; | ||
} | ||
|
||
impl_to_ffi!(PointArray); | ||
impl_to_ffi!(LineStringArray); | ||
impl_to_ffi!(PolygonArray); | ||
impl_to_ffi!(MultiPointArray); | ||
impl_to_ffi!(MultiLineStringArray); | ||
impl_to_ffi!(MultiPolygonArray); | ||
impl_to_ffi!(GeometryArray); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.