pub struct WkbBuilder<O: OffsetSizeTrait>(/* private fields */);
Expand description
The GeoArrow equivalent to Vec<Option<Wkb>>
: a mutable collection of Wkb buffers.
Converting a WkbBuilder
into a GenericWkbArray
is O(1)
.
Implementations§
Source§impl<O: OffsetSizeTrait> WkbBuilder<O>
impl<O: OffsetSizeTrait> WkbBuilder<O>
Sourcepub fn new(typ: WkbType) -> Self
pub fn new(typ: WkbType) -> Self
Creates a new empty WkbBuilder
.
Sourcepub fn with_capacity(typ: WkbType, capacity: WkbCapacity) -> Self
pub fn with_capacity(typ: WkbType, capacity: WkbCapacity) -> Self
Initializes a new WkbBuilder
with a pre-allocated capacity of slots and values.
Sourcepub fn push_geometry(
&mut self,
geom: Option<&impl GeometryTrait<T = f64>>,
) -> GeoArrowResult<()>
pub fn push_geometry( &mut self, geom: Option<&impl GeometryTrait<T = f64>>, ) -> GeoArrowResult<()>
Push a Geometry onto the end of this builder
Sourcepub fn extend_from_iter<'a>(
&mut self,
geoms: impl Iterator<Item = Option<&'a (impl GeometryTrait<T = f64> + 'a)>>,
) -> GeoArrowResult<()>
pub fn extend_from_iter<'a>( &mut self, geoms: impl Iterator<Item = Option<&'a (impl GeometryTrait<T = f64> + 'a)>>, ) -> GeoArrowResult<()>
Extend this builder from an iterator of Geometries.
Sourcepub fn from_nullable_geometries(
geoms: &[Option<impl GeometryTrait<T = f64>>],
typ: WkbType,
) -> GeoArrowResult<Self>
pub fn from_nullable_geometries( geoms: &[Option<impl GeometryTrait<T = f64>>], typ: WkbType, ) -> GeoArrowResult<Self>
Create this builder from a slice of nullable Geometries.
Sourcepub fn push_wkb(&mut self, wkb: Option<&[u8]>) -> GeoArrowResult<()>
pub fn push_wkb(&mut self, wkb: Option<&[u8]>) -> GeoArrowResult<()>
Push raw WKB bytes onto the end of this builder.
This method validates that the input bytes represent valid WKB before appending.
If the bytes are None
, a null value is appended.
§Errors
Returns an error if the input bytes are not valid WKB format.
§Example
use geoarrow_array::builder::WkbBuilder;
use geoarrow_array::GeoArrowArray;
use geoarrow_schema::WkbType;
let mut builder = WkbBuilder::<i32>::new(WkbType::default());
// Valid WKB for a Point(1.0, 2.0) in little-endian
let wkb_bytes = vec![
0x01, // Little-endian
0x01, 0x00, 0x00, 0x00, // Point type
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, // x = 1.0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, // y = 2.0
];
builder.push_wkb(Some(&wkb_bytes)).unwrap();
builder.push_wkb(None).unwrap(); // Append null
let array = builder.finish();
assert_eq!(array.len(), 2);
Sourcepub unsafe fn push_wkb_unchecked(&mut self, wkb: Option<&[u8]>)
pub unsafe fn push_wkb_unchecked(&mut self, wkb: Option<&[u8]>)
Push raw WKB bytes onto the end of this builder without validation.
This method directly appends the input bytes to the underlying buffer without
validating that they represent valid WKB. If the bytes are None
, a null value
is appended.
§Safety
This function is unsafe because it does not validate that the input bytes are valid WKB format. Calling this with invalid WKB data may result in undefined behavior when the resulting array is used with operations that assume valid WKB.
The caller must ensure that:
- The bytes represent valid WKB according to the OGC WKB specification
- The byte order (endianness) is correctly specified in the WKB header
- The geometry type and coordinates are properly encoded
§Example
use geoarrow_array::builder::WkbBuilder;
use geoarrow_array::GeoArrowArray;
use geoarrow_schema::WkbType;
let mut builder = WkbBuilder::<i32>::new(WkbType::default());
// Valid WKB for a Point(1.0, 2.0) in little-endian
let wkb_bytes = vec![
0x01, // Little-endian
0x01, 0x00, 0x00, 0x00, // Point type
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, // x = 1.0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, // y = 2.0
];
unsafe {
builder.push_wkb_unchecked(Some(&wkb_bytes));
builder.push_wkb_unchecked(None); // Append null
}
let array = builder.finish();
assert_eq!(array.len(), 2);
Sourcepub fn finish(self) -> GenericWkbArray<O>
pub fn finish(self) -> GenericWkbArray<O>
Consume this builder and convert to a GenericWkbArray.
This is O(1)
.