Trait geoarrow2::trait_::GeometryArrayTrait
source · pub trait GeometryArrayTrait<'a>: Debug + Send + Sync {
Show 19 methods
// Required methods
fn as_any(&self) -> &dyn Any;
fn data_type(&self) -> &GeoDataType;
fn storage_type(&self) -> DataType;
fn extension_field(&self) -> Arc<Field>;
fn extension_name(&self) -> &str;
fn into_array_ref(self) -> ArrayRef;
fn with_coords(self, coords: CoordBuffer) -> Self;
fn coord_type(&self) -> CoordType;
fn into_coord_type(self, coord_type: CoordType) -> Self;
fn len(&self) -> usize;
fn validity(&self) -> Option<&NullBuffer>;
fn slice(&self, offset: usize, length: usize) -> Self;
fn owned_slice(&self, offset: usize, length: usize) -> Self;
// Provided methods
fn is_empty(&self) -> bool { ... }
fn nulls(&self) -> Option<&NullBuffer> { ... }
fn logical_nulls(&self) -> Option<NullBuffer> { ... }
fn null_count(&self) -> usize { ... }
fn is_null(&self, i: usize) -> bool { ... }
fn is_valid(&self, i: usize) -> bool { ... }
}
Expand description
A trait of common methods that all geometry arrays in this crate implement.
Required Methods§
sourcefn as_any(&self) -> &dyn Any
fn as_any(&self) -> &dyn Any
Returns the array as Any
so that it can be
downcasted to a specific implementation.
Example:
//use geoarrow2::datatypes::GeoDataType;
//use geoarrow2::array::PointArray;
//use geoarrow2::GeometryArrayTrait;
//use geo::point;
//let point = point!(x: 1., y: 2.);
//let point_array: PointArray = vec![point].into();
//let geometry_array = Arc::new(point_array) as Arc<dyn GeometryArrayTrait>;
let id = Int32Array::from(vec![1, 2, 3, 4, 5]);
let batch = RecordBatch::try_new(
Arc::new(Schema::new(vec![Field::new("id", DataType::Int32, false)])),
vec![Arc::new(id)]
).unwrap();
let int32array = batch
.column(0)
.as_any()
.downcast_ref::<Int32Array>()
.expect("Failed to downcast");
sourcefn data_type(&self) -> &GeoDataType
fn data_type(&self) -> &GeoDataType
Returns a reference to the DataType
of this array.
Example:
use geoarrow2::datatypes::GeoDataType;
use geoarrow2::array::PointArray;
use geoarrow2::GeometryArrayTrait;
use geo::point;
let point = point!(x: 1., y: 2.);
let point_array: PointArray = vec![point].into();
assert!(matches!(point_array.data_type(), GeoDataType::Point(_)));
sourcefn storage_type(&self) -> DataType
fn storage_type(&self) -> DataType
Get the logical DataType of this array.
sourcefn extension_field(&self) -> Arc<Field>
fn extension_field(&self) -> Arc<Field>
Get the extension type of this array, as defined by the GeoArrow specification.
Always returns DataType::Extension
.
sourcefn extension_name(&self) -> &str
fn extension_name(&self) -> &str
Get the extension name of this array.
sourcefn into_array_ref(self) -> ArrayRef
fn into_array_ref(self) -> ArrayRef
sourcefn with_coords(self, coords: CoordBuffer) -> Self
fn with_coords(self, coords: CoordBuffer) -> Self
Create a new array with replaced coordinates
This is useful if you want to apply an operation to every coordinate in unison, such as a reprojection or a scaling operation, with no regards to each individual geometry
sourcefn coord_type(&self) -> CoordType
fn coord_type(&self) -> CoordType
Get the coordinate type of this geometry array, either interleaved or separated.
sourcefn into_coord_type(self, coord_type: CoordType) -> Self
fn into_coord_type(self, coord_type: CoordType) -> Self
Cast the coordinate buffer of this geometry array to the given coordinate type.
sourcefn validity(&self) -> Option<&NullBuffer>
fn validity(&self) -> Option<&NullBuffer>
Access the array’s validity. Every array has an optional NullBuffer
that, when available
specifies whether the array slot is valid or not (null). When the validity is None
, all
slots are valid.
sourcefn slice(&self, offset: usize, length: usize) -> Self
fn slice(&self, offset: usize, length: usize) -> Self
Returns a zero-copy slice of this array with the indicated offset and length.
Panic
This function panics iff offset + length > self.len()
.
sourcefn owned_slice(&self, offset: usize, length: usize) -> Self
fn owned_slice(&self, offset: usize, length: usize) -> Self
A slice that fully copies the contents of the underlying buffer
Provided Methods§
fn nulls(&self) -> Option<&NullBuffer>
fn logical_nulls(&self) -> Option<NullBuffer>
sourcefn null_count(&self) -> usize
fn null_count(&self) -> usize
The number of null slots in this array.
Implementation
This is O(1)
since the number of null elements is pre-computed.