Skip to main content

Geometry

Enum Geometry 

Source
#[non_exhaustive]
pub enum Geometry { Point(Coord), LineString(LineString), Polygon(Polygon), MultiPoint(Vec<Coord>), MultiLineString(Vec<LineString>), MultiPolygon(Vec<Polygon>), GeometryCollection(Vec<Geometry>), Empty(GeometryType), }
Expand description

The geometry tree. Marked #[non_exhaustive] so future SemVer-minor releases can add variants (curves, surfaces, Z/M-bearing variants once the IR grows past 2D).

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Point(Coord)

§

LineString(LineString)

§

Polygon(Polygon)

§

MultiPoint(Vec<Coord>)

§

MultiLineString(Vec<LineString>)

§

MultiPolygon(Vec<Polygon>)

§

GeometryCollection(Vec<Geometry>)

§

Empty(GeometryType)

A typed-empty geometry (e.g. POINT EMPTY, POLYGON EMPTY). The tag is preserved so WKB serialization round-trips correctly.

Implementations§

Source§

impl Geometry

Source

pub fn type_of(&self) -> GeometryType

Source

pub fn is_empty(&self) -> bool

Source

pub fn coord_count(&self) -> usize

Total coordinate count across the geometry tree. O(N) walk.

This is the right number to use when budgeting memory for an operation that scales with vertex density (Hilbert sort, geometry simplification, WKB encode). A single polygon with 100 000 vertices charges 100 000; a MultiPolygon of 50 such parts charges 5 000 000 — feature count alone hides this asymmetry.

Source

pub fn has_z(&self) -> bool

True if any coordinate in the tree carries a Z ordinate.

Source

pub fn bbox(&self) -> Option<[f64; 4]>

Compute the 2D bounding box [xmin, ymin, xmax, ymax].

Returns None for empty geometries (no coordinates to bound). NaN coordinates are skipped, so POINT EMPTY (stored as NaN/NaN) also yields None.

Source

pub fn has_m(&self) -> bool

True if any coordinate in the tree carries an M ordinate.

Source§

impl Geometry

Source

pub fn to_wkb(&self) -> Vec<u8>

Encode as OGC Simple Features Well-Known Binary (little-endian, 2D).

Source

pub fn write_wkb_into(&self, buf: &mut Vec<u8>)

Encode WKB into a caller-provided buffer (clears it first). Useful for row-by-row writers that want to reuse a scratch buffer.

Source§

impl Geometry

Source

pub fn from_wkb(bytes: &[u8]) -> Result<Self>

Decode OGC Simple Features WKB bytes into a Geometry.

Accepts both little-endian and big-endian, and respects per-nested byte-order bytes inside collections (the ISO WKB rule).

v0.1 returns Error::Unsupported for Z/M variants — the type code is recognized but ordinates beyond X/Y are not decoded.

Trait Implementations§

Source§

impl Clone for Geometry

Source§

fn clone(&self) -> Geometry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Geometry

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Geometry

Source§

fn eq(&self, other: &Geometry) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Geometry

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.