Skip to main content

Layer

Struct Layer 

Source
pub struct Layer {
    pub name: String,
    pub geom_type: Option<GeometryType>,
    pub crs: Option<Crs>,
    pub schema: Schema,
    pub features: Vec<Feature>,
    pub extent: Option<BBox>,
}
Expand description

A named collection of features sharing a geometry type and attribute schema.

This is the central data structure that all format drivers produce and consume.

§Example

use wbvector::feature::{Layer, FieldDef, FieldType};
use wbvector::geometry::{Geometry, GeometryType};

let mut layer = Layer::new("cities")
    .with_geom_type(GeometryType::Point)
    .with_epsg(4326);

layer.add_field(FieldDef::new("name",       FieldType::Text));
layer.add_field(FieldDef::new("population", FieldType::Integer));

layer.add_feature(Some(Geometry::point(-0.12, 51.5)), &[
    ("name", "London".into()),
    ("population", 9_000_000i64.into()),
])?;

Fields§

§name: String

Layer / table name.

§geom_type: Option<GeometryType>

Declared geometry type (all features should share this type).

§crs: Option<Crs>

Coordinate reference system metadata.

§schema: Schema

Attribute field schema.

§features: Vec<Feature>

Features in insertion order.

§extent: Option<BBox>

Cached bounding box (populated on first call to Layer::bbox).

Implementations§

Source§

impl Layer

Source

pub fn new(name: impl Into<String>) -> Self

Creates an empty layer with the provided name.

Source

pub fn with_geom_type(self, gt: GeometryType) -> Self

Sets the layer geometry type metadata.

Source

pub fn with_epsg(self, epsg: u32) -> Self

Source

pub fn with_crs(self, crs: Crs) -> Self

Sets complete CRS metadata.

Source

pub fn with_crs_epsg(self, epsg: u32) -> Self

Sets EPSG metadata on the layer CRS.

Source

pub fn with_crs_wkt(self, wkt: impl Into<String>) -> Self

Sets WKT metadata on the layer CRS.

Source

pub fn crs_epsg(&self) -> Option<u32>

Returns the CRS EPSG code metadata, if available.

Source

pub fn crs_wkt(&self) -> Option<&str>

Returns the CRS WKT metadata, if available.

Source

pub fn set_crs_epsg(&mut self, epsg: Option<u32>)

Updates the CRS EPSG metadata (or clears it when None).

Source

pub fn set_crs_wkt(&mut self, wkt: Option<String>)

Updates the CRS WKT metadata (or clears it when None).

Source

pub fn assign_crs_epsg(&mut self, epsg: u32)

Assign a CRS to this layer using an EPSG code.

Replaces the entire crs struct with a new Crs containing only the EPSG code. Any existing wkt field is cleared to ensure CRS consistency.

Source

pub fn assign_crs_wkt(&mut self, wkt: &str)

Assign a CRS to this layer using WKT text.

Replaces the entire crs struct with a new Crs containing only the WKT definition. Any existing epsg field is cleared to ensure CRS consistency.

Source

pub fn reproject_to_epsg(&self, dst_epsg: u32) -> Result<Self>

Reproject this layer to a destination EPSG code.

Source CRS is read from self.crs_epsg().

Source

pub fn reproject_to_epsg_with_options( &self, dst_epsg: u32, options: &VectorReprojectOptions, ) -> Result<Self>

Reproject this layer to a destination EPSG code with options.

Source

pub fn reproject_from_to_epsg( &self, src_epsg: u32, dst_epsg: u32, ) -> Result<Self>

Reproject this layer between explicit source/destination EPSG codes.

Source

pub fn reproject_from_to_epsg_with_options( &self, src_epsg: u32, dst_epsg: u32, options: &VectorReprojectOptions, ) -> Result<Self>

Reproject this layer between explicit source/destination EPSG codes with options.

Source

pub fn add_field(&mut self, def: FieldDef)

Adds a field definition to the layer schema.

Source

pub fn push(&mut self, f: Feature)

Appends a feature to the layer.

Source

pub fn len(&self) -> usize

Returns number of features.

Source

pub fn is_empty(&self) -> bool

Returns true when there are no features.

Source

pub fn iter(&self) -> impl Iterator<Item = &Feature>

Iterates over features.

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut Feature>

Iterates mutably over features.

Source

pub fn add_feature( &mut self, geom: Option<Geometry>, attrs: &[(&str, FieldValue)], ) -> Result<()>

Convenience: build a feature from (name, value) pairs and push it.

Source

pub fn bbox(&mut self) -> Option<BBox>

Compute (or return cached) bounding box over all feature geometries.

Source

pub fn features_in_bbox(&self, query: &BBox) -> Vec<&Feature>

Filter features whose geometry bbox intersects query.

Trait Implementations§

Source§

impl Clone for Layer

Source§

fn clone(&self) -> Layer

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 Layer

Source§

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

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

impl Index<usize> for Layer

Source§

type Output = Feature

The returned type after indexing.
Source§

fn index(&self, i: usize) -> &Feature

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<usize> for Layer

Source§

fn index_mut(&mut self, i: usize) -> &mut Feature

Performs the mutable indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl Freeze for Layer

§

impl RefUnwindSafe for Layer

§

impl Send for Layer

§

impl Sync for Layer

§

impl Unpin for Layer

§

impl UnsafeUnpin for Layer

§

impl UnwindSafe for Layer

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.