WkbBuilder

Struct WkbBuilder 

Source
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>

Source

pub fn new(typ: WkbType) -> Self

Creates a new empty WkbBuilder.

Source

pub fn with_capacity(typ: WkbType, capacity: WkbCapacity) -> Self

Initializes a new WkbBuilder with a pre-allocated capacity of slots and values.

Source

pub fn push_geometry( &mut self, geom: Option<&impl GeometryTrait<T = f64>>, ) -> GeoArrowResult<()>

Push a Geometry onto the end of this builder

Source

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.

Source

pub fn from_nullable_geometries( geoms: &[Option<impl GeometryTrait<T = f64>>], typ: WkbType, ) -> GeoArrowResult<Self>

Create this builder from a slice of nullable Geometries.

Source

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);
Source

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);
Source

pub fn finish(self) -> GenericWkbArray<O>

Consume this builder and convert to a GenericWkbArray.

This is O(1).

Trait Implementations§

Source§

impl<O: Debug + OffsetSizeTrait> Debug for WkbBuilder<O>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<O> Freeze for WkbBuilder<O>

§

impl<O> RefUnwindSafe for WkbBuilder<O>
where O: RefUnwindSafe,

§

impl<O> Send for WkbBuilder<O>

§

impl<O> Sync for WkbBuilder<O>

§

impl<O> Unpin for WkbBuilder<O>
where O: Unpin,

§

impl<O> UnwindSafe for WkbBuilder<O>
where O: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,