From e9bb49c07b2e5ea71fb7932a586b679f8731f857 Mon Sep 17 00:00:00 2001 From: Pirmin Kalberer Date: Sat, 31 Aug 2024 01:03:24 +0200 Subject: [PATCH] Integrate shp driver (#233) Solves #187 --- .github/workflows/linux.yml | 2 +- Cargo.toml | 4 +- README.md | 2 +- geozero-shp/Cargo.toml | 22 ----- geozero-shp/README.md | 27 ------ geozero/Cargo.toml | 9 +- geozero/src/lib.rs | 5 +- .../src => geozero/src/shp}/header.rs | 6 +- .../src/lib.rs => geozero/src/shp/mod.rs | 39 ++++++--- .../src => geozero/src/shp}/point_z.rs | 2 +- .../src/shp}/property_processor.rs | 6 +- .../src => geozero/src/shp}/reader.rs | 20 ++--- .../src => geozero/src/shp}/shp_reader.rs | 4 +- .../src => geozero/src/shp}/shx_reader.rs | 2 +- .../data => geozero/tests/data/shp}/line.shp | Bin .../data => geozero/tests/data/shp}/line.shx | Bin .../data => geozero/tests/data/shp}/linem.shp | Bin .../data => geozero/tests/data/shp}/linez.shp | Bin .../tests/data/shp}/multi_polygon.shp | Bin .../tests/data/shp}/multipatch.dbf | Bin .../tests/data/shp}/multipatch.shp | Bin .../tests/data/shp}/multipoint.shp | Bin .../tests/data/shp}/multipointz.shp | Bin .../data => geozero/tests/data/shp}/point.shp | Bin .../data => geozero/tests/data/shp}/point.shx | Bin .../tests/data/shp}/pointm.shp | Bin .../tests/data/shp}/pointz.shp | Bin .../data => geozero/tests/data/shp}/poly.PRJ | 0 .../data => geozero/tests/data/shp}/poly.dbf | Bin .../data => geozero/tests/data/shp}/poly.shp | Bin .../data => geozero/tests/data/shp}/poly.shx | Bin .../tests/data/shp}/polygon.shp | Bin .../tests/data/shp}/polygon_hole.shp | Bin .../tests/data/shp}/polygon_hole.shx | Bin .../tests/data/shp}/polygonm.shp | Bin .../tests/data/shp}/polygonz.shp | Bin .../reader.rs => geozero/tests/shp-reader.rs | 81 +++++++++--------- 37 files changed, 106 insertions(+), 125 deletions(-) delete mode 100644 geozero-shp/Cargo.toml delete mode 100644 geozero-shp/README.md rename {geozero-shp/src => geozero/src/shp}/header.rs (98%) rename geozero-shp/src/lib.rs => geozero/src/shp/mod.rs (62%) rename {geozero-shp/src => geozero/src/shp}/point_z.rs (96%) rename {geozero-shp/src => geozero/src/shp}/property_processor.rs (94%) rename {geozero-shp/src => geozero/src/shp}/reader.rs (94%) rename {geozero-shp/src => geozero/src/shp}/shp_reader.rs (99%) rename {geozero-shp/src => geozero/src/shp}/shx_reader.rs (96%) rename {geozero-shp/tests/data => geozero/tests/data/shp}/line.shp (100%) rename {geozero-shp/tests/data => geozero/tests/data/shp}/line.shx (100%) rename {geozero-shp/tests/data => geozero/tests/data/shp}/linem.shp (100%) rename {geozero-shp/tests/data => geozero/tests/data/shp}/linez.shp (100%) rename {geozero-shp/tests/data => geozero/tests/data/shp}/multi_polygon.shp (100%) rename {geozero-shp/tests/data => geozero/tests/data/shp}/multipatch.dbf (100%) rename {geozero-shp/tests/data => geozero/tests/data/shp}/multipatch.shp (100%) rename {geozero-shp/tests/data => geozero/tests/data/shp}/multipoint.shp (100%) rename {geozero-shp/tests/data => geozero/tests/data/shp}/multipointz.shp (100%) rename {geozero-shp/tests/data => geozero/tests/data/shp}/point.shp (100%) rename {geozero-shp/tests/data => geozero/tests/data/shp}/point.shx (100%) rename {geozero-shp/tests/data => geozero/tests/data/shp}/pointm.shp (100%) rename {geozero-shp/tests/data => geozero/tests/data/shp}/pointz.shp (100%) rename {geozero-shp/tests/data => geozero/tests/data/shp}/poly.PRJ (100%) rename {geozero-shp/tests/data => geozero/tests/data/shp}/poly.dbf (100%) rename {geozero-shp/tests/data => geozero/tests/data/shp}/poly.shp (100%) rename {geozero-shp/tests/data => geozero/tests/data/shp}/poly.shx (100%) rename {geozero-shp/tests/data => geozero/tests/data/shp}/polygon.shp (100%) rename {geozero-shp/tests/data => geozero/tests/data/shp}/polygon_hole.shp (100%) rename {geozero-shp/tests/data => geozero/tests/data/shp}/polygon_hole.shx (100%) rename {geozero-shp/tests/data => geozero/tests/data/shp}/polygonm.shp (100%) rename {geozero-shp/tests/data => geozero/tests/data/shp}/polygonz.shp (100%) rename geozero-shp/tests/reader.rs => geozero/tests/shp-reader.rs (84%) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index bb12bef3..dc411046 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -45,7 +45,7 @@ jobs: shell: bash # Make sure this list matches the members list in Cargo.toml run: | - for package in geozero geozero-shp geozero-cli geozero-bench; do + for package in geozero geozero-cli geozero-bench; do (echo "----- Testing doc build for package $package ----" && cargo doc -p $package --all-features --no-deps) done env: diff --git a/Cargo.toml b/Cargo.toml index 8974e1cc..349050d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [workspace] # Make sure this list matches the "Test Doc Build" section in .github/workflows/ci.yml -members = ["geozero", "geozero-shp", "geozero-cli", "geozero-bench"] -default-members = ["geozero", "geozero-shp", "geozero-cli"] +members = ["geozero", "geozero-cli", "geozero-bench"] +default-members = ["geozero", "geozero-cli"] resolver = "2" [workspace.package] diff --git a/README.md b/README.md index 5a36ad83..caeb8da0 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Supported dimensions: X, Y, Z, M, T | [geo-types](https://github.com/georust/geo) | ✅ | ✅ | | | MVT (Mapbox Vector Tiles) | ✅ | ✅ | | | GPX | ✅ | ❌ | | -| Shapefile | ✅ | ❌ | Available via the [geozero-shp](https://crates.io/crates/geozero-shp) crate. | +| Shapefile | ✅ | ❌ | | | FlatGeobuf | ✅ | ❌ | Available via the [flatgeobuf](https://crates.io/crates/flatgeobuf) crate. | | GeoArrow | ✅ | ✅ | Available via the [geoarrow](https://crates.io/crates/geoarrow) crate. | | GeoParquet | ✅ | ✅ | Available via the [geoarrow](https://crates.io/crates/geoarrow) crate. | diff --git a/geozero-shp/Cargo.toml b/geozero-shp/Cargo.toml deleted file mode 100644 index d99946fa..00000000 --- a/geozero-shp/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "geozero-shp" -version = "0.5.1" -description = "WARNING: The shp driver is now included in geozero." -readme = "README.md" -keywords = ["geo", "shapefile"] -categories = ["science::geo"] -authors.workspace = true -edition.workspace = true -homepage.workspace = true -repository.workspace = true -license.workspace = true - -[dependencies] -byteorder.workspace = true -dbase.workspace = true -geozero.workspace = true -thiserror.workspace = true - -[dev-dependencies] -geo-types.workspace = true -geozero = { workspace = true, default-features = true } diff --git a/geozero-shp/README.md b/geozero-shp/README.md deleted file mode 100644 index 2943f214..00000000 --- a/geozero-shp/README.md +++ /dev/null @@ -1,27 +0,0 @@ -> **DEPRECATED**: The shp driver is now included in `geozero`. - -# GeoZero Shapefile driver - -Reading Shapefiles with [GeoZero](https://github.com/georust/geozero) API. - -Features: -- [x] Read support for OGC simple feature types -- [x] Convert to GeoJSON, WKB (PostGIS/GeoPackage), WKT, GEOS, GDAL formats and more -- [ ] Support for Multipatch types -- [ ] Read spatial index -- [ ] Read projection files - -For writing Shapefiles either use [shapefile-rs](https://crates.io/crates/shapefile) or the GDAL driver of [GeoZero](https://crates.io/crates/geozero) - -Originally based on shapefile-rs from Thomas Montaigu. - - -## Usage example - -```rust,ignore -use geozero::geojson::GeoJsonWriter; - -let reader = geozero_shp::Reader::from_path("poly.shp")?; -let mut json: Vec = Vec::new(); -let cnt = reader.iter_features(GeoJsonWriter::new(&mut json))?.count(); -``` diff --git a/geozero/Cargo.toml b/geozero/Cargo.toml index 8b4040f8..6c3b156b 100644 --- a/geozero/Cargo.toml +++ b/geozero/Cargo.toml @@ -12,7 +12,7 @@ repository.workspace = true license.workspace = true [features] -default = ["with-svg", "with-wkt", "with-geo", "with-geojson"] +default = ["with-geo", "with-geojson", "with-svg", "with-wkt"] with-csv = ["dep:csv", "with-wkt"] with-gdal = ["dep:gdal", "dep:gdal-sys"] with-gdal-bindgen = ["with-gdal", "gdal?/bindgen"] @@ -25,6 +25,7 @@ with-mvt = ["dep:prost", "dep:prost-build", "dep:dup-indexer"] with-postgis-diesel = ["with-wkb", "dep:diesel", "dep:byteorder"] with-postgis-postgres = ["with-wkb", "dep:postgres-types", "dep:bytes"] with-postgis-sqlx = ["with-wkb", "dep:sqlx", "sqlx?/postgres"] +with-shp = ["dep:byteorder", "dep:dbase"] with-svg = [] with-tessellator = ["dep:lyon"] with-wkb = ["dep:scroll", "with-wkt"] @@ -39,6 +40,7 @@ thiserror.workspace = true byteorder = { workspace = true, optional = true } bytes = { workspace = true, optional = true } csv = { workspace = true, optional = true } +dbase = { workspace = true, optional = true } diesel = { workspace = true, optional = true } dup-indexer = { workspace = true, optional = true } gdal = { workspace = true, optional = true } @@ -128,6 +130,11 @@ name = "gpx" path = "tests/gpx.rs" required-features = ["with-gpx", "with-wkt", "with-geojson"] +[[test]] +name = "shp-reader" +path = "tests/shp-reader.rs" +required-features = ["with-shp"] + [[test]] name = "svg" path = "tests/svg.rs" diff --git a/geozero/src/lib.rs b/geozero/src/lib.rs index 42b6670f..a6ad4f22 100644 --- a/geozero/src/lib.rs +++ b/geozero/src/lib.rs @@ -12,7 +12,6 @@ //! Supported dimensions: X, Y, Z, M, T //! //! Available implementations: -//! * [geozero-shp](https://docs.rs/geozero-shp) //! * [flatgeobuf](https://docs.rs/flatgeobuf) //! * [geoarrow](https://docs.rs/geoarrow) //! @@ -28,6 +27,7 @@ //! | GEOS | `geos::Geometry` | XYZ | - | [ToGeos] | [GeosWriter](geos::GeosWriter) | //! | GPX | | XY | [GpxReader](gpx::GpxReader) | | | //! | MVT | [mvt::tile::Feature] | XY | [mvt::tile::Layer] | [ToMvt] | [MvtWriter](mvt::MvtWriter) | +//! | Shapefile | - | XYZM | [shp::ShpReader] | | | //! | SVG | - | XY | - | [ToSvg] | [SvgWriter](svg::SvgWriter) | //! | WKB | [Wkb](wkb::Wkb), [Ewkb](wkb::Ewkb), [GpkgWkb](wkb::GpkgWkb), [SpatiaLiteWkb](wkb::SpatiaLiteWkb), [MySQL](wkb::MySQLWkb) | XYZM | - | [ToWkb] | [WkbWriter](wkb::WkbWriter) | //! | WKT | [wkt::WktStr], [wkt::WktString], [wkt::EwktStr], [wkt::EwktString] | XYZM | [wkt::WktReader], [wkt::WktStr], [wkt::WktString], [wkt::EwktStr], [wkt::EwktString] | [ToWkt] | [WktWriter](wkt::WktWriter) | @@ -99,6 +99,9 @@ pub mod gpx; ))] pub mod postgis; +#[cfg(feature = "with-shp")] +pub mod shp; + #[cfg(feature = "with-svg")] pub mod svg; #[cfg(feature = "with-svg")] diff --git a/geozero-shp/src/header.rs b/geozero/src/shp/header.rs similarity index 98% rename from geozero-shp/src/header.rs rename to geozero/src/shp/header.rs index b8047418..5b1bac3d 100644 --- a/geozero-shp/src/header.rs +++ b/geozero/src/shp/header.rs @@ -1,5 +1,5 @@ -use crate::point_z::BBoxZ; -use crate::Error; +use crate::shp::point_z::BBoxZ; +use crate::shp::Error; use byteorder::{BigEndian, LittleEndian, ReadBytesExt}; use std::fmt; use std::io::Read; @@ -105,7 +105,7 @@ impl ShapeType { /// Returns the ShapeType corresponding to the input code /// if the code is valid /// ``` - /// use geozero_shp::ShapeType; + /// use geozero::shp::ShapeType; /// /// assert_eq!(ShapeType::from(25), Some(ShapeType::PolygonM)); /// assert_eq!(ShapeType::from(60), None); diff --git a/geozero-shp/src/lib.rs b/geozero/src/shp/mod.rs similarity index 62% rename from geozero-shp/src/lib.rs rename to geozero/src/shp/mod.rs index 9ec852e3..cef3ecf9 100644 --- a/geozero-shp/src/lib.rs +++ b/geozero/src/shp/mod.rs @@ -1,6 +1,28 @@ -#![deprecated( - note = "The geozero_shp crate has been deprecated. Instead, use geozero's built-in shapefile feature" -)] +//! Shapefile reader. +//! +//! Features: +//! - [x] Read support for OGC simple feature types +//! - [x] Convert to GeoJSON, WKB (PostGIS/GeoPackage), WKT, GEOS, GDAL formats and more +//! - [ ] Support for Multipatch types +//! - [ ] Read spatial index +//! - [ ] Read projection files +//! +//! For writing Shapefiles either use [shapefile-rs](https://crates.io/crates/shapefile) or the GDAL driver. +//! +//! Originally based on shapefile-rs from Thomas Montaigu. +//! +//! # Usage example: +//! +//! Use Shapefile feature iterator: +//! +//! ```rust,ignore +//! use geozero::geojson::GeoJsonWriter; +//! use geozero::shp::ShpReader; +//! +//! let reader = ShpReader::from_path("poly.shp")?; +//! let mut json: Vec = Vec::new(); +//! let cnt = reader.iter_features(GeoJsonWriter::new(&mut json))?.count(); +//! ``` mod header; mod point_z; @@ -9,12 +31,9 @@ pub mod reader; mod shp_reader; mod shx_reader; -pub use crate::header::ShapeType; -pub use crate::reader::Reader; -pub use crate::shp_reader::NO_DATA; - -// Re-export GeoZero to help avoid version conflicts -pub use geozero; +pub use crate::shp::header::ShapeType; +pub use crate::shp::reader::ShpReader; +pub use crate::shp::shp_reader::NO_DATA; /// All Errors that can happen when using this library #[derive(thiserror::Error, Debug)] @@ -50,5 +69,5 @@ pub enum Error { #[error("Index file missing")] MissingIndexFile, #[error("Geozero error")] - GeozeroError(#[from] geozero::error::GeozeroError), + GeozeroError(#[from] crate::error::GeozeroError), } diff --git a/geozero-shp/src/point_z.rs b/geozero/src/shp/point_z.rs similarity index 96% rename from geozero-shp/src/point_z.rs rename to geozero/src/shp/point_z.rs index 2341d41b..1d0e52cf 100644 --- a/geozero-shp/src/point_z.rs +++ b/geozero/src/shp/point_z.rs @@ -1,4 +1,4 @@ -use crate::shp_reader::{is_no_data, NO_DATA}; +use crate::shp::shp_reader::{is_no_data, NO_DATA}; use std::fmt; /// Point with `x`, `y`, `m`, `z` diff --git a/geozero-shp/src/property_processor.rs b/geozero/src/shp/property_processor.rs similarity index 94% rename from geozero-shp/src/property_processor.rs rename to geozero/src/shp/property_processor.rs index f4a7bbe3..caf41ad6 100644 --- a/geozero-shp/src/property_processor.rs +++ b/geozero/src/shp/property_processor.rs @@ -1,7 +1,7 @@ -use crate::reader::ShapeRecord; +use crate::error::Result; +use crate::shp::reader::ShapeRecord; +use crate::{ColumnValue, FeatureProperties, PropertyProcessor}; use dbase::FieldValue; -use geozero::error::Result; -use geozero::{ColumnValue, FeatureProperties, PropertyProcessor}; impl FeatureProperties for ShapeRecord { /// Process feature properties. diff --git a/geozero-shp/src/reader.rs b/geozero/src/shp/reader.rs similarity index 94% rename from geozero-shp/src/reader.rs rename to geozero/src/shp/reader.rs index 8d24cfb8..98f9caee 100644 --- a/geozero-shp/src/reader.rs +++ b/geozero/src/shp/reader.rs @@ -1,8 +1,8 @@ -use crate::shp_reader::{read_shape, RecordHeader}; -use crate::shx_reader::{read_index_file, ShapeIndex}; -use crate::{header, Error}; +use crate::shp::shp_reader::{read_shape, RecordHeader}; +use crate::shp::shx_reader::{read_index_file, ShapeIndex}; +use crate::shp::{header, Error}; +use crate::{FeatureProcessor, FeatureProperties, GeomProcessor}; pub use dbase::{FieldInfo, FieldType}; -use geozero::{FeatureProcessor, FeatureProperties, GeomProcessor}; use std::fs::File; use std::io::{BufReader, Read, Seek}; use std::iter::FusedIterator; @@ -91,14 +91,14 @@ impl<'a, P: FeatureProcessor, T: Read + Seek + 'a> Iterator for ShapeRecordItera impl<'a, P: FeatureProcessor, T: Read + Seek + 'a> FusedIterator for ShapeRecordIterator<'a, P, T> {} /// struct that reads the content of a shapefile -pub struct Reader { +pub struct ShpReader { source: T, header: header::Header, shapes_index: Option>, dbf_reader: Option>, } -impl Reader { +impl ShpReader { /// 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) @@ -110,10 +110,10 @@ impl Reader { /// Will also return an error if the data is not a shapefile (Wrong file code) /// /// Will also return an error if the shape type read from the input source is invalid - pub fn new(mut source: T) -> Result, Error> { + pub fn new(mut source: T) -> Result, Error> { let header = header::Header::read_from(&mut source)?; - Ok(Reader { + Ok(ShpReader { source, header, shapes_index: None, @@ -192,7 +192,7 @@ impl Reader { } } -impl Reader> { +impl ShpReader> { /// Creates a reader from a path to a file /// /// Will attempt to read both the .shx and .dbf associated with the file, @@ -220,7 +220,7 @@ impl Reader> { } // Does not work, because iter_features requires P instead of &mut P -// impl GeozeroDatasource for Reader { +// impl GeozeroDatasource for ShpReader { // fn process(&mut self, processor: &mut P) -> geozero::error::Result<()> { // self.iter_features(*processor).unwrap().all(); // Ok(()) diff --git a/geozero-shp/src/shp_reader.rs b/geozero/src/shp/shp_reader.rs similarity index 99% rename from geozero-shp/src/shp_reader.rs rename to geozero/src/shp/shp_reader.rs index 52f2b540..d8c5f66b 100644 --- a/geozero-shp/src/shp_reader.rs +++ b/geozero/src/shp/shp_reader.rs @@ -1,6 +1,6 @@ -use crate::{Error, ShapeType}; +use crate::shp::{Error, ShapeType}; +use crate::GeomProcessor; use byteorder::{BigEndian, LittleEndian, ReadBytesExt}; -use geozero::GeomProcessor; use std::io::Read; use std::mem::size_of; diff --git a/geozero-shp/src/shx_reader.rs b/geozero/src/shp/shx_reader.rs similarity index 96% rename from geozero-shp/src/shx_reader.rs rename to geozero/src/shp/shx_reader.rs index d61e1265..d1b4359c 100644 --- a/geozero-shp/src/shx_reader.rs +++ b/geozero/src/shp/shx_reader.rs @@ -1,4 +1,4 @@ -use crate::{header, Error}; +use crate::shp::{header, Error}; use byteorder::{BigEndian, ReadBytesExt}; use std::io::Read; diff --git a/geozero-shp/tests/data/line.shp b/geozero/tests/data/shp/line.shp similarity index 100% rename from geozero-shp/tests/data/line.shp rename to geozero/tests/data/shp/line.shp diff --git a/geozero-shp/tests/data/line.shx b/geozero/tests/data/shp/line.shx similarity index 100% rename from geozero-shp/tests/data/line.shx rename to geozero/tests/data/shp/line.shx diff --git a/geozero-shp/tests/data/linem.shp b/geozero/tests/data/shp/linem.shp similarity index 100% rename from geozero-shp/tests/data/linem.shp rename to geozero/tests/data/shp/linem.shp diff --git a/geozero-shp/tests/data/linez.shp b/geozero/tests/data/shp/linez.shp similarity index 100% rename from geozero-shp/tests/data/linez.shp rename to geozero/tests/data/shp/linez.shp diff --git a/geozero-shp/tests/data/multi_polygon.shp b/geozero/tests/data/shp/multi_polygon.shp similarity index 100% rename from geozero-shp/tests/data/multi_polygon.shp rename to geozero/tests/data/shp/multi_polygon.shp diff --git a/geozero-shp/tests/data/multipatch.dbf b/geozero/tests/data/shp/multipatch.dbf similarity index 100% rename from geozero-shp/tests/data/multipatch.dbf rename to geozero/tests/data/shp/multipatch.dbf diff --git a/geozero-shp/tests/data/multipatch.shp b/geozero/tests/data/shp/multipatch.shp similarity index 100% rename from geozero-shp/tests/data/multipatch.shp rename to geozero/tests/data/shp/multipatch.shp diff --git a/geozero-shp/tests/data/multipoint.shp b/geozero/tests/data/shp/multipoint.shp similarity index 100% rename from geozero-shp/tests/data/multipoint.shp rename to geozero/tests/data/shp/multipoint.shp diff --git a/geozero-shp/tests/data/multipointz.shp b/geozero/tests/data/shp/multipointz.shp similarity index 100% rename from geozero-shp/tests/data/multipointz.shp rename to geozero/tests/data/shp/multipointz.shp diff --git a/geozero-shp/tests/data/point.shp b/geozero/tests/data/shp/point.shp similarity index 100% rename from geozero-shp/tests/data/point.shp rename to geozero/tests/data/shp/point.shp diff --git a/geozero-shp/tests/data/point.shx b/geozero/tests/data/shp/point.shx similarity index 100% rename from geozero-shp/tests/data/point.shx rename to geozero/tests/data/shp/point.shx diff --git a/geozero-shp/tests/data/pointm.shp b/geozero/tests/data/shp/pointm.shp similarity index 100% rename from geozero-shp/tests/data/pointm.shp rename to geozero/tests/data/shp/pointm.shp diff --git a/geozero-shp/tests/data/pointz.shp b/geozero/tests/data/shp/pointz.shp similarity index 100% rename from geozero-shp/tests/data/pointz.shp rename to geozero/tests/data/shp/pointz.shp diff --git a/geozero-shp/tests/data/poly.PRJ b/geozero/tests/data/shp/poly.PRJ similarity index 100% rename from geozero-shp/tests/data/poly.PRJ rename to geozero/tests/data/shp/poly.PRJ diff --git a/geozero-shp/tests/data/poly.dbf b/geozero/tests/data/shp/poly.dbf similarity index 100% rename from geozero-shp/tests/data/poly.dbf rename to geozero/tests/data/shp/poly.dbf diff --git a/geozero-shp/tests/data/poly.shp b/geozero/tests/data/shp/poly.shp similarity index 100% rename from geozero-shp/tests/data/poly.shp rename to geozero/tests/data/shp/poly.shp diff --git a/geozero-shp/tests/data/poly.shx b/geozero/tests/data/shp/poly.shx similarity index 100% rename from geozero-shp/tests/data/poly.shx rename to geozero/tests/data/shp/poly.shx diff --git a/geozero-shp/tests/data/polygon.shp b/geozero/tests/data/shp/polygon.shp similarity index 100% rename from geozero-shp/tests/data/polygon.shp rename to geozero/tests/data/shp/polygon.shp diff --git a/geozero-shp/tests/data/polygon_hole.shp b/geozero/tests/data/shp/polygon_hole.shp similarity index 100% rename from geozero-shp/tests/data/polygon_hole.shp rename to geozero/tests/data/shp/polygon_hole.shp diff --git a/geozero-shp/tests/data/polygon_hole.shx b/geozero/tests/data/shp/polygon_hole.shx similarity index 100% rename from geozero-shp/tests/data/polygon_hole.shx rename to geozero/tests/data/shp/polygon_hole.shx diff --git a/geozero-shp/tests/data/polygonm.shp b/geozero/tests/data/shp/polygonm.shp similarity index 100% rename from geozero-shp/tests/data/polygonm.shp rename to geozero/tests/data/shp/polygonm.shp diff --git a/geozero-shp/tests/data/polygonz.shp b/geozero/tests/data/shp/polygonz.shp similarity index 100% rename from geozero-shp/tests/data/polygonz.shp rename to geozero/tests/data/shp/polygonz.shp diff --git a/geozero-shp/tests/reader.rs b/geozero/tests/shp-reader.rs similarity index 84% rename from geozero-shp/tests/reader.rs rename to geozero/tests/shp-reader.rs index d464477d..16edc2a3 100644 --- a/geozero-shp/tests/reader.rs +++ b/geozero/tests/shp-reader.rs @@ -1,5 +1,6 @@ use dbase::FieldValue; use geozero::geojson::GeoJsonWriter; +use geozero::shp::ShpReader; use geozero::wkt::WktWriter; use geozero::{CoordDimensions, FeatureProperties, ProcessorSink}; use std::fs::File; @@ -8,23 +9,23 @@ use std::str::from_utf8; #[test] fn read_header() { - let reader = geozero_shp::Reader::from_path("./tests/data/line.shp").unwrap(); + let reader = ShpReader::from_path("./tests/data/shp/line.shp").unwrap(); let header = reader.header(); assert_eq!(header.file_length, 136); - assert_eq!(header.shape_type, geozero_shp::ShapeType::Polyline); + assert_eq!(header.shape_type, geozero::shp::ShapeType::Polyline); assert_eq!(header.bbox.x_range(), [1.0, 5.0]); } #[test] -fn iterate() -> Result<(), geozero_shp::Error> { - let reader = geozero_shp::Reader::from_path("./tests/data/poly.shp")?; +fn iterate() -> Result<(), geozero::shp::Error> { + let reader = ShpReader::from_path("./tests/data/shp/poly.shp")?; let mut cnt = 0; for _ in reader.iter_geometries(&mut ProcessorSink::new()) { cnt += 1; } assert_eq!(cnt, 10); - let reader = geozero_shp::Reader::from_path("./tests/data/poly.shp")?; + let reader = ShpReader::from_path("./tests/data/shp/poly.shp")?; let mut cnt = 0; for feat in reader.iter_features(&mut ProcessorSink::new())? { if let Ok(feat) = feat { @@ -34,8 +35,8 @@ fn iterate() -> Result<(), geozero_shp::Error> { } assert_eq!(cnt, 10); - let source = BufReader::new(File::open("./tests/data/poly.shp")?); - let reader = geozero_shp::Reader::new(source)?; + let source = BufReader::new(File::open("./tests/data/shp/poly.shp")?); + let reader = ShpReader::new(source)?; let mut cnt = 0; for _ in reader.iter_geometries(&mut ProcessorSink::new()) { cnt += 1; @@ -46,8 +47,8 @@ fn iterate() -> Result<(), geozero_shp::Error> { } #[test] -fn shp_to_json() -> Result<(), geozero_shp::Error> { - let reader = geozero_shp::Reader::from_path("./tests/data/poly.shp")?; +fn shp_to_json() -> Result<(), geozero::shp::Error> { + let reader = ShpReader::from_path("./tests/data/shp/poly.shp")?; let mut json: Vec = Vec::new(); let cnt = reader .iter_features(&mut GeoJsonWriter::new(&mut json))? @@ -67,11 +68,11 @@ fn shp_to_json() -> Result<(), geozero_shp::Error> { } #[test] -fn shp_to_geo() -> Result<(), geozero_shp::Error> { +fn shp_to_geo() -> Result<(), geozero::shp::Error> { use geo_types::Geometry; use geozero::geo_types::GeoWriter; - let reader = geozero_shp::Reader::from_path("./tests/data/poly.shp")?; + let reader = ShpReader::from_path("./tests/data/shp/poly.shp")?; let mut geo = GeoWriter::new(); let mut cnt = 0; for _geom in reader.iter_geometries(&mut geo) { @@ -90,8 +91,8 @@ fn shp_to_geo() -> Result<(), geozero_shp::Error> { } #[test] -fn property_filter() -> Result<(), geozero_shp::Error> { - let reader = geozero_shp::Reader::from_path("./tests/data/poly.shp")?; +fn property_filter() -> Result<(), geozero::shp::Error> { + let reader = ShpReader::from_path("./tests/data/shp/poly.shp")?; let mut json: Vec = Vec::new(); let cnt = reader .iter_features(&mut GeoJsonWriter::new(&mut json))? @@ -104,8 +105,8 @@ fn property_filter() -> Result<(), geozero_shp::Error> { } #[test] -fn property_access() -> Result<(), geozero_shp::Error> { - let reader = geozero_shp::Reader::from_path("./tests/data/poly.shp")?; +fn property_access() -> Result<(), geozero::shp::Error> { + let reader = ShpReader::from_path("./tests/data/shp/poly.shp")?; let mut cnt = 0; for feat in reader.iter_features(&mut ProcessorSink::new())? { if let Ok(feat) = feat { @@ -131,8 +132,8 @@ fn property_access() -> Result<(), geozero_shp::Error> { } #[test] -fn property_file() -> Result<(), geozero_shp::Error> { - let reader = geozero_shp::Reader::from_path("./tests/data/poly.shp")?; +fn property_file() -> Result<(), geozero::shp::Error> { + let reader = ShpReader::from_path("./tests/data/shp/poly.shp")?; let fields = reader.dbf_fields().unwrap(); assert_eq!(fields.len(), 3); let sql = fields @@ -164,8 +165,8 @@ fn property_file() -> Result<(), geozero_shp::Error> { } #[test] -fn point() -> Result<(), geozero_shp::Error> { - let reader = geozero_shp::Reader::from_path("./tests/data/point.shp")?; +fn point() -> Result<(), geozero::shp::Error> { + let reader = ShpReader::from_path("./tests/data/shp/point.shp")?; let mut wkt_data: Vec = Vec::new(); reader .iter_geometries(&mut WktWriter::new(&mut wkt_data)) @@ -175,8 +176,8 @@ fn point() -> Result<(), geozero_shp::Error> { } #[test] -fn pointzm() -> Result<(), geozero_shp::Error> { - let reader = geozero_shp::Reader::from_path("./tests/data/pointm.shp")?; +fn pointzm() -> Result<(), geozero::shp::Error> { + let reader = ShpReader::from_path("./tests/data/shp/pointm.shp")?; let mut wkt_data: Vec = Vec::new(); let mut writer = WktWriter::with_dims(&mut wkt_data, CoordDimensions::xym()); reader.iter_geometries(&mut writer).next(); @@ -185,7 +186,7 @@ fn pointzm() -> Result<(), geozero_shp::Error> { "POINT(160477.9000324604 5403959.561417906 0)" ); - let reader = geozero_shp::Reader::from_path("./tests/data/pointz.shp")?; + let reader = ShpReader::from_path("./tests/data/shp/pointz.shp")?; let mut wkt_data: Vec = Vec::new(); let mut writer = WktWriter::with_dims(&mut wkt_data, CoordDimensions::xyz()); reader.iter_geometries(&mut writer).next(); @@ -197,8 +198,8 @@ fn pointzm() -> Result<(), geozero_shp::Error> { } #[test] -fn multipoint() -> Result<(), geozero_shp::Error> { - let reader = geozero_shp::Reader::from_path("./tests/data/multipoint.shp")?; +fn multipoint() -> Result<(), geozero::shp::Error> { + let reader = ShpReader::from_path("./tests/data/shp/multipoint.shp")?; let mut wkt_data: Vec = Vec::new(); reader .iter_geometries(&mut WktWriter::new(&mut wkt_data)) @@ -208,8 +209,8 @@ fn multipoint() -> Result<(), geozero_shp::Error> { } #[test] -fn multipointzm() -> Result<(), geozero_shp::Error> { - let reader = geozero_shp::Reader::from_path("./tests/data/multipointz.shp")?; +fn multipointzm() -> Result<(), geozero::shp::Error> { + let reader = ShpReader::from_path("./tests/data/shp/multipointz.shp")?; let mut wkt_data: Vec = Vec::new(); let mut writer = WktWriter::with_dims(&mut wkt_data, CoordDimensions::xyz()); reader.iter_geometries(&mut writer).next(); @@ -221,8 +222,8 @@ fn multipointzm() -> Result<(), geozero_shp::Error> { } #[test] -fn line() -> Result<(), geozero_shp::Error> { - let reader = geozero_shp::Reader::from_path("./tests/data/line.shp")?; +fn line() -> Result<(), geozero::shp::Error> { + let reader = ShpReader::from_path("./tests/data/shp/line.shp")?; let mut wkt_data: Vec = Vec::new(); reader .iter_geometries(&mut WktWriter::new(&mut wkt_data)) @@ -235,8 +236,8 @@ fn line() -> Result<(), geozero_shp::Error> { } #[test] -fn linezm() -> Result<(), geozero_shp::Error> { - let reader = geozero_shp::Reader::from_path("./tests/data/linez.shp")?; +fn linezm() -> Result<(), geozero::shp::Error> { + let reader = ShpReader::from_path("./tests/data/shp/linez.shp")?; let mut wkt_data: Vec = Vec::new(); let mut writer = WktWriter::with_dims(&mut wkt_data, CoordDimensions::xyzm()); reader.iter_geometries(&mut writer).next(); @@ -245,7 +246,7 @@ fn linezm() -> Result<(), geozero_shp::Error> { "MULTILINESTRING((1 5 18 -1000000000000000000000000000000000000000,5 5 20 -1000000000000000000000000000000000000000,5 1 22 -1000000000000000000000000000000000000000,3 3 0 -1000000000000000000000000000000000000000,1 1 0 -1000000000000000000000000000000000000000),(3 2 0 -1000000000000000000000000000000000000000,2 6 0 -1000000000000000000000000000000000000000),(3 2 15 0,2 6 13 3,1 9 14 2))" ); - let reader = geozero_shp::Reader::from_path("./tests/data/linez.shp")?; + let reader = ShpReader::from_path("./tests/data/shp/linez.shp")?; let mut wkt_data: Vec = Vec::new(); let mut writer = WktWriter::with_dims(&mut wkt_data, CoordDimensions::xyz()); reader.iter_geometries(&mut writer).next(); @@ -254,7 +255,7 @@ fn linezm() -> Result<(), geozero_shp::Error> { "MULTILINESTRING((1 5 18,5 5 20,5 1 22,3 3 0,1 1 0),(3 2 0,2 6 0),(3 2 15,2 6 13,1 9 14))" ); - let reader = geozero_shp::Reader::from_path("./tests/data/linez.shp")?; + let reader = ShpReader::from_path("./tests/data/shp/linez.shp")?; let mut wkt_data: Vec = Vec::new(); let mut writer = WktWriter::new(&mut wkt_data); // return XY only @@ -264,7 +265,7 @@ fn linezm() -> Result<(), geozero_shp::Error> { "MULTILINESTRING((1 5,5 5,5 1,3 3,1 1),(3 2,2 6),(3 2,2 6,1 9))" ); - let reader = geozero_shp::Reader::from_path("./tests/data/linem.shp")?; + let reader = ShpReader::from_path("./tests/data/shp/linem.shp")?; let mut wkt_data: Vec = Vec::new(); let mut writer = WktWriter::with_dims(&mut wkt_data, CoordDimensions::xym()); reader.iter_geometries(&mut writer).next(); @@ -277,8 +278,8 @@ fn linezm() -> Result<(), geozero_shp::Error> { } #[test] -fn polygon() -> Result<(), geozero_shp::Error> { - let reader = geozero_shp::Reader::from_path("./tests/data/polygon.shp")?; +fn polygon() -> Result<(), geozero::shp::Error> { + let reader = ShpReader::from_path("./tests/data/shp/polygon.shp")?; let mut wkt_data: Vec = Vec::new(); reader .iter_geometries(&mut WktWriter::new(&mut wkt_data)) @@ -289,7 +290,7 @@ fn polygon() -> Result<(), geozero_shp::Error> { //ogrinfo: "MULTIPOLYGON(((122 37,117 36,115 32,118 20,113 24)),((15 2,17 6,22 7)),((122 37,117 36,115 32)))" ); - let reader = geozero_shp::Reader::from_path("./tests/data/polygon_hole.shp")?; + let reader = ShpReader::from_path("./tests/data/shp/polygon_hole.shp")?; let mut wkt_data: Vec = Vec::new(); reader .iter_geometries(&mut WktWriter::new(&mut wkt_data)) @@ -299,7 +300,7 @@ fn polygon() -> Result<(), geozero_shp::Error> { "MULTIPOLYGON(((-120 60,120 60,120 -60,-120 -60,-120 60),(-60 30,-60 -30,60 -30,60 30,-60 30)))" ); - let reader = geozero_shp::Reader::from_path("./tests/data/multi_polygon.shp")?; + let reader = ShpReader::from_path("./tests/data/shp/multi_polygon.shp")?; let mut wkt_data: Vec = Vec::new(); reader .iter_geometries(&mut WktWriter::new(&mut wkt_data)) @@ -316,8 +317,8 @@ fn polygon() -> Result<(), geozero_shp::Error> { } #[test] -fn polygonzm() -> Result<(), geozero_shp::Error> { - let reader = geozero_shp::Reader::from_path("./tests/data/polygonz.shp")?; +fn polygonzm() -> Result<(), geozero::shp::Error> { + let reader = ShpReader::from_path("./tests/data/shp/polygonz.shp")?; let mut wkt_data: Vec = Vec::new(); let mut writer = WktWriter::with_dims(&mut wkt_data, CoordDimensions::xyzm()); reader.iter_geometries(&mut writer).next(); @@ -326,7 +327,7 @@ fn polygonzm() -> Result<(), geozero_shp::Error> { "MULTIPOLYGON(((1422692.1644789441 4188837.794210903 72.46632654472523 0,1422692.1625749937 4188837.75060327 72.46632654472523 1,1422692.156877633 4188837.7073275167 72.46632654472523 2,1422692.1474302218 4188837.664712999 72.46632654472523 3,1422692.1343046608 4188837.6230840385 72.46632654472523 4,1422692.1176008438 4188837.582757457 72.46632654472523 5,1422692.0974458966 4188837.5440401635 72.46632654472523 6,1422692.0739932107 4188837.5072268206 72.46632654472523 7,1422692.047421275 4188837.4725976 72.46632654472523 8,1422692.017932318 4188837.4404160506 72.46632654472523 9,1422691.9857507686 4188837.4109270936 72.46632654472523 10,1422691.951121548 4188837.384355158 72.46632654472523 11,1422691.914308205 4188837.360902472 72.46632654472523 12,1422691.8755909116 4188837.3407475245 72.46632654472523 13,1422691.8352643298 4188837.3240437075 72.46632654472523 14,1422691.7936353693 4188837.3109181467 72.46632654472523 15,1422691.7510208515 4188837.3014707356 72.46632654472523 16,1422691.7077450987 4188837.295773375 72.46632654472523 17,1422691.6641374656 4188837.293869424 72.46632654472523 18,1422691.6205298326 4188837.295773375 72.46632654472523 19,1422691.5772540797 4188837.3014707356 72.46632654472523 20,1422691.534639562 4188837.3109181467 72.46632654472523 21,1422691.4930106015 4188837.3240437075 72.46632654472523 22,1422691.4526840197 4188837.3407475245 72.46632654472523 23,1422691.4139667263 4188837.360902472 72.46632654472523 24,1422691.3771533833 4188837.384355158 72.46632654472523 25,1422691.3425241627 4188837.4109270936 72.46632654472523 26,1422691.3103426134 4188837.4404160506 72.46632654472523 27,1422691.2808536564 4188837.4725976 72.46632654472523 28,1422691.2542817206 4188837.5072268206 72.46632654472523 29,1422691.2308290347 4188837.5440401635 72.46632654472523 30,1422691.2106740875 4188837.582757457 72.46632654472523 31,1422691.1939702705 4188837.6230840385 72.46632654472523 32,1422691.1808447095 4188837.664712999 72.46632654472523 33,1422691.1713972983 4188837.7073275167 72.46632654472523 34,1422691.1656999376 4188837.75060327 72.46632654472523 35,1422691.1637959871 4188837.794210903 72.46632654472523 36,1422691.1656999376 4188837.837818536 72.46632654472523 37,1422691.1713972983 4188837.881094289 72.46632654472523 38,1422691.1808447095 4188837.9237088067 72.46632654472523 39,1422691.1939702705 4188837.9653377673 72.46632654472523 40,1422691.2106740875 4188838.0056643486 72.46632654472523 41,1422691.2308290347 4188838.0443816422 72.46632654472523 42,1422691.2542817206 4188838.081194985 72.46632654472523 43,1422691.2808536564 4188838.115824206 72.46632654472523 44,1422691.3103426134 4188838.148005755 72.46632654472523 45,1422691.3425241627 4188838.177494712 72.46632654472523 46,1422691.3771533833 4188838.2040666477 72.46632654472523 47,1422691.4139667263 4188838.227519334 72.46632654472523 48,1422691.4526840197 4188838.2476742812 72.46632654472523 49,1422691.4930106015 4188838.2643780983 72.46632654472523 50,1422691.534639562 4188838.277503659 72.46632654472523 51,1422691.5772540797 4188838.28695107 72.46632654472523 52,1422691.6205298326 4188838.292648431 72.46632654472523 53,1422691.6641374656 4188838.2945523816 72.46632654472523 54,1422691.7077450987 4188838.292648431 72.46632654472523 55,1422691.7510208515 4188838.28695107 72.46632654472523 56,1422691.7936353693 4188838.277503659 72.46632654472523 57,1422691.8352643298 4188838.2643780983 72.46632654472523 58,1422691.8755909116 4188838.2476742812 72.46632654472523 59,1422691.914308205 4188838.227519334 72.46632654472523 60,1422691.951121548 4188838.2040666477 72.46632654472523 61,1422691.9857507686 4188838.177494712 72.46632654472523 62,1422692.017932318 4188838.148005755 72.46632654472523 63,1422692.047421275 4188838.115824206 72.46632654472523 64,1422692.0739932107 4188838.081194985 72.46632654472523 65,1422692.0974458966 4188838.0443816422 72.46632654472523 66,1422692.1176008438 4188838.0056643486 72.46632654472523 67,1422692.1343046608 4188837.9653377673 72.46632654472523 68,1422692.1474302218 4188837.9237088067 72.46632654472523 69,1422692.156877633 4188837.881094289 72.46632654472523 70,1422692.1625749937 4188837.837818536 72.46632654472523 71,1422692.1644789441 4188837.794210903 72.46632654472523 72)))" ); - let reader = geozero_shp::Reader::from_path("./tests/data/polygonm.shp")?; + let reader = ShpReader::from_path("./tests/data/shp/polygonm.shp")?; let mut wkt_data: Vec = Vec::new(); let mut writer = WktWriter::with_dims(&mut wkt_data, CoordDimensions::xym()); reader.iter_geometries(&mut writer).next();