Trait GeoArrowArrayAccessor

Source
pub trait GeoArrowArrayAccessor<'a>: GeoArrowArray {
    type Item: Send + Sync + GeometryTrait<T = f64>;

    // Required method
    unsafe fn value_unchecked(
        &'a self,
        index: usize,
    ) -> GeoArrowResult<Self::Item>;

    // Provided methods
    fn value(&'a self, index: usize) -> GeoArrowResult<Self::Item> { ... }
    fn get(&'a self, index: usize) -> GeoArrowResult<Option<Self::Item>> { ... }
    unsafe fn get_unchecked(
        &'a self,
        index: usize,
    ) -> Option<GeoArrowResult<Self::Item>> { ... }
    fn iter(
        &'a self,
    ) -> impl ExactSizeIterator<Item = Option<GeoArrowResult<Self::Item>>> + 'a { ... }
    fn iter_values(
        &'a self,
    ) -> impl ExactSizeIterator<Item = GeoArrowResult<Self::Item>> + 'a { ... }
}
Expand description

A trait for accessing the values of a GeoArrowArray.

§Performance

Accessing a geometry from a “native” array, such as PointArray, MultiPolygonArray or GeometryArray will always be constant-time and zero-copy.

Accessing a geometry from a “serialized” array such as GenericWkbArray or GenericWktArray will trigger some amount of parsing. In the case of GenericWkbArray, accessing an item will read the WKB header and scan the buffer if needed to find internal geometry offsets, but will not copy any internal coordinates. This allows for later access to be constant-time (though not necessarily zero-copy, since WKB is not byte-aligned). In the case of GenericWktArray, accessing a geometry will fully parse the WKT string and copy coordinates to a separate representation. This means that calling .iter() on a GenericWktArray will transparently fully parse every row.

§Validity

A GeoArrowArrayAccessor must always return a well-defined value for an index that is within the bounds 0..Array::len, including for null indexes where Array::is_null is true.

The value at null indexes is unspecified, and implementations must not rely on a specific value such as Default::default being returned, however, it must not be undefined.

Required Associated Types§

Source

type Item: Send + Sync + GeometryTrait<T = f64>

The geoarrow scalar object for this geometry array type.

Required Methods§

Source

unsafe fn value_unchecked(&'a self, index: usize) -> GeoArrowResult<Self::Item>

Returns the element at index i, not considering validity.

§Examples
use geo_traits::{CoordTrait, PointTrait};

let point1 = geo_types::point!(x: 1., y: 2.);

let point_type = PointType::new(Dimension::XY, Default::default());
let point_array =
    PointBuilder::from_nullable_points([Some(&point1), None].into_iter(), point_type.clone())
        .finish();

let coord = unsafe { point_array.value_unchecked(0) }
    .unwrap()
    .coord()
    .unwrap();
assert_eq!(coord.x(), 1.);
assert_eq!(coord.y(), 2.);
§Errors

Errors for invalid WKT and WKB geometries. Will never error for native arrays.

§Safety

Caller is responsible for ensuring that the index is within the bounds of the array

Provided Methods§

Source

fn value(&'a self, index: usize) -> GeoArrowResult<Self::Item>

Returns the element at index i, not considering validity.

§Examples
use geo_traits::{CoordTrait, PointTrait};

let point1 = geo_types::point!(x: 1., y: 2.);

let point_type = PointType::new(Dimension::XY, Default::default());
let point_array =
    PointBuilder::from_nullable_points([Some(&point1), None].into_iter(), point_type.clone())
        .finish();

let coord = point_array.value(0).unwrap().coord().unwrap();
assert_eq!(coord.x(), 1.);
assert_eq!(coord.y(), 2.);
§Errors

Errors for invalid WKT and WKB geometries. Will never error for native arrays.

§Panics

Panics if the value is outside the bounds of the array.

Source

fn get(&'a self, index: usize) -> GeoArrowResult<Option<Self::Item>>

Returns the value at slot i as an Arrow scalar, considering validity.

§Examples
let point1 = geo_types::point!(x: 1., y: 2.);

let point_type = PointType::new(Dimension::XY, Default::default());
let point_array =
    PointBuilder::from_nullable_points([Some(&point1), None].into_iter(), point_type.clone())
        .finish();

assert!(point_array.get(0).unwrap().is_some());
assert!(point_array.get(1).unwrap().is_none());
§Errors

Errors for invalid WKT and WKB geometries. Will never error for native arrays.

Source

unsafe fn get_unchecked( &'a self, index: usize, ) -> Option<GeoArrowResult<Self::Item>>

Returns the value at slot i as an Arrow scalar, considering validity.

§Errors

Errors for invalid WKT and WKB geometries. Will never error for native arrays.

§Safety

Caller is responsible for ensuring that the index is within the bounds of the array

Source

fn iter( &'a self, ) -> impl ExactSizeIterator<Item = Option<GeoArrowResult<Self::Item>>> + 'a

Iterates over this array’s geoarrow scalar values, considering validity.

§Errors

Errors for invalid WKT and WKB geometries. Will never error for native arrays.

Source

fn iter_values( &'a self, ) -> impl ExactSizeIterator<Item = GeoArrowResult<Self::Item>> + 'a

Iterator over geoarrow scalar values, not considering validity.

§Errors

Errors for invalid WKT and WKB geometries. Will never error for native arrays.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§