pub struct GeometryBuilder { /* private fields */ }
Expand description
The GeoArrow equivalent to a Vec<Option<Geometry>>
: a mutable collection of Geometries.
Each Geometry can have a different dimension. All geometries must have the same coordinate type.
This currently has the caveat that these geometries must be a primitive geometry type. This does not currently support nested GeometryCollection objects.
Converting an GeometryBuilder
into a GeometryArray
is O(1)
.
§Invariants
- All arrays must have the same coordinate layout (interleaved or separated)
Implementations§
Source§impl<'a> GeometryBuilder
impl<'a> GeometryBuilder
Sourcepub fn new(typ: GeometryType) -> Self
pub fn new(typ: GeometryType) -> Self
Creates a new empty GeometryBuilder
.
Sourcepub fn with_capacity(typ: GeometryType, capacity: GeometryCapacity) -> Self
pub fn with_capacity(typ: GeometryType, capacity: GeometryCapacity) -> Self
Creates a new GeometryBuilder
with given capacity and no validity.
Sourcepub fn with_prefer_multi(self, prefer_multi: bool) -> Self
pub fn with_prefer_multi(self, prefer_multi: bool) -> Self
Change whether to prefer multi or single arrays for new single-part geometries.
If true
, a new Point
will be added to the MultiPointBuilder
child array, a new
LineString
will be added to the MultiLineStringBuilder
child array, and a new Polygon
will be added to the MultiPolygonBuilder
child array.
This can be desired when the user wants to downcast the array to a single geometry array
later, as casting to a, say, MultiPointArray
from a GeometryArray
could be done
zero-copy.
Note that only geometries added after this method is called will be affected.
Sourcepub fn reserve(&mut self, capacity: GeometryCapacity)
pub fn reserve(&mut self, capacity: GeometryCapacity)
Reserves capacity for at least additional
more geometries.
The collection may reserve more space to speculatively avoid frequent reallocations. After
calling reserve
, capacity will be greater than or equal to self.len() + additional
.
Does nothing if capacity is already sufficient.
Sourcepub fn reserve_exact(&mut self, capacity: GeometryCapacity)
pub fn reserve_exact(&mut self, capacity: GeometryCapacity)
Reserves the minimum capacity for at least additional
more Geometries.
Unlike reserve
, this will not deliberately over-allocate to speculatively avoid
frequent allocations. After calling reserve_exact
, capacity will be greater than or equal
to self.len() + additional
. Does nothing if the capacity is already sufficient.
Note that the allocator may give the collection more space than it
requests. Therefore, capacity can not be relied upon to be precisely
minimal. Prefer reserve
if future insertions are expected.
Sourcepub fn finish(self) -> GeometryArray
pub fn finish(self) -> GeometryArray
Consume the builder and convert to an immutable GeometryArray
Sourcepub fn push_geometry(
&mut self,
value: Option<&'a impl GeometryTrait<T = f64>>,
) -> GeoArrowResult<()>
pub fn push_geometry( &mut self, value: Option<&'a impl GeometryTrait<T = f64>>, ) -> GeoArrowResult<()>
Add a new geometry to this builder
Sourcepub fn push_null(&mut self)
pub fn push_null(&mut self)
Push a null to this builder.
Adding null values to a union array is tricky, because you don’t want to add a null to a child that would otherwise be totally empty. Ideally, as few children as possible exist and are non-empty.
We handle that by pushing nulls to the first non-empty child we find. If no underlying arrays are non-empty, we add to an internal counter instead. Once the first non-empty geometry is pushed, then we flush all the “deferred nulls” to that child.
Sourcepub fn extend_from_iter(
&mut self,
geoms: impl Iterator<Item = Option<&'a (impl GeometryTrait<T = f64> + 'a)>>,
)
pub fn extend_from_iter( &mut self, geoms: impl Iterator<Item = Option<&'a (impl GeometryTrait<T = f64> + 'a)>>, )
Extend this builder with the given geometries
Sourcepub fn from_nullable_geometries(
geoms: &[Option<impl GeometryTrait<T = f64>>],
typ: GeometryType,
) -> GeoArrowResult<Self>
pub fn from_nullable_geometries( geoms: &[Option<impl GeometryTrait<T = f64>>], typ: GeometryType, ) -> GeoArrowResult<Self>
Create this builder from a slice of nullable Geometries.