geoarrow_wasm/array/
geometry.rs1use crate::array::ffi::FFIArrowArray;
2use crate::array::polygon::PolygonArray;
3use crate::array::primitive::BooleanArray;
4use crate::array::primitive::FloatArray;
5use crate::array::{
6 LineStringArray, MultiLineStringArray, MultiPointArray, MultiPolygonArray, PointArray,
7};
8use crate::broadcasting::{BroadcastableAffine, BroadcastableFloat};
9use crate::error::WasmResult;
10use crate::impl_geometry_array;
11use crate::log;
12#[cfg(feature = "geodesy")]
13use crate::reproject::ReprojectDirection;
14use crate::TransformOrigin;
15use arrow2::datatypes::Field;
16use geoarrow::GeometryArrayTrait;
17use wasm_bindgen::prelude::*;
18
19#[wasm_bindgen]
20pub enum GeometryType {
21 Point = 0,
22 LineString = 1,
23 Polygon = 3,
24 MultiPoint = 4,
25 MultiLineString = 5,
26 MultiPolygon = 6,
27}
28
29#[wasm_bindgen]
30pub struct GeometryArray(pub(crate) geoarrow::array::GeometryArray);
31
32impl_geometry_array!(GeometryArray);
33
34#[wasm_bindgen]
35impl GeometryArray {
36 #[wasm_bindgen]
37 pub fn from_point_array(arr: PointArray) -> Self {
38 Self(geoarrow::array::GeometryArray::Point(arr.0))
39 }
40
41 #[wasm_bindgen]
42 pub fn from_line_string_array(arr: LineStringArray) -> Self {
43 Self(geoarrow::array::GeometryArray::LineString(arr.0))
44 }
45
46 #[wasm_bindgen]
47 pub fn from_polygon_array(arr: PolygonArray) -> Self {
48 Self(geoarrow::array::GeometryArray::Polygon(arr.0))
49 }
50
51 #[wasm_bindgen]
52 pub fn from_multi_point_array(arr: MultiPointArray) -> Self {
53 Self(geoarrow::array::GeometryArray::MultiPoint(arr.0))
54 }
55
56 #[wasm_bindgen]
57 pub fn from_multi_line_string_array(arr: MultiLineStringArray) -> Self {
58 Self(geoarrow::array::GeometryArray::MultiLineString(arr.0))
59 }
60
61 #[wasm_bindgen]
62 pub fn from_multi_polygon_array(arr: MultiPolygonArray) -> Self {
63 Self(geoarrow::array::GeometryArray::MultiPolygon(arr.0))
64 }
65
66 #[wasm_bindgen]
67 pub fn geometry_type(&self) -> GeometryType {
68 match self.0 {
69 geoarrow::array::GeometryArray::Point(_) => GeometryType::Point,
70 geoarrow::array::GeometryArray::LineString(_) => GeometryType::LineString,
71 geoarrow::array::GeometryArray::Polygon(_) => GeometryType::Polygon,
72 geoarrow::array::GeometryArray::MultiPoint(_) => GeometryType::MultiPoint,
73 geoarrow::array::GeometryArray::MultiLineString(_) => GeometryType::MultiLineString,
74 geoarrow::array::GeometryArray::MultiPolygon(_) => GeometryType::MultiPolygon,
75 geoarrow::array::GeometryArray::WKB(_) => unimplemented!(),
76 }
77 }
78}
79
80impl From<&GeometryArray> for geoarrow::array::GeometryArray {
81 fn from(value: &GeometryArray) -> Self {
82 value.0.clone()
83 }
84}