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: StringLayer / table name.
geom_type: Option<GeometryType>Declared geometry type (all features should share this type).
crs: Option<Crs>Coordinate reference system metadata.
schema: SchemaAttribute 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
impl Layer
Sourcepub fn with_geom_type(self, gt: GeometryType) -> Self
pub fn with_geom_type(self, gt: GeometryType) -> Self
Sets the layer geometry type metadata.
Sourcepub fn with_epsg(self, epsg: u32) -> Self
pub fn with_epsg(self, epsg: u32) -> Self
Alias for Layer::with_crs_epsg.
Sourcepub fn with_crs_epsg(self, epsg: u32) -> Self
pub fn with_crs_epsg(self, epsg: u32) -> Self
Sets EPSG metadata on the layer CRS.
Sourcepub fn with_crs_wkt(self, wkt: impl Into<String>) -> Self
pub fn with_crs_wkt(self, wkt: impl Into<String>) -> Self
Sets WKT metadata on the layer CRS.
Sourcepub fn set_crs_epsg(&mut self, epsg: Option<u32>)
pub fn set_crs_epsg(&mut self, epsg: Option<u32>)
Updates the CRS EPSG metadata (or clears it when None).
Sourcepub fn set_crs_wkt(&mut self, wkt: Option<String>)
pub fn set_crs_wkt(&mut self, wkt: Option<String>)
Updates the CRS WKT metadata (or clears it when None).
Sourcepub fn assign_crs_epsg(&mut self, epsg: u32)
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.
Sourcepub fn assign_crs_wkt(&mut self, wkt: &str)
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.
Sourcepub fn reproject_to_epsg(&self, dst_epsg: u32) -> Result<Self>
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().
Sourcepub fn reproject_to_epsg_with_options(
&self,
dst_epsg: u32,
options: &VectorReprojectOptions,
) -> Result<Self>
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.
Sourcepub fn reproject_from_to_epsg(
&self,
src_epsg: u32,
dst_epsg: u32,
) -> Result<Self>
pub fn reproject_from_to_epsg( &self, src_epsg: u32, dst_epsg: u32, ) -> Result<Self>
Reproject this layer between explicit source/destination EPSG codes.
Sourcepub fn reproject_from_to_epsg_with_options(
&self,
src_epsg: u32,
dst_epsg: u32,
options: &VectorReprojectOptions,
) -> Result<Self>
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.
Sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = &mut Feature>
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut Feature>
Iterates mutably over features.
Sourcepub fn add_feature(
&mut self,
geom: Option<Geometry>,
attrs: &[(&str, FieldValue)],
) -> Result<()>
pub fn add_feature( &mut self, geom: Option<Geometry>, attrs: &[(&str, FieldValue)], ) -> Result<()>
Convenience: build a feature from (name, value) pairs and push it.
Sourcepub fn bbox(&mut self) -> Option<BBox>
pub fn bbox(&mut self) -> Option<BBox>
Compute (or return cached) bounding box over all feature geometries.
Sourcepub fn features_in_bbox(&self, query: &BBox) -> Vec<&Feature>
pub fn features_in_bbox(&self, query: &BBox) -> Vec<&Feature>
Filter features whose geometry bbox intersects query.