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
impl ShapefileReader
Sourcepub fn open<P: AsRef<Path>>(base_path: P) -> Result<Self>
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.
Sourcepub fn header(&self) -> &ShapefileHeader
pub fn header(&self) -> &ShapefileHeader
Returns the Shapefile header
Sourcepub fn field_descriptors(&self) -> &[FieldDescriptor]
pub fn field_descriptors(&self) -> &[FieldDescriptor]
Returns the field descriptors
Sourcepub fn index_entries(&self) -> Option<&[IndexEntry]>
pub fn index_entries(&self) -> Option<&[IndexEntry]>
Returns the index entries (if .shx was loaded)
Sourcepub fn encoding(&self) -> Option<&str>
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.
Sourcepub fn features_in_bbox(
&mut self,
min_x: f64,
min_y: f64,
max_x: f64,
max_y: f64,
) -> Result<Vec<ShapefileFeature>>
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.
Sourcepub fn iter_features(&self) -> Result<FeatureIter<'_>>
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.
Sourcepub fn read_features_where<F>(
&self,
predicate: F,
) -> Result<Vec<ShapefileFeature>>
pub fn read_features_where<F>( &self, predicate: F, ) -> Result<Vec<ShapefileFeature>>
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.
Sourcepub fn read_features_filtered(
&self,
filter: &FieldFilter,
) -> Result<Vec<ShapefileFeature>>
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.
Sourcepub fn read_features(&self) -> Result<Vec<ShapefileFeature>>
pub fn read_features(&self) -> Result<Vec<ShapefileFeature>>
Reads all features from the Shapefile