tmontaigu / shapefile-rs

Rust library to read & write shapefiles
MIT License
59 stars 19 forks source link

Provide better shape constructors #3

Closed tmontaigu closed 5 years ago

tmontaigu commented 5 years ago

Current constructors for the shapes are error-prone

The current form new(points: Vec<PointType>, parts: Vec<i32>) requires that users properly organize the points in the Vec and that parts array is properly populated. As no real checks are done, this can lead to wrong shapefile being written.

We should change constructors to something like:

new(points: Vec<PointType>)
with_multiparts(points: Vec<Vec<PointType>>)

Constructor could then sort points clock-wise/counter clock-wise to match the ESRI standard and generate the parts array preventing from mistakes.

And maybe we could add Builders.