From 11abe7326cd6deb6cc28031fd7e6c4f06b02bc46 Mon Sep 17 00:00:00 2001 From: Kyle Barron Date: Fri, 20 Dec 2024 17:55:07 -0500 Subject: [PATCH] Deny missing docs from `geoarrow::scalar` (#958) --- js/src/algorithm/geo/skew.rs | 34 +++++++++--------- js/src/lib.rs | 4 +-- rust/geoarrow/src/array/binary/array.rs | 4 ++- rust/geoarrow/src/array/mod.rs | 2 -- rust/geoarrow/src/array/wkt/array.rs | 8 ++--- rust/geoarrow/src/io/mod.rs | 2 +- rust/geoarrow/src/scalar/binary/mod.rs | 1 - rust/geoarrow/src/scalar/binary/owned.rs | 2 +- rust/geoarrow/src/scalar/binary/scalar.rs | 8 ++++- .../src/scalar/coord/combined/scalar.rs | 5 +++ .../src/scalar/coord/interleaved/scalar.rs | 3 ++ .../src/scalar/coord/separated/scalar.rs | 3 ++ rust/geoarrow/src/scalar/geometry/scalar.rs | 12 ++++++- .../src/scalar/geometrycollection/scalar.rs | 7 ++-- rust/geoarrow/src/scalar/linestring/scalar.rs | 6 ++-- rust/geoarrow/src/scalar/mod.rs | 31 +++++++++------- .../src/scalar/multilinestring/scalar.rs | 8 +++-- rust/geoarrow/src/scalar/multipoint/scalar.rs | 6 ++-- .../src/scalar/multipolygon/scalar.rs | 6 ++-- rust/geoarrow/src/scalar/point/scalar.rs | 6 ++-- rust/geoarrow/src/scalar/polygon/scalar.rs | 8 +++-- rust/geoarrow/src/scalar/rect/scalar.rs | 8 +++-- rust/geoarrow/src/scalar/scalar.rs | 36 +++++++++++-------- 23 files changed, 137 insertions(+), 73 deletions(-) diff --git a/js/src/algorithm/geo/skew.rs b/js/src/algorithm/geo/skew.rs index 45a1c68bd..1926b8633 100644 --- a/js/src/algorithm/geo/skew.rs +++ b/js/src/algorithm/geo/skew.rs @@ -1,6 +1,6 @@ use crate::broadcasting::BroadcastableFloat; use crate::data::*; -use crate::scalar::Point; +// use crate::scalar::Point; use wasm_bindgen::prelude::*; macro_rules! impl_skew { @@ -28,22 +28,22 @@ macro_rules! impl_skew { Skew::skew_xy(&self.0, °rees_x.0, °rees_y.0).into() } - /// An affine transformation which skews a geometry around a point of `origin`, sheared - /// by an angle along the x and y dimensions. - /// - /// The point of origin is *usually* given as the 2D bounding box centre of the - /// geometry, in which case you can just use [`skew`](Self::skew) or - /// [`skew_xy`](Self::skew_xy), but this method allows you to specify any point. - #[wasm_bindgen(js_name = skewAroundPoint)] - pub fn skew_around_point( - &self, - degrees_x: BroadcastableFloat, - degrees_y: BroadcastableFloat, - origin: Point, - ) -> Self { - use geoarrow::algorithm::geo::Skew; - Skew::skew_around_point(&self.0, °rees_x.0, °rees_y.0, origin.0.into()).into() - } + // /// An affine transformation which skews a geometry around a point of `origin`, sheared + // /// by an angle along the x and y dimensions. + // /// + // /// The point of origin is *usually* given as the 2D bounding box centre of the + // /// geometry, in which case you can just use [`skew`](Self::skew) or + // /// [`skew_xy`](Self::skew_xy), but this method allows you to specify any point. + // #[wasm_bindgen(js_name = skewAroundPoint)] + // pub fn skew_around_point( + // &self, + // degrees_x: BroadcastableFloat, + // degrees_y: BroadcastableFloat, + // origin: Point, + // ) -> Self { + // use geoarrow::algorithm::geo::Skew; + // Skew::skew_around_point(&self.0, °rees_x.0, °rees_y.0, origin.0.into()).into() + // } } }; } diff --git a/js/src/lib.rs b/js/src/lib.rs index b58989b53..129c3d45c 100644 --- a/js/src/lib.rs +++ b/js/src/lib.rs @@ -9,8 +9,8 @@ pub mod ffi; pub mod io; // #[cfg(feature = "geodesy")] // pub mod reproject; -#[cfg(feature = "scalar")] -pub mod scalar; +// #[cfg(feature = "scalar")] +// pub mod scalar; #[cfg(feature = "vector")] pub mod vector; // pub mod transform_origin; diff --git a/rust/geoarrow/src/array/binary/array.rs b/rust/geoarrow/src/array/binary/array.rs index 0ed44fcde..98ca6d765 100644 --- a/rust/geoarrow/src/array/binary/array.rs +++ b/rust/geoarrow/src/array/binary/array.rs @@ -21,7 +21,9 @@ use geo_traits::GeometryTrait; /// /// This array implements [`SerializedArray`], not [`NativeArray`]. This means that you'll need to /// parse the `WKBArray` into a native-typed GeoArrow array (such as -/// [`PointArray`][crate::array::PointArray]) before using it for computations. +/// [`GeometryArray`][crate::array::GeometryArray]) before using it for computations. +/// +/// Refer to [`crate::io::wkb`] for encoding and decoding this array to the native array types. #[derive(Debug, Clone, PartialEq)] pub struct WKBArray { pub(crate) data_type: SerializedType, diff --git a/rust/geoarrow/src/array/mod.rs b/rust/geoarrow/src/array/mod.rs index ce69c4a35..f7f2acc92 100644 --- a/rust/geoarrow/src/array/mod.rs +++ b/rust/geoarrow/src/array/mod.rs @@ -53,8 +53,6 @@ //! second pass. //! -// #![allow(missing_docs)] // FIXME - pub use binary::{WKBArray, WKBBuilder, WKBCapacity}; pub use cast::{AsChunkedNativeArray, AsNativeArray, AsSerializedArray}; pub use coord::{ diff --git a/rust/geoarrow/src/array/wkt/array.rs b/rust/geoarrow/src/array/wkt/array.rs index d4333f7f6..758dfd150 100644 --- a/rust/geoarrow/src/array/wkt/array.rs +++ b/rust/geoarrow/src/array/wkt/array.rs @@ -19,10 +19,10 @@ use crate::ArrayBase; /// /// This is semantically equivalent to `Vec>` due to the internal validity bitmap. /// -/// This array _can_ be used directly for operations, but that will incur costly encoding to and -/// from WKT on every operation. Instead, you usually want to use the WKBArray only for -/// serialization purposes (e.g. to and from [GeoParquet](https://geoparquet.org/)) but convert to -/// strongly-typed arrays (such as the [`PointArray`][crate::array::PointArray]) for computations. +/// This is a wrapper around an Arrow [GenericStringArray], but additionally stores an +/// [ArrayMetadata] so that we can persist CRS information about the data. +/// +/// Refer to [`crate::io::wkt`] for encoding and decoding this array to the native array types. #[derive(Debug, Clone, PartialEq)] pub struct WKTArray { pub(crate) data_type: SerializedType, diff --git a/rust/geoarrow/src/io/mod.rs b/rust/geoarrow/src/io/mod.rs index a3ee35575..9aa976320 100644 --- a/rust/geoarrow/src/io/mod.rs +++ b/rust/geoarrow/src/io/mod.rs @@ -1,5 +1,5 @@ //! Reader and writer implementations of many common geospatial file formats, including -//! interoperability with the `geozero` crate. +//! interoperability with the [`geozero`] crate. #![allow(missing_docs)] // FIXME diff --git a/rust/geoarrow/src/scalar/binary/mod.rs b/rust/geoarrow/src/scalar/binary/mod.rs index 41c1da296..65b59a795 100644 --- a/rust/geoarrow/src/scalar/binary/mod.rs +++ b/rust/geoarrow/src/scalar/binary/mod.rs @@ -1,5 +1,4 @@ mod owned; mod scalar; -pub use owned::OwnedWKB; pub use scalar::WKB; diff --git a/rust/geoarrow/src/scalar/binary/owned.rs b/rust/geoarrow/src/scalar/binary/owned.rs index 8b321e1af..b6b866641 100644 --- a/rust/geoarrow/src/scalar/binary/owned.rs +++ b/rust/geoarrow/src/scalar/binary/owned.rs @@ -9,7 +9,7 @@ pub struct OwnedWKB { } impl OwnedWKB { - pub fn new(arr: GenericBinaryArray, geom_index: usize) -> Self { + pub(crate) fn new(arr: GenericBinaryArray, geom_index: usize) -> Self { Self { arr, geom_index } } } diff --git a/rust/geoarrow/src/scalar/binary/scalar.rs b/rust/geoarrow/src/scalar/binary/scalar.rs index d5035717a..d823e3d2c 100644 --- a/rust/geoarrow/src/scalar/binary/scalar.rs +++ b/rust/geoarrow/src/scalar/binary/scalar.rs @@ -10,6 +10,11 @@ use rstar::{RTreeObject, AABB}; /// /// This is zero-cost to _create_ from a [WKBArray] but the WKB has not been preprocessed yet, so /// it's not constant-time to access coordinate values. +/// +/// This does not directly implement [GeometryTrait], because it first needs to be parsed. Use +/// [`parse`] to access an opaque object that does implement [GeometryTrait]. +/// +/// [`parse`]: WKB::parse #[derive(Debug, Clone)] pub struct WKB<'a, O: OffsetSizeTrait> { pub(crate) arr: &'a GenericBinaryArray, @@ -27,12 +32,13 @@ impl<'a, O: OffsetSizeTrait> WKB<'a, O> { self.as_ref() } - pub fn into_owned_inner(self) -> (GenericBinaryArray, usize) { + pub(crate) fn into_owned_inner(self) -> (GenericBinaryArray, usize) { // TODO: hard slice? // let owned = self.into_owned(); (self.arr.clone(), self.geom_index) } + /// Parse this WKB buffer to a geometry. pub fn parse(&self) -> Result + use<'_, O>> { Ok(wkb::reader::read_wkb(self.as_ref())?) } diff --git a/rust/geoarrow/src/scalar/coord/combined/scalar.rs b/rust/geoarrow/src/scalar/coord/combined/scalar.rs index 447538371..e3eeb52db 100644 --- a/rust/geoarrow/src/scalar/coord/combined/scalar.rs +++ b/rust/geoarrow/src/scalar/coord/combined/scalar.rs @@ -5,9 +5,14 @@ use crate::trait_::NativeScalar; use geo_traits::to_geo::ToGeoCoord; use geo_traits::CoordTrait; +/// An Arrow equivalent of a Coord +/// +/// This implements [CoordTrait], which you can use to extract data. #[derive(Debug, Clone)] pub enum Coord<'a> { + /// Separated coordinate Separated(SeparatedCoord<'a>), + /// Interleaved coordinate Interleaved(InterleavedCoord<'a>), } diff --git a/rust/geoarrow/src/scalar/coord/interleaved/scalar.rs b/rust/geoarrow/src/scalar/coord/interleaved/scalar.rs index 9c8cb372e..3f2d36cc3 100644 --- a/rust/geoarrow/src/scalar/coord/interleaved/scalar.rs +++ b/rust/geoarrow/src/scalar/coord/interleaved/scalar.rs @@ -8,6 +8,9 @@ use crate::trait_::NativeScalar; use geo_traits::to_geo::ToGeoCoord; use geo_traits::CoordTrait; +/// An Arrow equivalent of a Coord +/// +/// This implements [CoordTrait], which you can use to extract data. #[derive(Debug, Clone)] pub struct InterleavedCoord<'a> { pub(crate) coords: &'a ScalarBuffer, diff --git a/rust/geoarrow/src/scalar/coord/separated/scalar.rs b/rust/geoarrow/src/scalar/coord/separated/scalar.rs index 0a71b5aa8..278a9fe8e 100644 --- a/rust/geoarrow/src/scalar/coord/separated/scalar.rs +++ b/rust/geoarrow/src/scalar/coord/separated/scalar.rs @@ -7,6 +7,9 @@ use geo_traits::to_geo::ToGeoCoord; use geo_traits::CoordTrait; use rstar::{RTreeObject, AABB}; +/// An Arrow equivalent of a Coord +/// +/// This implements [CoordTrait], which you can use to extract data. #[derive(Debug, Clone)] pub struct SeparatedCoord<'a> { pub(crate) buffers: &'a [ScalarBuffer; 4], diff --git a/rust/geoarrow/src/scalar/geometry/scalar.rs b/rust/geoarrow/src/scalar/geometry/scalar.rs index f0bd18068..f745df596 100644 --- a/rust/geoarrow/src/scalar/geometry/scalar.rs +++ b/rust/geoarrow/src/scalar/geometry/scalar.rs @@ -9,16 +9,26 @@ use geo_traits::{ }; use rstar::{RTreeObject, AABB}; -/// A Geometry is an enum over the various underlying _zero copy_ GeoArrow scalar types. +/// An Arrow equivalent of a Geometry +/// +/// This implements [GeometryTrait], which you can use to extract data. #[derive(Debug)] pub enum Geometry<'a> { + /// Point geometry Point(crate::scalar::Point<'a>), + /// LineString geometry LineString(crate::scalar::LineString<'a>), + /// Polygon geometry Polygon(crate::scalar::Polygon<'a>), + /// MultiPoint geometry MultiPoint(crate::scalar::MultiPoint<'a>), + /// MultiLineString geometry MultiLineString(crate::scalar::MultiLineString<'a>), + /// MultiPolygon geometry MultiPolygon(crate::scalar::MultiPolygon<'a>), + /// GeometryCollection geometry GeometryCollection(crate::scalar::GeometryCollection<'a>), + /// Rect geometry Rect(crate::scalar::Rect<'a>), } diff --git a/rust/geoarrow/src/scalar/geometrycollection/scalar.rs b/rust/geoarrow/src/scalar/geometrycollection/scalar.rs index 635b2800d..fc3a9ad2c 100644 --- a/rust/geoarrow/src/scalar/geometrycollection/scalar.rs +++ b/rust/geoarrow/src/scalar/geometrycollection/scalar.rs @@ -12,6 +12,8 @@ use geo_traits::GeometryCollectionTrait; use rstar::{RTreeObject, AABB}; /// An Arrow equivalent of a GeometryCollection +/// +/// This implements [GeometryCollectionTrait], which you can use to extract data. #[derive(Debug, Clone)] pub struct GeometryCollection<'a> { pub(crate) array: &'a MixedGeometryArray, @@ -25,7 +27,7 @@ pub struct GeometryCollection<'a> { } impl<'a> GeometryCollection<'a> { - pub fn new( + pub(crate) fn new( array: &'a MixedGeometryArray, geom_offsets: &'a OffsetBuffer, geom_index: usize, @@ -39,7 +41,8 @@ impl<'a> GeometryCollection<'a> { } } - pub fn into_inner(&self) -> (&MixedGeometryArray, &OffsetBuffer, usize) { + #[allow(clippy::wrong_self_convention)] + pub(crate) fn into_inner(&self) -> (&MixedGeometryArray, &OffsetBuffer, usize) { (self.array, self.geom_offsets, self.geom_index) } } diff --git a/rust/geoarrow/src/scalar/linestring/scalar.rs b/rust/geoarrow/src/scalar/linestring/scalar.rs index b27508eab..f8f3f7d4b 100644 --- a/rust/geoarrow/src/scalar/linestring/scalar.rs +++ b/rust/geoarrow/src/scalar/linestring/scalar.rs @@ -10,6 +10,8 @@ use geo_traits::LineStringTrait; use rstar::{RTreeObject, AABB}; /// An Arrow equivalent of a LineString +/// +/// This implements [LineStringTrait], which you can use to extract data. #[derive(Debug, Clone)] pub struct LineString<'a> { pub(crate) coords: &'a CoordBuffer, @@ -23,7 +25,7 @@ pub struct LineString<'a> { } impl<'a> LineString<'a> { - pub fn new( + pub(crate) fn new( coords: &'a CoordBuffer, geom_offsets: &'a OffsetBuffer, geom_index: usize, @@ -37,7 +39,7 @@ impl<'a> LineString<'a> { } } - pub fn into_owned_inner(self) -> (CoordBuffer, OffsetBuffer, usize) { + pub(crate) fn into_owned_inner(self) -> (CoordBuffer, OffsetBuffer, usize) { ( self.coords.clone(), self.geom_offsets.clone(), diff --git a/rust/geoarrow/src/scalar/mod.rs b/rust/geoarrow/src/scalar/mod.rs index 34d5c37f6..6f1fb43e6 100644 --- a/rust/geoarrow/src/scalar/mod.rs +++ b/rust/geoarrow/src/scalar/mod.rs @@ -1,18 +1,25 @@ //! GeoArrow scalars, which are references onto a full GeoArrow array at a specific index. -#![allow(missing_docs)] // FIXME - -pub use binary::{OwnedWKB, WKB}; +pub use binary::WKB; pub use coord::{Coord, InterleavedCoord, SeparatedCoord}; -pub use geometry::{Geometry, OwnedGeometry}; -pub use geometrycollection::{GeometryCollection, OwnedGeometryCollection}; -pub use linestring::{LineString, OwnedLineString}; -pub use multilinestring::{MultiLineString, OwnedMultiLineString}; -pub use multipoint::{MultiPoint, OwnedMultiPoint}; -pub use multipolygon::{MultiPolygon, OwnedMultiPolygon}; -pub use point::{OwnedPoint, Point}; -pub use polygon::{OwnedPolygon, Polygon}; -pub use rect::{OwnedRect, Rect}; +pub use geometry::Geometry; +pub(crate) use geometry::OwnedGeometry; +pub use geometrycollection::GeometryCollection; +pub(crate) use geometrycollection::OwnedGeometryCollection; +pub use linestring::LineString; +pub(crate) use linestring::OwnedLineString; +pub use multilinestring::MultiLineString; +pub(crate) use multilinestring::OwnedMultiLineString; +pub use multipoint::MultiPoint; +pub(crate) use multipoint::OwnedMultiPoint; +pub use multipolygon::MultiPolygon; +pub(crate) use multipolygon::OwnedMultiPolygon; +pub(crate) use point::OwnedPoint; +pub use point::Point; +pub(crate) use polygon::OwnedPolygon; +pub use polygon::Polygon; +pub(crate) use rect::OwnedRect; +pub use rect::Rect; pub use scalar::GeometryScalar; mod binary; diff --git a/rust/geoarrow/src/scalar/multilinestring/scalar.rs b/rust/geoarrow/src/scalar/multilinestring/scalar.rs index da5b34866..a65cdbb0f 100644 --- a/rust/geoarrow/src/scalar/multilinestring/scalar.rs +++ b/rust/geoarrow/src/scalar/multilinestring/scalar.rs @@ -10,6 +10,8 @@ use geo_traits::MultiLineStringTrait; use rstar::{RTreeObject, AABB}; /// An Arrow equivalent of a MultiLineString +/// +/// This implements [MultiLineStringTrait], which you can use to extract data. #[derive(Debug, Clone)] pub struct MultiLineString<'a> { pub(crate) coords: &'a CoordBuffer, @@ -26,7 +28,7 @@ pub struct MultiLineString<'a> { } impl<'a> MultiLineString<'a> { - pub fn new( + pub(crate) fn new( coords: &'a CoordBuffer, geom_offsets: &'a OffsetBuffer, ring_offsets: &'a OffsetBuffer, @@ -42,7 +44,9 @@ impl<'a> MultiLineString<'a> { } } - pub fn into_owned_inner(self) -> (CoordBuffer, OffsetBuffer, OffsetBuffer, usize) { + pub(crate) fn into_owned_inner( + self, + ) -> (CoordBuffer, OffsetBuffer, OffsetBuffer, usize) { ( self.coords.clone(), self.geom_offsets.clone(), diff --git a/rust/geoarrow/src/scalar/multipoint/scalar.rs b/rust/geoarrow/src/scalar/multipoint/scalar.rs index 090fd409f..3e8f96c8f 100644 --- a/rust/geoarrow/src/scalar/multipoint/scalar.rs +++ b/rust/geoarrow/src/scalar/multipoint/scalar.rs @@ -11,6 +11,8 @@ use geo_traits::MultiPointTrait; use rstar::{RTreeObject, AABB}; /// An Arrow equivalent of a MultiPoint +/// +/// This implements [MultiPointTrait], which you can use to extract data. #[derive(Debug, Clone)] pub struct MultiPoint<'a> { /// Buffer of coordinates @@ -25,7 +27,7 @@ pub struct MultiPoint<'a> { } impl<'a> MultiPoint<'a> { - pub fn new( + pub(crate) fn new( coords: &'a CoordBuffer, geom_offsets: &'a OffsetBuffer, geom_index: usize, @@ -39,7 +41,7 @@ impl<'a> MultiPoint<'a> { } } - pub fn into_owned_inner(self) -> (CoordBuffer, OffsetBuffer, usize) { + pub(crate) fn into_owned_inner(self) -> (CoordBuffer, OffsetBuffer, usize) { ( self.coords.clone(), self.geom_offsets.clone(), diff --git a/rust/geoarrow/src/scalar/multipolygon/scalar.rs b/rust/geoarrow/src/scalar/multipolygon/scalar.rs index 1b2995a9c..d3d08b70c 100644 --- a/rust/geoarrow/src/scalar/multipolygon/scalar.rs +++ b/rust/geoarrow/src/scalar/multipolygon/scalar.rs @@ -11,6 +11,8 @@ use geo_traits::MultiPolygonTrait; use rstar::{RTreeObject, AABB}; /// An Arrow equivalent of a MultiPolygon +/// +/// This implements [MultiPolygonTrait], which you can use to extract data. #[derive(Debug, Clone)] pub struct MultiPolygon<'a> { pub(crate) coords: &'a CoordBuffer, @@ -30,7 +32,7 @@ pub struct MultiPolygon<'a> { } impl<'a> MultiPolygon<'a> { - pub fn new( + pub(crate) fn new( coords: &'a CoordBuffer, geom_offsets: &'a OffsetBuffer, polygon_offsets: &'a OffsetBuffer, @@ -48,7 +50,7 @@ impl<'a> MultiPolygon<'a> { } } - pub fn into_owned_inner( + pub(crate) fn into_owned_inner( self, ) -> ( CoordBuffer, diff --git a/rust/geoarrow/src/scalar/point/scalar.rs b/rust/geoarrow/src/scalar/point/scalar.rs index 2fe4cd7cf..7a4f41e52 100644 --- a/rust/geoarrow/src/scalar/point/scalar.rs +++ b/rust/geoarrow/src/scalar/point/scalar.rs @@ -8,6 +8,8 @@ use geo_traits::PointTrait; use rstar::{RTreeObject, AABB}; /// An Arrow equivalent of a Point +/// +/// This implements [PointTrait], which you can use to extract data. #[derive(Debug, Clone)] pub struct Point<'a> { coords: &'a CoordBuffer, @@ -15,11 +17,11 @@ pub struct Point<'a> { } impl<'a> Point<'a> { - pub fn new(coords: &'a CoordBuffer, geom_index: usize) -> Self { + pub(crate) fn new(coords: &'a CoordBuffer, geom_index: usize) -> Self { Point { coords, geom_index } } - pub fn into_owned_inner(self) -> (CoordBuffer, usize) { + pub(crate) fn into_owned_inner(self) -> (CoordBuffer, usize) { (self.coords.clone(), self.geom_index) } } diff --git a/rust/geoarrow/src/scalar/polygon/scalar.rs b/rust/geoarrow/src/scalar/polygon/scalar.rs index ec47f02b5..57c018a02 100644 --- a/rust/geoarrow/src/scalar/polygon/scalar.rs +++ b/rust/geoarrow/src/scalar/polygon/scalar.rs @@ -11,6 +11,8 @@ use geo_traits::PolygonTrait; use rstar::{RTreeObject, AABB}; /// An Arrow equivalent of a Polygon +/// +/// This implements [PolygonTrait], which you can use to extract data. #[derive(Debug, Clone)] pub struct Polygon<'a> { pub(crate) coords: &'a CoordBuffer, @@ -27,7 +29,7 @@ pub struct Polygon<'a> { } impl<'a> Polygon<'a> { - pub fn new( + pub(crate) fn new( coords: &'a CoordBuffer, geom_offsets: &'a OffsetBuffer, ring_offsets: &'a OffsetBuffer, @@ -43,7 +45,9 @@ impl<'a> Polygon<'a> { } } - pub fn into_owned_inner(self) -> (CoordBuffer, OffsetBuffer, OffsetBuffer, usize) { + pub(crate) fn into_owned_inner( + self, + ) -> (CoordBuffer, OffsetBuffer, OffsetBuffer, usize) { ( self.coords.clone(), self.geom_offsets.clone(), diff --git a/rust/geoarrow/src/scalar/rect/scalar.rs b/rust/geoarrow/src/scalar/rect/scalar.rs index 1b8cd0141..3557bae76 100644 --- a/rust/geoarrow/src/scalar/rect/scalar.rs +++ b/rust/geoarrow/src/scalar/rect/scalar.rs @@ -7,6 +7,9 @@ use crate::trait_::NativeScalar; use geo_traits::to_geo::ToGeoRect; use geo_traits::RectTrait; +/// An Arrow equivalent of a Rect +/// +/// This implements [RectTrait], which you can use to extract data. #[derive(Debug, Clone)] pub struct Rect<'a> { lower: &'a SeparatedCoordBuffer, @@ -15,7 +18,7 @@ pub struct Rect<'a> { } impl<'a> Rect<'a> { - pub fn new( + pub(crate) fn new( lower: &'a SeparatedCoordBuffer, upper: &'a SeparatedCoordBuffer, geom_index: usize, @@ -26,7 +29,8 @@ impl<'a> Rect<'a> { geom_index, } } - pub fn into_owned_inner(self) -> (SeparatedCoordBuffer, SeparatedCoordBuffer, usize) { + + pub(crate) fn into_owned_inner(self) -> (SeparatedCoordBuffer, SeparatedCoordBuffer, usize) { // TODO: make hard slice? (self.lower.clone(), self.upper.clone(), self.geom_index) } diff --git a/rust/geoarrow/src/scalar/scalar.rs b/rust/geoarrow/src/scalar/scalar.rs index 5c6c37f3a..55445a47e 100644 --- a/rust/geoarrow/src/scalar/scalar.rs +++ b/rust/geoarrow/src/scalar/scalar.rs @@ -16,6 +16,7 @@ use crate::trait_::{ArrayAccessor, NativeArrayRef, NativeScalar}; pub struct GeometryScalar(NativeArrayRef); impl GeometryScalar { + /// Create a new scalar from an array of length 1 pub fn try_new(array: NativeArrayRef) -> Result { if array.len() != 1 { Err(GeoArrowError::General(format!( @@ -27,19 +28,29 @@ impl GeometryScalar { } } + /// The data type of this scalar pub fn data_type(&self) -> NativeType { self.0.data_type() } + /// Access the underlying array. + /// + /// The array will have a single element. pub fn inner(&self) -> &NativeArrayRef { &self.0 } + /// Access the underlying array. + /// + /// The array will have a single element. pub fn into_inner(self) -> NativeArrayRef { self.0 } - pub fn dimension(&self) -> Dimension { + /// Access the underlying dimension + /// + /// If the type of the array is `Geometry`, dimension will be `None`. + pub fn dimension(&self) -> Option { use NativeType::*; match self.data_type() { Point(_, dim) @@ -49,22 +60,12 @@ impl GeometryScalar { | MultiLineString(_, dim) | MultiPolygon(_, dim) | GeometryCollection(_, dim) - | Rect(dim) => dim, - Geometry(_) => todo!(), // WKB => { - // let arr = self.0.as_ref(); - // let wkb_arr = arr.as_wkb().value(0); - // let wkb_obj = wkb_arr.to_wkb_object(); - // wkb_obj.dimension() - // } - // LargeWKB => { - // let arr = self.0.as_ref(); - // let wkb_arr = arr.as_large_wkb().value(0); - // let wkb_obj = wkb_arr.to_wkb_object(); - // wkb_obj.dimension() - // } + | Rect(dim) => Some(dim), + Geometry(_) => None, } } + /// Convert to a [Geometry] pub fn as_geometry(&self) -> Option> { // Note: we use `.downcast_ref` directly here because we need to pass in the generic // TODO: may be able to change this now that we don't have @@ -122,6 +123,7 @@ impl GeometryScalar { } } + /// Convert to a [geo::Geometry]. pub fn to_geo(&self) -> geo::Geometry { macro_rules! impl_to_geo { ($cast_func:ident) => {{ @@ -144,6 +146,7 @@ impl GeometryScalar { } } + /// Convert to a [geo::Point]. pub fn to_geo_point(&self) -> Result { match self.to_geo() { geo::Geometry::Point(g) => Ok(g), @@ -154,6 +157,7 @@ impl GeometryScalar { } } + /// Convert to a [geo::LineString]. pub fn to_geo_line_string(&self) -> Result { match self.to_geo() { geo::Geometry::LineString(g) => Ok(g), @@ -164,6 +168,7 @@ impl GeometryScalar { } } + /// Convert to a [geo::Polygon]. pub fn to_geo_polygon(&self) -> Result { match self.to_geo() { geo::Geometry::Polygon(g) => Ok(g), @@ -174,6 +179,7 @@ impl GeometryScalar { } } + /// Convert to a [geo::MultiPoint]. pub fn to_geo_multi_point(&self) -> Result { match self.to_geo() { geo::Geometry::MultiPoint(g) => Ok(g), @@ -184,6 +190,7 @@ impl GeometryScalar { } } + /// Convert to a [geo::MultiLineString]. pub fn to_geo_multi_line_string(&self) -> Result { match self.to_geo() { geo::Geometry::MultiLineString(g) => Ok(g), @@ -194,6 +201,7 @@ impl GeometryScalar { } } + /// Convert to a [geo::MultiPolygon]. pub fn to_geo_multi_polygon(&self) -> Result { match self.to_geo() { geo::Geometry::MultiPolygon(g) => Ok(g),