Struct shapefile::reader::Reader[][src]

pub struct Reader<T: Read + Seek> { /* fields omitted */ }

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

impl<T: Read + Seek> Reader<T>[src]

pub fn new(shape_reader: ShapeReader<T>, dbase_reader: Reader<T>) -> Self[src]

Creates a new Reader from both a ShapeReader (.shp, .shx) and dbase::Reader (.dbf)

pub fn header(&self) -> &Header[src]

Returns the header of the .shp file

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

Notable traits for ShapeRecordIterator<'a, T, S, R>

impl<'a, T: Read + Seek, S: ReadableShape, R: ReadableRecord> Iterator for ShapeRecordIterator<'a, T, S, R> type Item = Result<(S, R), Error>;
[src]

pub fn iter_shapes_and_records(
    &mut self
) -> ShapeRecordIterator<'_, T, Shape, Record>

Notable traits for ShapeRecordIterator<'a, T, S, R>

impl<'a, T: Read + Seek, S: ReadableShape, R: ReadableRecord> Iterator for ShapeRecordIterator<'a, T, S, R> type Item = Result<(S, R), Error>;
[src]

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>
[src]

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

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

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

Seeks to the start of the shape at index

pub fn into_table_info(self) -> TableInfo[src]

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

impl Reader<BufReader<File>>[src]

pub fn from_path<P: AsRef<Path>>(path: P) -> Result<Self, Error>[src]

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> RefUnwindSafe for Reader<T> where
    T: RefUnwindSafe

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

impl<T> Sync for Reader<T> where
    T: Sync

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

impl<T> UnwindSafe for Reader<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.