[][src]Module shapefile::reader

Reader module, contains the definitions of the types that a user should use to read a file

This module proposes two type: a Reader and a FileReaderBuilder

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).

Note that by default the Reader does not read the index file and so the methods read_nth_shape_as and read_nth_shape will not work. If you wish to use them you will have to give to the reader a source for the index file via add_index_source

Or use the FileReaderBuilder if you are reading from files (not buffers)

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").unwrap();
for shape in reader {
    let shape = shape.unwrap();
    println!("{}", shape);
}

Creates a reader from a path, reads the whole file at once

let reader = shapefile::Reader::from_path("tests/data/pointm.shp").unwrap();
let shapes = reader.read().unwrap();
let mut reader = shapefile::FileReaderBuilder::new("tests/data/line.shp").with_index().build().unwrap();

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

Two functions (read and read_as) are provided to read files with one function call (thus not having to build a Reader)

Structs

FileReaderBuilder
Reader

struct that reads the content of a shapefile

ShapeIterator

Struct that handle iteration over the shapes of a .shp file

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