Struct shapefile::reader::ShapeReader [−][src]
pub struct ShapeReader<T: Read> { /* fields omitted */ }
This reader only reads the .shp
and optionally the (.shx
) files
of a shapefile.
Implementations
impl<T: Read> ShapeReader<T>
[src]
impl<T: Read> ShapeReader<T>
[src]pub fn new(source: T) -> Result<Self, Error>
[src]
Creates a new ShapeReader 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
Example
use std::fs::File; let file = File::open("tests/data/line.shp")?; let reader = shapefile::ShapeReader::new(file)?;
pub fn with_shx(source: T, shx_source: T) -> Result<Self, Error>
[src]
Creates a new ShapeReader using 2 sources, one for the .shp the other for the .shx
The .shp header is read upon creation and the whole .shx file is read upon creation.
Example
use std::fs::File; let shp_file = File::open("cities.shp")?; let shx_file = File::open("cities.shx:")?; let reader = shapefile::ShapeReader::with_shx(shp_file, shx_file)?;
pub fn header(&self) -> &Header
[src]
Returns a non-mutable reference to the header read
Examples
let reader = shapefile::ShapeReader::from_path("tests/data/pointz.shp")?; let header = reader.header(); assert_eq!(header.shape_type, shapefile::ShapeType::PointZ);
pub fn read_as<S: ReadableShape>(self) -> Result<Vec<S>, 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::ShapeReader; let mut reader = ShapeReader::from_path("tests/data/linem.shp")?; let polylines_m = reader.read_as::<shapefile::PolylineM>(); // we ask for the correct type assert_eq!(polylines_m.is_ok(), true);
use shapefile::ShapeReader; let mut reader = ShapeReader::from_path("tests/data/linem.shp")?; 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
let mut reader = shapefile::ShapeReader::from_path("tests/data/multipoint.shp")?; let shapes = reader.read()?; for shape in shapes { match shape { shapefile::Shape::Multipoint(pts) => println!(" Yay Multipoints: {}", pts), _ => panic!("ups, not multipoints"), } }
pub fn iter_shapes_as<S: ReadableShape>(&mut self) -> ShapeIterator<'_, T, S>ⓘNotable traits for ShapeIterator<'a, T, S>
impl<'a, T: Read, S: ReadableShape> Iterator for ShapeIterator<'a, T, S> type Item = Result<S, Error>;
[src]
Notable traits for ShapeIterator<'a, T, S>
impl<'a, T: Read, S: ReadableShape> Iterator for ShapeIterator<'a, T, S> type Item = Result<S, Error>;
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 mut reader = shapefile::ShapeReader::from_path("tests/data/multipoint.shp")?; for multipoints in reader.iter_shapes_as::<shapefile::Multipoint>() { let points = multipoints?; println!("{}", points); }
pub fn iter_shapes(&mut self) -> ShapeIterator<'_, T, Shape>ⓘNotable traits for ShapeIterator<'a, T, S>
impl<'a, T: Read, S: ReadableShape> Iterator for ShapeIterator<'a, T, S> type Item = Result<S, Error>;
[src]
Notable traits for ShapeIterator<'a, T, S>
impl<'a, T: Read, S: ReadableShape> Iterator for ShapeIterator<'a, T, S> type Item = Result<S, Error>;
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 mut reader = shapefile::ShapeReader::from_path("tests/data/multipoint.shp")?; for shape in reader.iter_shapes() { match shape? { shapefile::Shape::Multipatch(shp) => println!("Multipoint!"), _ => println!("Other type of shape"), } }
let mut reader = shapefile::ShapeReader::from_path("tests/data/multipoint.shp")?; for shape in reader.iter_shapes() { match shape? { shapefile::Shape::Multipatch(shp) => println!("Multipoint!"), _ => println!("Other type of shape"), } }
impl<T: Read + Seek> ShapeReader<T>
[src]
impl<T: Read + Seek> ShapeReader<T>
[src]Sources that implements Seek
have access to
a few more methods that uses the index file(.shx)
pub fn read_nth_shape_as<S: ReadableShape>(
&mut self,
index: usize
) -> Option<Result<S, Error>>
[src]
&mut self,
index: usize
) -> Option<Result<S, Error>>
Reads the n
th shape of the shapefile
Important
Even though in shapefiles, shapes are indexed starting from ‘1’. this method expects indexes starting from 0.
Returns
None
if the index is out of range
Errors
This method will return an Error::MissingIndexFile
if you use it
but no .shx was found when opening the shapefile.
pub fn read_nth_shape(&mut self, index: usize) -> Option<Result<Shape, Error>>
[src]
Reads the n
th shape of the shapefile
pub fn seek(&mut self, index: usize) -> Result<(), Error>
[src]
Seek to the start of the shape at index
Error
Returns Error::MissingIndexFile if the shx file was not found by ShapeReader::from_path or the reader was not constructed with ShapeReader::with_shx
impl ShapeReader<BufReader<File>>
[src]
impl ShapeReader<BufReader<File>>
[src]Auto Trait Implementations
impl<T> RefUnwindSafe for ShapeReader<T> where
T: RefUnwindSafe,
impl<T> RefUnwindSafe for ShapeReader<T> where
T: RefUnwindSafe,
impl<T> Send for ShapeReader<T> where
T: Send,
impl<T> Send for ShapeReader<T> where
T: Send,
impl<T> Sync for ShapeReader<T> where
T: Sync,
impl<T> Sync for ShapeReader<T> where
T: Sync,
impl<T> Unpin for ShapeReader<T> where
T: Unpin,
impl<T> Unpin for ShapeReader<T> where
T: Unpin,
impl<T> UnwindSafe for ShapeReader<T> where
T: UnwindSafe,
impl<T> UnwindSafe for ShapeReader<T> where
T: UnwindSafe,