pub struct Reader<T: Read> { /* fields omitted */ }
struct that reads the content of a shapefile
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)
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
Returns a non-mutable reference to the header read
let reader = shapefile::Reader::from_path("tests/data/pointz.shp").unwrap();
let header = reader.header();
assert_eq!(header.shape_type, shapefile::ShapeType::PointZ);
Reads all the shape as shape of a certain type.
To be used if you know in advance which shape type the file contains.
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.
use shapefile::Reader;
let mut reader = Reader::from_path("tests/data/linem.shp").unwrap();
let polylines_m = reader.read_as::<shapefile::PolylineM>().unwrap();
use shapefile::Reader;
let mut reader = Reader::from_path("tests/data/linem.shp").unwrap();
let polylines = reader.read_as::<shapefile::Polyline>();
assert_eq!(polylines.is_err(), true);
Reads all the shapes and returns them
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"),
}
}
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
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);
}
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
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"),
}
}
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()
)
Creates a reader from a path to a file
use shapefile::Reader;
let mut reader = Reader::from_path("tests/data/line.shp").unwrap();
let polylines = reader.read_as::<shapefile::Polyline>().unwrap();
Reads the n
th shape of the shapefile
None
if the index is out of range or if no index file was added prior to
calling this function
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)
Reads the n
th shape of the shapefile
None
if the index is out of range or if no index file was added prior to
calling this function
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);
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?
type Error = !
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
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.
🔬 This is a nightly-only experimental API. (try_from
)
Mutably borrows from an owned value. Read more