Struct shapefile::reader::Reader

source ·
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>

source

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)

source

pub fn header(&self) -> &Header

Returns the header of the .shp file

source

pub fn iter_shapes_and_records_as<S: ReadableShape, R: ReadableRecord>( &mut self ) -> ShapeRecordIterator<'_, T, D, S, R>

source

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);
}
source

pub fn read_as<S: ReadableShape, R: ReadableRecord>( &mut self ) -> Result<Vec<(S, R)>, Error>

source

pub fn read(&mut self) -> Result<Vec<(Shape, Record)>, Error>

Read all the shape and record and returns them in a Vec

§Example
let mut reader = shapefile::Reader::from_path("tests/data/multipatch.shp")?;
let data = reader.read()?;
source

pub fn seek(&mut self, index: usize) -> Result<(), Error>

Seeks to the start of the shape at index

source

pub fn shape_count(&self) -> Result<usize, Error>

Returns the number of shapes in the shapefile

See ShapeReader::shape_count

source

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

source

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);

Auto Trait Implementations§

§

impl<T, D> Freeze for Reader<T, D>
where D: Freeze, T: Freeze,

§

impl<T, D> !RefUnwindSafe for Reader<T, D>

§

impl<T, D> Send for Reader<T, D>
where D: Send, T: Send,

§

impl<T, D> !Sync for Reader<T, D>

§

impl<T, D> Unpin for Reader<T, D>
where D: Unpin, T: Unpin,

§

impl<T, D> !UnwindSafe for Reader<T, D>

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

§

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

§

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.