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"),
}
}
Read and return only the records contained in the .dbf file
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()
)
Adds the source
as the source where the dbf record will be read from
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.
Eg: If you open a file "SummonersRift.shp" and no file "SummonersRift.dbf" exists, the from_path
constructor won't fail because the .dbf wasn't found, however if you try to
use
use std::path::Path;
assert_eq!(Path::new("tests/data/linem.dbf").exists(), false);
assert_eq!(Path::new("tests/data/linem.shx").exists(), false);
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();
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
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
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
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
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static