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

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

struct that reads the content of a shapefile

Methods

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

pub fn new(source: T) -> Result<Reader<T>, Error>
[src]

Creates a new Reader from a source that implements the Read trait

The Shapefile header is read upon creation (but no reading of the Shapes is done)

Errors

Will forward any std::io::Error

Will also return an error if the data is not a shapefile (Wrong file code)

Will also return an error if the shapetype read from the input source is invalid

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

Returns a non-mutable reference to the header read

Examples

let reader = shapefile::Reader::from_path("tests/data/pointz.shp").unwrap();
let header = reader.header();
assert_eq!(header.shape_type, shapefile::ShapeType::PointZ);

pub fn read_as<S: ReadableShape>(self) -> Result<Vec<S::ReadShape>, Error>
[src]

Reads all the shape as shape of a certain type.

To be used if you know in advance which shape type the file contains.

Errors

The function has an additional error that is returned if the shape type you asked to be read does not match the actual shape type in the file.

Examples

use shapefile::Reader;
let mut reader = Reader::from_path("tests/data/linem.shp").unwrap();
let polylines_m = reader.read_as::<shapefile::PolylineM>().unwrap(); // we ask for the correct type
use shapefile::Reader;
let mut reader = Reader::from_path("tests/data/linem.shp").unwrap();
let polylines = reader.read_as::<shapefile::Polyline>(); // we ask for the wrong type
assert_eq!(polylines.is_err(), true);

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

Reads all the shapes and returns them

Examples

use shapefile::Reader;
let mut reader = Reader::from_path("tests/data/multipoint.shp").unwrap();
let shapes = reader.read().unwrap();
for shape in shapes {
    match shape {
        shapefile::Shape::Multipoint(pts) => println!(" Yay Multipoints: {}", pts),
        _ => panic!("ups, not multipoints"),
    }
}

Important traits for ShapeIterator<T, S>
pub fn iter_shapes_as<S: ReadableShape>(self) -> ShapeIterator<T, S>
[src]

Returns an iterator that tries to read the shapes as the specified type Will return an error of the type S does not match the actual type in the file

Examples

let reader = shapefile::Reader::from_path("tests/data/multipoint.shp").unwrap();
for multipoints in reader.iter_shapes_as::<shapefile::Multipoint>() {
    let points = multipoints.unwrap();
    println!("{}", points);
}

Important traits for ShapeIterator<T, S>
pub fn iter_shapes(self) -> ShapeIterator<T, Shape>
[src]

Returns an iterator that to reads the shapes wraps them in the enum Shape You do not need to call this method and can iterate over the Reader directly

Examples

let reader = shapefile::Reader::from_path("tests/data/multipoint.shp").unwrap();
for shape in reader.iter_shapes() {
    match shape.unwrap() {
        shapefile::Shape::Multipatch(shp) => println!("Multipoint!"),
        _ => println!("Other type of shape"),
    }
}
let reader = shapefile::Reader::from_path("tests/data/multipoint.shp").unwrap();
for shape in reader {
    match shape.unwrap() {
        shapefile::Shape::Multipatch(shp) => println!("Multipoint!"),
        _ => println!("Other type of shape"),
    }
}

pub fn add_index_source(&mut self, source: T) -> Result<(), Error>
[src]

Reads the index file from the source This allows to later read shapes by giving their index without reading the whole file

(see Reader::read_nth_shape())

impl Reader<BufReader<File>>
[src]

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

Creates a reader from a path to a file

Examples

use shapefile::Reader;
let mut reader = Reader::from_path("tests/data/line.shp").unwrap();
let polylines = reader.read_as::<shapefile::Polyline>().unwrap();

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

pub fn read_nth_shape_as<S: ReadableShape>(
    &mut self,
    index: usize
) -> Option<Result<S::ReadShape, Error>>
[src]

Reads the nth shape of the shapefile

Returns

None if the index is out of range or if no index file was added prior to calling this function

Examples

use shapefile::FileReaderBuilder;
let mut reader = FileReaderBuilder::new("tests/data/line.shp").with_index().build().unwrap();
let shape = reader.read_nth_shape_as::<shapefile::Polyline>(117);
assert_eq!(shape.is_none(), true);

let shape = reader.read_nth_shape_as::<shapefile::Polyline>(0);
assert_eq!(shape.is_some(), true)

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

Reads the nth shape of the shapefile

Returns

None if the index is out of range or if no index file was added prior to calling this function

Examples

use shapefile::FileReaderBuilder;
let mut reader = FileReaderBuilder::new("tests/data/line.shp").with_index().build().unwrap();
let shape = reader.read_nth_shape(117);
assert_eq!(shape.is_none(), true);

let shape = reader.read_nth_shape(0);
assert_eq!(shape.is_some(), true)
use shapefile::Reader;
let mut reader = Reader::from_path("tests/data/line.shp").unwrap();
let shape = reader.read_nth_shape(0);
assert_eq!(shape.is_none(), true); // We didn't give the shx file

Trait Implementations

impl<T: Read> IntoIterator for Reader<T>
[src]

type Item = Result<Shape, Error>

The type of the elements being iterated over.

type IntoIter = ShapeIterator<T, Shape>

Which kind of iterator are we turning this into?

Auto Trait Implementations

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

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

Blanket Implementations

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

impl<T> From for T
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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