Skip to content

Commit

Permalink
Progress
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebarron committed Nov 15, 2024
1 parent cb227ca commit b561410
Show file tree
Hide file tree
Showing 42 changed files with 481 additions and 593 deletions.
76 changes: 38 additions & 38 deletions rust/geoarrow/src/algorithm/geo/euclidean_distance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub trait EuclideanDistance<Rhs> {
///
/// let distance = point.euclidean_distance(&polygon);
///
/// assert_relative_eq!(distance, 2.1213203435596424);
/// assert_relative_eq!(distance.1213203435596424);
/// ```
///
/// `Point` to `LineString`:
Expand Down Expand Up @@ -186,9 +186,9 @@ iter_geo_impl!(MultiPolygonArray, PointArray);
// └─────────────────────────────────┘

// Note: this implementation is outside the macro because it is not generic over O
impl<'a> EuclideanDistance<Point<'a, 2>> for PointArray {
impl<'a> EuclideanDistance<Point<'a>> for PointArray {
/// Minimum distance between two Points
fn euclidean_distance(&self, other: &Point<'a, 2>) -> Float64Array {
fn euclidean_distance(&self, other: &Point<'a>) -> Float64Array {
let mut output_array = Float64Builder::with_capacity(self.len());

self.iter_geo().for_each(|maybe_point| {
Expand Down Expand Up @@ -220,48 +220,48 @@ macro_rules! iter_geo_impl_scalar {
}

// Implementations on PointArray
iter_geo_impl_scalar!(PointArray, LineString<'a, 2>);
iter_geo_impl_scalar!(PointArray, Polygon<'a, 2>);
iter_geo_impl_scalar!(PointArray, MultiPoint<'a, 2>);
iter_geo_impl_scalar!(PointArray, MultiLineString<'a, 2>);
iter_geo_impl_scalar!(PointArray, MultiPolygon<'a, 2>);
iter_geo_impl_scalar!(PointArray, LineString<'a>);
iter_geo_impl_scalar!(PointArray, Polygon<'a>);
iter_geo_impl_scalar!(PointArray, MultiPoint<'a>);
iter_geo_impl_scalar!(PointArray, MultiLineString<'a>);
iter_geo_impl_scalar!(PointArray, MultiPolygon<'a>);

// Implementations on LineStringArray
iter_geo_impl_scalar!(LineStringArray, Point<'a, 2>);
iter_geo_impl_scalar!(LineStringArray, LineString<'a, 2>);
iter_geo_impl_scalar!(LineStringArray, Polygon<'a, 2>);
// iter_geo_impl_scalar!(LineStringArray, MultiPoint<'a, 2>);
// iter_geo_impl_scalar!(LineStringArray, MultiLineString<'a, 2>);
// iter_geo_impl_scalar!(LineStringArray, MultiPolygon<'a, 2>);
iter_geo_impl_scalar!(LineStringArray, Point<'a>);
iter_geo_impl_scalar!(LineStringArray, LineString<'a>);
iter_geo_impl_scalar!(LineStringArray, Polygon<'a>);
// iter_geo_impl_scalar!(LineStringArray, MultiPoint<'a>);
// iter_geo_impl_scalar!(LineStringArray, MultiLineString<'a>);
// iter_geo_impl_scalar!(LineStringArray, MultiPolygon<'a>);

// Implementations on PolygonArray
iter_geo_impl_scalar!(PolygonArray, Point<'a, 2>);
iter_geo_impl_scalar!(PolygonArray, LineString<'a, 2>);
iter_geo_impl_scalar!(PolygonArray, Polygon<'a, 2>);
// iter_geo_impl_scalar!(PolygonArray, MultiPoint<'a, 2>);
// iter_geo_impl_scalar!(PolygonArray, MultiLineString<'a, 2>);
// iter_geo_impl_scalar!(PolygonArray, MultiPolygon<'a, 2>);
iter_geo_impl_scalar!(PolygonArray, Point<'a>);
iter_geo_impl_scalar!(PolygonArray, LineString<'a>);
iter_geo_impl_scalar!(PolygonArray, Polygon<'a>);
// iter_geo_impl_scalar!(PolygonArray, MultiPoint<'a>);
// iter_geo_impl_scalar!(PolygonArray, MultiLineString<'a>);
// iter_geo_impl_scalar!(PolygonArray, MultiPolygon<'a>);

// Implementations on MultiPointArray
iter_geo_impl_scalar!(MultiPointArray, Point<'a, 2>);
// iter_geo_impl_scalar!(MultiPointArray, LineString<'a, 2>);
// iter_geo_impl_scalar!(MultiPointArray, Polygon<'a, 2>);
// iter_geo_impl_scalar!(MultiPointArray, MultiPoint<'a, 2>);
// iter_geo_impl_scalar!(MultiPointArray, MultiLineString<'a, 2>);
// iter_geo_impl_scalar!(MultiPointArray, MultiPolygon<'a, 2>);
iter_geo_impl_scalar!(MultiPointArray, Point<'a>);
// iter_geo_impl_scalar!(MultiPointArray, LineString<'a>);
// iter_geo_impl_scalar!(MultiPointArray, Polygon<'a>);
// iter_geo_impl_scalar!(MultiPointArray, MultiPoint<'a>);
// iter_geo_impl_scalar!(MultiPointArray, MultiLineString<'a>);
// iter_geo_impl_scalar!(MultiPointArray, MultiPolygon<'a>);

// Implementations on MultiLineStringArray
iter_geo_impl_scalar!(MultiLineStringArray, Point<'a, 2>);
// iter_geo_impl_scalar!(MultiLineStringArray, LineString<'a, 2>);
// iter_geo_impl_scalar!(MultiLineStringArray, Polygon<'a, 2>);
// iter_geo_impl_scalar!(MultiLineStringArray, MultiPoint<'a, 2>);
// iter_geo_impl_scalar!(MultiLineStringArray, MultiLineString<'a, 2>);
// iter_geo_impl_scalar!(MultiLineStringArray, MultiPolygon<'a, 2>);
iter_geo_impl_scalar!(MultiLineStringArray, Point<'a>);
// iter_geo_impl_scalar!(MultiLineStringArray, LineString<'a>);
// iter_geo_impl_scalar!(MultiLineStringArray, Polygon<'a>);
// iter_geo_impl_scalar!(MultiLineStringArray, MultiPoint<'a>);
// iter_geo_impl_scalar!(MultiLineStringArray, MultiLineString<'a>);
// iter_geo_impl_scalar!(MultiLineStringArray, MultiPolygon<'a>);

// Implementations on MultiPolygonArray
iter_geo_impl_scalar!(MultiPolygonArray, Point<'a, 2>);
// iter_geo_impl_scalar!(MultiPolygonArray, LineString<'a, 2>);
// iter_geo_impl_scalar!(MultiPolygonArray, Polygon<'a, 2>);
// iter_geo_impl_scalar!(MultiPolygonArray, MultiPoint<'a, 2>);
// iter_geo_impl_scalar!(MultiPolygonArray, MultiLineString<'a, 2>);
// iter_geo_impl_scalar!(MultiPolygonArray, MultiPolygon<'a, 2>);
iter_geo_impl_scalar!(MultiPolygonArray, Point<'a>);
// iter_geo_impl_scalar!(MultiPolygonArray, LineString<'a>);
// iter_geo_impl_scalar!(MultiPolygonArray, Polygon<'a>);
// iter_geo_impl_scalar!(MultiPolygonArray, MultiPoint<'a>);
// iter_geo_impl_scalar!(MultiPolygonArray, MultiLineString<'a>);
// iter_geo_impl_scalar!(MultiPolygonArray, MultiPolygon<'a>);
74 changes: 37 additions & 37 deletions rust/geoarrow/src/algorithm/geo/within.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ iter_geo_impl!(MultiPolygonArray, MultiPolygonArray);
// └──────────────────────────────────────────┘

// Note: this implementation is outside the macro because it is not generic over O
impl<'a> Within<Point<'a, 2>> for PointArray {
fn is_within(&self, rhs: &Point<'a, 2>) -> BooleanArray {
impl<'a> Within<Point<'a>> for PointArray {
fn is_within(&self, rhs: &Point<'a>) -> BooleanArray {
let mut output_array = BooleanBuilder::with_capacity(self.len());

self.iter_geo().for_each(|maybe_point| {
Expand Down Expand Up @@ -175,51 +175,51 @@ macro_rules! iter_geo_impl_geoarrow_scalar {
}

// Implementations on PointArray
iter_geo_impl_geoarrow_scalar!(PointArray, LineString<'a, 2>);
iter_geo_impl_geoarrow_scalar!(PointArray, Polygon<'a, 2>);
iter_geo_impl_geoarrow_scalar!(PointArray, MultiPoint<'a, 2>);
iter_geo_impl_geoarrow_scalar!(PointArray, MultiLineString<'a, 2>);
iter_geo_impl_geoarrow_scalar!(PointArray, MultiPolygon<'a, 2>);
iter_geo_impl_geoarrow_scalar!(PointArray, LineString<'a>);
iter_geo_impl_geoarrow_scalar!(PointArray, Polygon<'a>);
iter_geo_impl_geoarrow_scalar!(PointArray, MultiPoint<'a>);
iter_geo_impl_geoarrow_scalar!(PointArray, MultiLineString<'a>);
iter_geo_impl_geoarrow_scalar!(PointArray, MultiPolygon<'a>);

// Implementations on LineStringArray
iter_geo_impl_geoarrow_scalar!(LineStringArray, Point<'a, 2>);
iter_geo_impl_geoarrow_scalar!(LineStringArray, LineString<'a, 2>);
iter_geo_impl_geoarrow_scalar!(LineStringArray, Polygon<'a, 2>);
iter_geo_impl_geoarrow_scalar!(LineStringArray, MultiPoint<'a, 2>);
iter_geo_impl_geoarrow_scalar!(LineStringArray, MultiLineString<'a, 2>);
iter_geo_impl_geoarrow_scalar!(LineStringArray, MultiPolygon<'a, 2>);
iter_geo_impl_geoarrow_scalar!(LineStringArray, Point<'a>);
iter_geo_impl_geoarrow_scalar!(LineStringArray, LineString<'a>);
iter_geo_impl_geoarrow_scalar!(LineStringArray, Polygon<'a>);
iter_geo_impl_geoarrow_scalar!(LineStringArray, MultiPoint<'a>);
iter_geo_impl_geoarrow_scalar!(LineStringArray, MultiLineString<'a>);
iter_geo_impl_geoarrow_scalar!(LineStringArray, MultiPolygon<'a>);

// Implementations on PolygonArray
iter_geo_impl_geoarrow_scalar!(PolygonArray, Point<'a, 2>);
iter_geo_impl_geoarrow_scalar!(PolygonArray, LineString<'a, 2>);
iter_geo_impl_geoarrow_scalar!(PolygonArray, Polygon<'a, 2>);
iter_geo_impl_geoarrow_scalar!(PolygonArray, MultiPoint<'a, 2>);
iter_geo_impl_geoarrow_scalar!(PolygonArray, MultiLineString<'a, 2>);
iter_geo_impl_geoarrow_scalar!(PolygonArray, MultiPolygon<'a, 2>);
iter_geo_impl_geoarrow_scalar!(PolygonArray, Point<'a>);
iter_geo_impl_geoarrow_scalar!(PolygonArray, LineString<'a>);
iter_geo_impl_geoarrow_scalar!(PolygonArray, Polygon<'a>);
iter_geo_impl_geoarrow_scalar!(PolygonArray, MultiPoint<'a>);
iter_geo_impl_geoarrow_scalar!(PolygonArray, MultiLineString<'a>);
iter_geo_impl_geoarrow_scalar!(PolygonArray, MultiPolygon<'a>);

// Implementations on MultiPointArray
iter_geo_impl_geoarrow_scalar!(MultiPointArray, Point<'a, 2>);
iter_geo_impl_geoarrow_scalar!(MultiPointArray, LineString<'a, 2>);
iter_geo_impl_geoarrow_scalar!(MultiPointArray, Polygon<'a, 2>);
iter_geo_impl_geoarrow_scalar!(MultiPointArray, MultiPoint<'a, 2>);
iter_geo_impl_geoarrow_scalar!(MultiPointArray, MultiLineString<'a, 2>);
iter_geo_impl_geoarrow_scalar!(MultiPointArray, MultiPolygon<'a, 2>);
iter_geo_impl_geoarrow_scalar!(MultiPointArray, Point<'a>);
iter_geo_impl_geoarrow_scalar!(MultiPointArray, LineString<'a>);
iter_geo_impl_geoarrow_scalar!(MultiPointArray, Polygon<'a>);
iter_geo_impl_geoarrow_scalar!(MultiPointArray, MultiPoint<'a>);
iter_geo_impl_geoarrow_scalar!(MultiPointArray, MultiLineString<'a>);
iter_geo_impl_geoarrow_scalar!(MultiPointArray, MultiPolygon<'a>);

// Implementations on MultiLineStringArray
iter_geo_impl_geoarrow_scalar!(MultiLineStringArray, Point<'a, 2>);
iter_geo_impl_geoarrow_scalar!(MultiLineStringArray, LineString<'a, 2>);
iter_geo_impl_geoarrow_scalar!(MultiLineStringArray, Polygon<'a, 2>);
iter_geo_impl_geoarrow_scalar!(MultiLineStringArray, MultiPoint<'a, 2>);
iter_geo_impl_geoarrow_scalar!(MultiLineStringArray, MultiLineString<'a, 2>);
iter_geo_impl_geoarrow_scalar!(MultiLineStringArray, MultiPolygon<'a, 2>);
iter_geo_impl_geoarrow_scalar!(MultiLineStringArray, Point<'a>);
iter_geo_impl_geoarrow_scalar!(MultiLineStringArray, LineString<'a>);
iter_geo_impl_geoarrow_scalar!(MultiLineStringArray, Polygon<'a>);
iter_geo_impl_geoarrow_scalar!(MultiLineStringArray, MultiPoint<'a>);
iter_geo_impl_geoarrow_scalar!(MultiLineStringArray, MultiLineString<'a>);
iter_geo_impl_geoarrow_scalar!(MultiLineStringArray, MultiPolygon<'a>);

// Implementations on MultiPolygonArray
iter_geo_impl_geoarrow_scalar!(MultiPolygonArray, Point<'a, 2>);
iter_geo_impl_geoarrow_scalar!(MultiPolygonArray, LineString<'a, 2>);
iter_geo_impl_geoarrow_scalar!(MultiPolygonArray, Polygon<'a, 2>);
iter_geo_impl_geoarrow_scalar!(MultiPolygonArray, MultiPoint<'a, 2>);
iter_geo_impl_geoarrow_scalar!(MultiPolygonArray, MultiLineString<'a, 2>);
iter_geo_impl_geoarrow_scalar!(MultiPolygonArray, MultiPolygon<'a, 2>);
iter_geo_impl_geoarrow_scalar!(MultiPolygonArray, Point<'a>);
iter_geo_impl_geoarrow_scalar!(MultiPolygonArray, LineString<'a>);
iter_geo_impl_geoarrow_scalar!(MultiPolygonArray, Polygon<'a>);
iter_geo_impl_geoarrow_scalar!(MultiPolygonArray, MultiPoint<'a>);
iter_geo_impl_geoarrow_scalar!(MultiPolygonArray, MultiLineString<'a>);
iter_geo_impl_geoarrow_scalar!(MultiPolygonArray, MultiPolygon<'a>);

// ┌─────────────────────────────────────┐
// │ Implementations for RHS geo scalars │
Expand Down
40 changes: 20 additions & 20 deletions rust/geoarrow/src/algorithm/native/explode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ pub trait Explode {
fn explode(&self) -> Self::Output;
}

impl Explode for PointArray<2> {
impl Explode for PointArray {
type Output = (Self, Option<Int32Array>);

fn explode(&self) -> Self::Output {
(self.clone(), None)
}
}

impl Explode for LineStringArray<2> {
impl Explode for LineStringArray {
type Output = (Self, Option<Int32Array>);

fn explode(&self) -> Self::Output {
(self.clone(), None)
}
}

impl Explode for PolygonArray<2> {
impl Explode for PolygonArray {
type Output = (Self, Option<Int32Array>);

fn explode(&self) -> Self::Output {
Expand Down Expand Up @@ -67,8 +67,8 @@ fn explode_offsets(offsets: &OffsetBuffer<i32>) -> Int32Array {
Int32Array::new(take_indices.into(), None)
}

impl Explode for MultiPointArray<2> {
type Output = (PointArray<2>, Option<Int32Array>);
impl Explode for MultiPointArray {
type Output = (PointArray, Option<Int32Array>);

fn explode(&self) -> Self::Output {
assert_eq!(
Expand All @@ -83,8 +83,8 @@ impl Explode for MultiPointArray<2> {
}
}

impl Explode for MultiLineStringArray<2> {
type Output = (LineStringArray<2>, Option<Int32Array>);
impl Explode for MultiLineStringArray {
type Output = (LineStringArray, Option<Int32Array>);

fn explode(&self) -> Self::Output {
assert_eq!(
Expand All @@ -104,8 +104,8 @@ impl Explode for MultiLineStringArray<2> {
}
}

impl Explode for MultiPolygonArray<2> {
type Output = (PolygonArray<2>, Option<Int32Array>);
impl Explode for MultiPolygonArray {
type Output = (PolygonArray, Option<Int32Array>);

fn explode(&self) -> Self::Output {
assert_eq!(
Expand Down Expand Up @@ -147,8 +147,8 @@ impl Explode for &dyn NativeArray {
MultiPoint(_, XY) => call_explode!(as_multi_point),
MultiLineString(_, XY) => call_explode!(as_multi_line_string),
MultiPolygon(_, XY) => call_explode!(as_multi_polygon),
// Mixed(_, XY) => self.as_mixed::<2>().explode(),
// GeometryCollection(_, XY) => self.as_geometry_collection::<2>().explode(),
// Mixed(_, XY) => self.as_mixed::().explode(),
// GeometryCollection(_, XY) => self.as_geometry_collection::().explode(),
_ => return Err(GeoArrowError::IncorrectType("".into())),
};
Ok(result)
Expand Down Expand Up @@ -192,15 +192,15 @@ impl Explode for &dyn ChunkedNativeArray {
use NativeType::*;

match self.data_type() {
Point(_, XY) => self.as_point::<2>().explode(),
LineString(_, XY) => self.as_line_string::<2>().explode(),
Polygon(_, XY) => self.as_polygon::<2>().explode(),
MultiPoint(_, XY) => self.as_multi_point::<2>().explode(),
MultiLineString(_, XY) => self.as_multi_line_string::<2>().explode(),
MultiPolygon(_, XY) => self.as_multi_polygon::<2>().explode(),
Mixed(_, XY) => self.as_mixed::<2>().explode(),
GeometryCollection(_, XY) => self.as_geometry_collection::<2>().explode(),
Rect(XY) => self.as_rect::<2>().explode(),
Point(_, XY) => self.as_point::().explode(),
LineString(_, XY) => self.as_line_string::().explode(),
Polygon(_, XY) => self.as_polygon::().explode(),
MultiPoint(_, XY) => self.as_multi_point::().explode(),
MultiLineString(_, XY) => self.as_multi_line_string::().explode(),
MultiPolygon(_, XY) => self.as_multi_polygon::().explode(),
Mixed(_, XY) => self.as_mixed::().explode(),
GeometryCollection(_, XY) => self.as_geometry_collection::().explode(),
Rect(XY) => self.as_rect::().explode(),
_ => todo!(),
}
}
Expand Down
14 changes: 7 additions & 7 deletions rust/geoarrow/src/algorithm/native/type_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub trait TypeIds {
fn get_unique_type_ids(&self) -> HashSet<i16>;
}

impl TypeIds for PointArray<2> {
impl TypeIds for PointArray {
fn get_type_ids(&self) -> Int16Array {
let values = vec![0i16; self.len()];
Int16Array::new(values.into(), self.nulls().cloned())
Expand Down Expand Up @@ -67,13 +67,13 @@ macro_rules! constant_impl {
};
}

constant_impl!(LineStringArray<2>, 1);
constant_impl!(PolygonArray<2>, 3);
constant_impl!(MultiPointArray<2>, 4);
constant_impl!(MultiLineStringArray<2>, 5);
constant_impl!(MultiPolygonArray<2>, 6);
constant_impl!(LineStringArray, 1);
constant_impl!(PolygonArray, 3);
constant_impl!(MultiPointArray, 4);
constant_impl!(MultiLineStringArray, 5);
constant_impl!(MultiPolygonArray, 6);

impl TypeIds for MixedGeometryArray<2> {
impl TypeIds for MixedGeometryArray {
fn get_type_ids(&self) -> Int16Array {
use crate::scalar::Geometry::*;

Expand Down
50 changes: 12 additions & 38 deletions rust/geoarrow/src/array/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::array::metadata::ArrayMetadata;
use crate::array::wkt::WKTArray;
use crate::array::CoordType;
use crate::array::*;
use crate::datatypes::{Dimension, NativeType, SerializedType};
use crate::datatypes::{NativeType, SerializedType};
use crate::error::Result;
use crate::trait_::{NativeArrayRef, SerializedArray, SerializedArrayRef};
use crate::{ArrayBase, NativeArray};
Expand All @@ -29,45 +29,19 @@ impl NativeArrayDyn {
pub fn from_arrow_array(array: &dyn Array, field: &Field) -> Result<Self> {
let data_type = NativeType::try_from(field)?;

use Dimension::*;
use NativeType::*;
let geo_arr: Arc<dyn NativeArray> = match data_type {
Point(_, dim) => match dim {
XY => Arc::new(PointArray::try_from((array, field))?),
XYZ => Arc::new(PointArray::<3>::try_from((array, field))?),
},
LineString(_, dim) => match dim {
XY => Arc::new(LineStringArray::try_from((array, field))?),
XYZ => Arc::new(LineStringArray::<3>::try_from((array, field))?),
},
Polygon(_, dim) => match dim {
XY => Arc::new(PolygonArray::try_from((array, field))?),
XYZ => Arc::new(PolygonArray::<3>::try_from((array, field))?),
},
MultiPoint(_, dim) => match dim {
XY => Arc::new(MultiPointArray::try_from((array, field))?),
XYZ => Arc::new(MultiPointArray::<3>::try_from((array, field))?),
},
MultiLineString(_, dim) => match dim {
XY => Arc::new(MultiLineStringArray::try_from((array, field))?),
XYZ => Arc::new(MultiLineStringArray::<3>::try_from((array, field))?),
},
MultiPolygon(_, dim) => match dim {
XY => Arc::new(MultiPolygonArray::try_from((array, field))?),
XYZ => Arc::new(MultiPolygonArray::<3>::try_from((array, field))?),
},
Mixed(_, dim) => match dim {
XY => Arc::new(MixedGeometryArray::try_from((array, field))?),
XYZ => Arc::new(MixedGeometryArray::<3>::try_from((array, field))?),
},
GeometryCollection(_, dim) => match dim {
XY => Arc::new(GeometryCollectionArray::try_from((array, field))?),
XYZ => Arc::new(GeometryCollectionArray::<3>::try_from((array, field))?),
},
Rect(dim) => match dim {
XY => Arc::new(RectArray::try_from((array, field))?),
XYZ => Arc::new(RectArray::<3>::try_from((array, field))?),
},
Point(_, _) => Arc::new(PointArray::try_from((array, field))?),
LineString(_, _) => Arc::new(LineStringArray::try_from((array, field))?),
Polygon(_, _) => Arc::new(PolygonArray::try_from((array, field))?),
MultiPoint(_, _) => Arc::new(MultiPointArray::try_from((array, field))?),
MultiLineString(_, _) => Arc::new(MultiLineStringArray::try_from((array, field))?),
MultiPolygon(_, _) => Arc::new(MultiPolygonArray::try_from((array, field))?),
Mixed(_, _) => Arc::new(MixedGeometryArray::try_from((array, field))?),
GeometryCollection(_, _) => {
Arc::new(GeometryCollectionArray::try_from((array, field))?)
}
Rect(_) => Arc::new(RectArray::try_from((array, field))?),
};

Ok(Self(geo_arr))
Expand Down
Loading

0 comments on commit b561410

Please sign in to comment.