[−][src]Struct shapefile::reader::Reader
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
Example
use std::fs::File; let file = File::open("tests/data/line.shp").unwrap(); let reader = shapefile::Reader::new(file).unwrap();
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>, 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"), } }
pub fn read_records(self) -> Result<Vec<Record>, Error>
[src]
Read and return only the records contained in the .dbf file
ⓘ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 iter_shapes_and_records_as<S: ReadableShape>(
self
) -> Result<ShapeRecordIterator<T, S>, Error>
[src]
self
) -> Result<ShapeRecordIterator<T, S>, Error>
Returns an iterator over the Shapes and their Records
Errors
The Result
will be an error if the .dbf wasn't found
Example
use shapefile::{Reader, Multipatch}; let reader = Reader::from_path("tests/data/multipatch.shp").unwrap(); for result in reader.iter_shapes_and_records_as::<Multipatch>().unwrap() { let (shape, record) = result.unwrap(); // ... }
pub fn iter_shapes_and_records(
self
) -> Result<ShapeRecordIterator<T, Shape>, Error>
[src]
self
) -> Result<ShapeRecordIterator<T, Shape>, Error>
Returns an iterator over the Shapes and their Records
Errors
The Result
will be an error if the .dbf wasn't found
Example
use shapefile::{Reader, Shape}; let reader = Reader::from_path("tests/data/multipatch.shp").unwrap(); for result in reader.iter_shapes_and_records().unwrap() { let (shape, record) = result.unwrap(); match shape { Shape::Multipatch(multip) => {/*...*/ }, //.. _ => { /*...*/ } } // ... }
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 read_nth_shape())
pub fn add_dbf_source(&mut self, source: T) -> Result<(), Error>
[src]
Adds the source
as the source where the dbf record will be read from
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
Will attempt to read both the .shx and .dbf associated with the file, if they do not exists the function will not fail, and you will get an error later if you try to use a function that requires the file to be present.
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); // both .shx and .dbf does not exists, but creation does not fail let mut reader = shapefile::Reader::from_path("tests/data/linem.shp").unwrap(); let result = reader.iter_shapes_and_records(); assert_eq!(result.is_err(), true); assert_eq!(Path::new("tests/data/multipatch.dbf").exists(), true); let mut reader = shapefile::Reader::from_path("tests/data/multipatch.shp").unwrap(); let result = reader.iter_shapes_and_records(); assert_eq!(result.is_err(), false);
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]
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
Trait Implementations
impl<T: Read> IntoIterator for Reader<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Reader<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Reader<T> where
T: Send,
T: Send,
impl<T> Sync for Reader<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Reader<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Reader<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
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?
fn into_iter(self) -> I
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,