[−][src]Module shapefile::reader
Reader module, contains the definitions of the types that a user should use to read a file
The Reader is the struct that actually reads the file from any source as long as it implements the
Read
Trait (std::fs::File
, and std::io::Cursor
for example).
It is recommended to create a Reader
using its
from_path method as this constructor
will take care of opening the .shx and .dbf files corresponding to the .shp (if they exists).
If you want to read a shapefile that is not storred in a file (e.g the shp data is in a buffer),
you will have to construct the Reader
"by hand" with its new method.
If you want the "manually" constructed Reader
to also read the shx and dbf file content
you will have to use add_index_source and/or
add_dbf_source
Examples
When reading from a file:
Creates a reader from a path, then iterate over its Shapes
, reading one shape each iteration
let reader = shapefile::Reader::from_path("tests/data/pointm.shp")?; for shape in reader { let shape = shape?; println!("{}", shape); }
Creates a reader from a path, reads the whole file at once
let shapes = shapefile::Reader::from_path("tests/data/pointm.shp") .and_then(|rdr| rdr.read());
If you know beforehand the exact type that the .shp file is made of,
you can use the different *_as::<S>()
functions.:
- read_as To read all the shapes as the specified type
- iter_shapes_as To iterate over the shapes as shapes of the specified type
- iter_shapes_and_records_as To iterate over both the shapes and records
Otherwise use the functions that return Shapes and do a match
Two functions (read and read_as) are provided to read
files with one function call (thus not having to build a Reader
)
Structs
Reader | struct that reads the content of a shapefile |
ShapeIterator | Struct that handle iteration over the shapes of a .shp file |
ShapeRecordIterator |
Functions
read | Function to read all the Shapes in a file. |
read_as | Function to read all the Shapes in a file as a certain type |