Skip to main content

ShapefileReader

Struct ShapefileReader 

Source
pub struct ShapefileReader {
    pub crs: Option<String>,
    pub encoding: Option<String>,
    /* private fields */
}
Expand description

Shapefile reader that coordinates .shp, .dbf, and optionally .shx files

Fields§

§crs: Option<String>

CRS as WKT string from .prj file (if present)

§encoding: Option<String>

Character encoding from .cpg file (if present)

Implementations§

Source§

impl ShapefileReader

Source

pub fn open<P: AsRef<Path>>(base_path: P) -> Result<Self>

Opens a Shapefile from a base path (without extension)

Reads the .shp, .dbf, and optionally .shx, .prj, and .cpg files.

Source

pub fn header(&self) -> &ShapefileHeader

Returns the Shapefile header

Source

pub fn field_descriptors(&self) -> &[FieldDescriptor]

Returns the field descriptors

Source

pub fn index_entries(&self) -> Option<&[IndexEntry]>

Returns the index entries (if .shx was loaded)

Source

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

Returns the CRS as a WKT string, if a .prj file was present

Source

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

Returns the character encoding name from the .cpg file, if present

Common values: "UTF-8", "CP1252", "ISO-8859-1". NOTE: Non-UTF-8 encodings are not yet transcoded; DBF fields use String::from_utf8_lossy as a fallback.

Source

pub fn features_in_bbox( &mut self, min_x: f64, min_y: f64, max_x: f64, max_y: f64, ) -> Result<Vec<ShapefileFeature>>

Returns features whose bounding box intersects the given query bbox.

Reads all shape records from .shp and .dbf, then filters to those whose bounding box overlaps [min_x, min_y, max_x, max_y] (inclusive). Point shapes use the point coordinate as a degenerate bbox. Null shapes are excluded.

For large shapefiles this reads all geometry upfront; a full R-tree spatial index backed by lazy .shx seeks is a follow-up item.

Source

pub fn iter_features(&self) -> Result<FeatureIter<'_>>

Returns a streaming iterator over the Shapefile’s features.

Unlike read_features, which loads everything into memory, this opens fresh buffered readers and reads one SHP record + one DBF record per Iterator::next call. Memory usage is therefore O(1) with respect to the number of features.

§Errors

Returns an error if the .shp or .dbf files cannot be opened, or if the header/field-descriptor section cannot be read. Individual record errors are surfaced as Err items from the iterator.

Source

pub fn read_features_where<F>( &self, predicate: F, ) -> Result<Vec<ShapefileFeature>>
where F: Fn(&ShapefileFeature) -> bool,

Reads features that satisfy an arbitrary predicate closure.

This is a convenience wrapper over ShapefileReader::read_features that filters the result set in-place without a second allocation. The predicate receives a shared reference to each ShapefileFeature and returns true for features that should be included in the output.

For structured attribute comparisons prefer read_features_filtered, which accepts a crate::filter::FieldFilter directly.

§Errors

Propagates any I/O or parse errors from the underlying read.

Source

pub fn read_features_filtered( &self, filter: &FieldFilter, ) -> Result<Vec<ShapefileFeature>>

Reads features that match a structured crate::filter::FieldFilter.

This is a thin convenience method over read_features_where that accepts a crate::filter::FieldFilter directly.

§Errors

Propagates any I/O or parse errors from the underlying read.

Source

pub fn read_features(&self) -> Result<Vec<ShapefileFeature>>

Reads all features from the Shapefile

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