pub struct Reader<T: Read + Seek, D: Read + Seek> { /* private fields */ }
Expand description
Reader that reads a shapefile.
The recommended way to create a Reader is by using its Reader::from_path associated function as it will take care of opening the .shx and .dbf files corresponding to the .shp and return an error in case some mandatory files are missing.
If you want to read a shapefile that is not stored in a file (e.g the shp data is in a buffer), you will have to construct the Reader “by hand” with its Reader::new associated function.
Implementations§
source§impl<T: Read + Seek, D: Read + Seek> Reader<T, D>
impl<T: Read + Seek, D: Read + Seek> Reader<T, D>
sourcepub fn new(shape_reader: ShapeReader<T>, dbase_reader: Reader<D>) -> Self
pub fn new(shape_reader: ShapeReader<T>, dbase_reader: Reader<D>) -> Self
Creates a new Reader from both a ShapeReader (.shp, .shx) and dbase::Reader (.dbf)
pub fn iter_shapes_and_records_as<S: ReadableShape, R: ReadableRecord>( &mut self ) -> ShapeRecordIterator<'_, T, D, S, R> ⓘ
sourcepub fn iter_shapes_and_records(
&mut self
) -> ShapeRecordIterator<'_, T, D, Shape, Record> ⓘ
pub fn iter_shapes_and_records( &mut self ) -> ShapeRecordIterator<'_, T, D, Shape, Record> ⓘ
Returns an iterator that returns both the shape and the record
§Example
let mut reader = shapefile::Reader::from_path("tests/data/multipatch.shp")?;
for shape_record in reader.iter_shapes_and_records() {
let (shape, record) = shape_record?;
println!("Geometry: {}, Properties {:?}", shape, record);
}
pub fn read_as<S: ReadableShape, R: ReadableRecord>( &mut self ) -> Result<Vec<(S, R)>, Error>
sourcepub fn seek(&mut self, index: usize) -> Result<(), Error>
pub fn seek(&mut self, index: usize) -> Result<(), Error>
Seeks to the start of the shape at index
sourcepub fn shape_count(&self) -> Result<usize, Error>
pub fn shape_count(&self) -> Result<usize, Error>
Returns the number of shapes in the shapefile
sourcepub fn into_table_info(self) -> TableInfo
pub fn into_table_info(self) -> TableInfo
Consumes the self and returns the dbase table info which can be given to TableWriterBuild or crate::Writer::from_path_with_info to create a shapefile where the .dbf file has the same structure as the .dbf read by this reader
source§impl Reader<BufReader<File>, BufReader<File>>
impl Reader<BufReader<File>, BufReader<File>>
sourcepub fn from_path<P: AsRef<Path>>(path: P) -> Result<Self, Error>
pub fn from_path<P: AsRef<Path>>(path: P) -> Result<Self, Error>
Creates a reader from a path the .shp file
Will attempt to read both the .shx
and .dbf
associated with the file,
If the .shx
is not found, no error will be returned,
however seek will fail is used.
If the .dbf
is not found Error::MissingDbf will be return as the error.
§Examples
use std::path::Path;
assert_eq!(Path::new("tests/data/linem.dbf").exists(), false);
assert_eq!(Path::new("tests/data/linem.shx").exists(), false);
// .dbf file not found, the reader can't be created
let mut reader = shapefile::Reader::from_path("tests/data/linem.shp");
assert_eq!(reader.is_err(), true);
assert_eq!(Path::new("tests/data/multipatch.dbf").exists(), true);
// The dbf file exists, the reader can be created
let mut reader = shapefile::Reader::from_path("tests/data/multipatch.shp");
assert_eq!(reader.is_err(), false);