Crate shapefile

Source
Expand description

Read & Write Shapefile in Rust

A shapefile is in reality a collection of 3 mandatory files:

  • .shp (feature geometry aka shapes)
  • .shx (index of feature geometry)
  • .dbf (attribute information, aka records)

As different shapefiles can store different type of shapes (but one shapefile can only store the same type of shapes) This library provide two ways of reading the shapes:

  1. Reading as Shape and then do a match to handle the different shapes
  2. Reading directly as concrete shapes (ie Polyline, PolylineZ, Point, etc) this of course only works if the file actually contains shapes that matches the requested type

§dBase

The attributes (stored in the .dbg) files are read and written using the dbase crate which is re-exported so you can use use shapefile::dbase. dBase files may have different encoding which may only be supported if either one of the following features is enabled:

  • encoding_rs (notably supports GBK encoding)
  • yore

§Shapefiles shapes

The Point, PointM and PointZ are the base data types of shapefiles, the other shapes (Polyline, Multipoint, …) are collections of these type of points with different semantics (multiple parts or no, closed parts or no, …)

With the exception of the Multipatch shape, each shape as a variant for each type of point. (Multipatch always uses PointZ) Eg: For the polyline, there is Polyline, PolylineM, PolylineZ

§Reading

For more details see the reader module

§Writing

To write a file see the writer module

§Features

The geo-types feature can be enabled to have access to From and TryFrom implementations allowing to convert (or try to) back and forth between shapefile’s type and the one in geo_types

The yore or encoding_rs feature can be activated to allows the dbase crate to handle files with special encodings.

Re-exports§

pub extern crate dbase;
pub use reader::read;
pub use reader::read_as;
pub use reader::read_shapes;
pub use reader::read_shapes_as;
pub use reader::Reader;
pub use reader::ShapeReader;
pub use record::Multipatch;
pub use record::convert_shapes_to_vec_of;
pub use record::HasShapeType;
pub use record::ReadableShape;
pub use record::Multipoint;
pub use record::MultipointM;
pub use record::MultipointZ;
pub use record::Patch;
pub use record::Shape;
pub use record::NO_DATA;
pub use record::Point;
pub use record::PointM;
pub use record::PointZ;
pub use record::Polygon;
pub use record::PolygonM;
pub use record::PolygonRing;
pub use record::PolygonZ;
pub use record::Polyline;
pub use record::PolylineM;
pub use record::PolylineZ;
pub use writer::ShapeWriter;
pub use writer::Writer;

Modules§

header
reader
Reader module, contains the definitions of the types that a user should use to read a file
record
Shape records
writer
Module with the definition of the Writer that allows writing shapefile

Macros§

multipatch
multipoint
polygon
polyline

Enums§

Error
All Errors that can happen when using this library
ShapeType
The enum for the ShapeType as defined in the specification