diff --git a/src/array/multilinestring/mutable.rs b/src/array/multilinestring/mutable.rs index 899cd2c4..c23823b7 100644 --- a/src/array/multilinestring/mutable.rs +++ b/src/array/multilinestring/mutable.rs @@ -3,8 +3,8 @@ use std::sync::Arc; // use super::array::check; use crate::array::mutable_offset::OffsetsBuilder; use crate::array::{ - MultiLineStringArray, MutableCoordBuffer, MutableInterleavedCoordBuffer, MutablePolygonArray, - WKBArray, + CoordType, MultiLineStringArray, MutableCoordBuffer, MutableInterleavedCoordBuffer, + MutablePolygonArray, MutableSeparatedCoordBuffer, WKBArray, }; use crate::error::{GeoArrowError, Result}; use crate::geo_traits::{LineStringTrait, MultiLineStringTrait}; @@ -41,15 +41,40 @@ impl MutableMultiLineStringArray { MutablePolygonArray::new().into() } + pub fn new_with_options(coord_type: CoordType) -> Self { + Self::with_capacities_and_options(0, 0, 0, coord_type) + } + /// Creates a new [`MutableMultiLineStringArray`] with a capacity. pub fn with_capacities( coord_capacity: usize, ring_capacity: usize, geom_capacity: usize, ) -> Self { - let coords = MutableInterleavedCoordBuffer::with_capacity(coord_capacity); + Self::with_capacities_and_options( + coord_capacity, + ring_capacity, + geom_capacity, + Default::default(), + ) + } + + pub fn with_capacities_and_options( + coord_capacity: usize, + ring_capacity: usize, + geom_capacity: usize, + coord_type: CoordType, + ) -> Self { + let coords = match coord_type { + CoordType::Interleaved => MutableCoordBuffer::Interleaved( + MutableInterleavedCoordBuffer::with_capacity(coord_capacity), + ), + CoordType::Separated => MutableCoordBuffer::Separated( + MutableSeparatedCoordBuffer::with_capacity(coord_capacity), + ), + }; Self { - coords: MutableCoordBuffer::Interleaved(coords), + coords, geom_offsets: OffsetsBuilder::with_capacity(geom_capacity), ring_offsets: OffsetsBuilder::with_capacity(ring_capacity), validity: NullBufferBuilder::new(geom_capacity), diff --git a/src/array/multipoint/mutable.rs b/src/array/multipoint/mutable.rs index e48017c5..26ed09fd 100644 --- a/src/array/multipoint/mutable.rs +++ b/src/array/multipoint/mutable.rs @@ -3,8 +3,8 @@ use std::sync::Arc; // use super::array::check; use crate::array::mutable_offset::OffsetsBuilder; use crate::array::{ - MultiPointArray, MutableCoordBuffer, MutableInterleavedCoordBuffer, MutableLineStringArray, - WKBArray, + CoordType, MultiPointArray, MutableCoordBuffer, MutableInterleavedCoordBuffer, + MutableLineStringArray, MutableSeparatedCoordBuffer, WKBArray, }; use crate::error::{GeoArrowError, Result}; use crate::geo_traits::{MultiPointTrait, PointTrait}; @@ -29,14 +29,34 @@ pub struct MutableMultiPointArray { impl MutableMultiPointArray { /// Creates a new empty [`MutableMultiPointArray`]. pub fn new() -> Self { - Self::with_capacities(0, 0) + Self::new_with_options(Default::default()) } + /// Creates a new [`MutableMultiPointArray`] with a specified [`CoordType`] + pub fn new_with_options(coord_type: CoordType) -> Self { + Self::with_capacities_and_options(0, 0, coord_type) + } /// Creates a new [`MutableMultiPointArray`] with a capacity. pub fn with_capacities(coord_capacity: usize, geom_capacity: usize) -> Self { - let coords = MutableInterleavedCoordBuffer::with_capacity(coord_capacity); + Self::with_capacities_and_options(coord_capacity, geom_capacity, Default::default()) + } + + // with capacities and options enables us to write with_capacities based on this method + pub fn with_capacities_and_options( + coord_capacity: usize, + geom_capacity: usize, + coord_type: CoordType, + ) -> Self { + let coords = match coord_type { + CoordType::Interleaved => MutableCoordBuffer::Interleaved( + MutableInterleavedCoordBuffer::with_capacity(coord_capacity), + ), + CoordType::Separated => MutableCoordBuffer::Separated( + MutableSeparatedCoordBuffer::with_capacity(coord_capacity), + ), + }; Self { - coords: MutableCoordBuffer::Interleaved(coords), + coords, geom_offsets: OffsetsBuilder::with_capacity(geom_capacity), validity: NullBufferBuilder::new(geom_capacity), } diff --git a/src/array/multipolygon/mutable.rs b/src/array/multipolygon/mutable.rs index d3cf69b7..bdf3da02 100644 --- a/src/array/multipolygon/mutable.rs +++ b/src/array/multipolygon/mutable.rs @@ -3,7 +3,8 @@ use std::sync::Arc; // use super::array::check; use crate::array::mutable_offset::OffsetsBuilder; use crate::array::{ - MultiPolygonArray, MutableCoordBuffer, MutableInterleavedCoordBuffer, WKBArray, + CoordType, MultiPolygonArray, MutableCoordBuffer, MutableInterleavedCoordBuffer, + MutableSeparatedCoordBuffer, WKBArray, }; use crate::error::{GeoArrowError, Result}; use crate::geo_traits::{LineStringTrait, MultiPolygonTrait, PolygonTrait}; @@ -44,7 +45,11 @@ pub struct MutableMultiPolygonArray { impl MutableMultiPolygonArray { /// Creates a new empty [`MutableMultiPolygonArray`]. pub fn new() -> Self { - Self::with_capacities(0, 0, 0, 0) + Self::new_with_options(Default::default()) + } + + pub fn new_with_options(coord_type: CoordType) -> Self { + Self::with_capacities_and_options(0, 0, 0, 0, coord_type) } /// Creates a new [`MutableMultiPolygonArray`] with a capacity. @@ -54,9 +59,33 @@ impl MutableMultiPolygonArray { polygon_capacity: usize, geom_capacity: usize, ) -> Self { - let coords = MutableInterleavedCoordBuffer::with_capacity(coord_capacity); + Self::with_capacities_and_options( + coord_capacity, + ring_capacity, + polygon_capacity, + geom_capacity, + Default::default(), + ) + } + + pub fn with_capacities_and_options( + coord_capacity: usize, + ring_capacity: usize, + polygon_capacity: usize, + geom_capacity: usize, + coord_type: CoordType, + ) -> Self { + let coords = match coord_type { + CoordType::Interleaved => MutableCoordBuffer::Interleaved( + MutableInterleavedCoordBuffer::with_capacity(coord_capacity), + ), + CoordType::Separated => MutableCoordBuffer::Separated( + MutableSeparatedCoordBuffer::with_capacity(coord_capacity), + ), + }; + Self { - coords: MutableCoordBuffer::Interleaved(coords), + coords, geom_offsets: OffsetsBuilder::with_capacity(geom_capacity), polygon_offsets: OffsetsBuilder::with_capacity(polygon_capacity), ring_offsets: OffsetsBuilder::with_capacity(ring_capacity), diff --git a/src/array/polygon/mutable.rs b/src/array/polygon/mutable.rs index 4cee3f0c..d8af0c59 100644 --- a/src/array/polygon/mutable.rs +++ b/src/array/polygon/mutable.rs @@ -3,8 +3,8 @@ use std::sync::Arc; // use super::array::check; use crate::array::mutable_offset::OffsetsBuilder; use crate::array::{ - MutableCoordBuffer, MutableInterleavedCoordBuffer, MutableMultiLineStringArray, PolygonArray, - WKBArray, + CoordType, MutableCoordBuffer, MutableInterleavedCoordBuffer, MutableMultiLineStringArray, + MutableSeparatedCoordBuffer, PolygonArray, WKBArray, }; use crate::error::{GeoArrowError, Result}; use crate::geo_traits::{LineStringTrait, PolygonTrait}; @@ -43,15 +43,40 @@ impl MutablePolygonArray { Self::with_capacities(0, 0, 0) } + pub fn new_with_options(coord_type: CoordType) -> Self { + Self::with_capacities_and_options(0, 0, 0, coord_type) + } + /// Creates a new [`MutablePolygonArray`] with given capacities and no validity. pub fn with_capacities( coord_capacity: usize, ring_capacity: usize, geom_capacity: usize, ) -> Self { - let coords = MutableInterleavedCoordBuffer::with_capacity(coord_capacity); + Self::with_capacities_and_options( + coord_capacity, + ring_capacity, + geom_capacity, + Default::default(), + ) + } + + pub fn with_capacities_and_options( + coord_capacity: usize, + ring_capacity: usize, + geom_capacity: usize, + coord_type: CoordType, + ) -> Self { + let coords = match coord_type { + CoordType::Interleaved => MutableCoordBuffer::Interleaved( + MutableInterleavedCoordBuffer::with_capacity(coord_capacity), + ), + CoordType::Separated => MutableCoordBuffer::Separated( + MutableSeparatedCoordBuffer::with_capacity(coord_capacity), + ), + }; Self { - coords: MutableCoordBuffer::Interleaved(coords), + coords, geom_offsets: OffsetsBuilder::with_capacity(geom_capacity), ring_offsets: OffsetsBuilder::with_capacity(ring_capacity), validity: NullBufferBuilder::new(geom_capacity),