From a95c3328c09c9978b17471694c41d37d754d2704 Mon Sep 17 00:00:00 2001 From: Kyle Barron Date: Tue, 23 Jul 2024 15:25:09 -0400 Subject: [PATCH] Update for latest wkt --- Cargo.toml | 11 ++++++++--- geozero/src/csv/csv_reader.rs | 14 ++++++-------- geozero/src/wkt/wkt_reader.rs | 21 ++++++++++----------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bb446476..54d9b71d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,10 @@ resolver = "2" [workspace.package] # This version should match the version in [workspace.dependencies] below version = "0.13.0" -authors = ["Pirmin Kalberer ", "Yuri Astrakhan "] +authors = [ + "Pirmin Kalberer ", + "Yuri Astrakhan ", +] edition = "2021" homepage = "https://github.com/georust/geozero" repository = "https://github.com/georust/geozero" @@ -27,7 +30,9 @@ clap = { version = "4.3", features = ["derive"] } criterion = "0.5.1" csv = "1.2.2" dbase = "0.4" -diesel = { version = "2.1.0", default-features = false, features = ["postgres"] } +diesel = { version = "2.1.0", default-features = false, features = [ + "postgres", +] } dup-indexer = "0.3" env_logger = "0.10.0" flatgeobuf = "4.0.0" @@ -56,7 +61,7 @@ serde_json = "1.0.104" sqlx = { version = "0.7", default-features = false } thiserror = "1.0" tokio = { version = "1.30.0", default-features = false } -wkt = "0.10.3" +wkt = { git = "https://github.com/georust/wkt", rev = "a26848c97686245548a43375133f41e77322247d" } [patch.crates-io] geozero = { path = "./geozero" } diff --git a/geozero/src/csv/csv_reader.rs b/geozero/src/csv/csv_reader.rs index 1f514a96..2e322b68 100644 --- a/geozero/src/csv/csv_reader.rs +++ b/geozero/src/csv/csv_reader.rs @@ -132,14 +132,12 @@ pub fn process_csv_geom( processor.geometrycollection_begin(1, 0)?; } - crate::wkt::wkt_reader::process_wkt_geom_n(&wkt.item, record_idx, processor).map_err( - |e| { - // +2 to start at line 1 and to account for the header row - let line = record_idx + 2; - log::warn!("line {line}: invalid WKT: '{geometry_field}', record: {record:?}"); - e - }, - )?; + crate::wkt::wkt_reader::process_wkt_geom_n(&wkt, record_idx, processor).map_err(|e| { + // +2 to start at line 1 and to account for the header row + let line = record_idx + 2; + log::warn!("line {line}: invalid WKT: '{geometry_field}', record: {record:?}"); + e + })?; } if !collection_started { diff --git a/geozero/src/wkt/wkt_reader.rs b/geozero/src/wkt/wkt_reader.rs index fdefd256..82e57fef 100644 --- a/geozero/src/wkt/wkt_reader.rs +++ b/geozero/src/wkt/wkt_reader.rs @@ -3,7 +3,6 @@ use crate::{FeatureProcessor, GeomProcessor, GeozeroDatasource, GeozeroGeometry} use std::io::Read; use wkt::types::{Coord, LineString, Polygon}; -use wkt::Geometry; /// A wrapper around a WKT String or String slice. #[derive(Debug)] @@ -78,22 +77,22 @@ pub fn read_wkt(reader: &mut R, processor: &mut P) -> let mut wkt_string = String::new(); reader.read_to_string(&mut wkt_string)?; let wkt = wkt::Wkt::from_str(&wkt_string).map_err(|e| GeozeroError::Geometry(e.to_string()))?; - process_wkt_geom(&wkt.item, processor) + process_wkt_geom(&wkt, processor) } /// Process WKT geometry -fn process_wkt_geom(geometry: &Geometry, processor: &mut P) -> Result<()> { +fn process_wkt_geom(geometry: &wkt::Wkt, processor: &mut P) -> Result<()> { process_wkt_geom_n(geometry, 0, processor) } pub(crate) fn process_wkt_geom_n( - geometry: &Geometry, + geometry: &wkt::Wkt, idx: usize, processor: &mut P, ) -> Result<()> { let multi_dim = processor.multi_dim(); match geometry { - Geometry::Point(g) => { + wkt::Wkt::Point(g) => { if let Some(ref coord) = g.0 { processor.point_begin(idx)?; process_coord(coord, multi_dim, 0, processor)?; @@ -102,7 +101,7 @@ pub(crate) fn process_wkt_geom_n( processor.empty_point(idx) } } - Geometry::MultiPoint(g) => { + wkt::Wkt::MultiPoint(g) => { processor.multipoint_begin(g.0.len(), idx)?; let multi_dim1 = processor.multi_dim(); for (idxc, point) in g.0.iter().enumerate() { @@ -116,23 +115,23 @@ pub(crate) fn process_wkt_geom_n( } processor.multipoint_end(idx) } - Geometry::LineString(g) => process_linestring(g, true, idx, processor), - Geometry::MultiLineString(g) => { + wkt::Wkt::LineString(g) => process_linestring(g, true, idx, processor), + wkt::Wkt::MultiLineString(g) => { processor.multilinestring_begin(g.0.len(), idx)?; for (idxc, linestring) in g.0.iter().enumerate() { process_linestring(linestring, false, idxc, processor)?; } processor.multilinestring_end(idx) } - Geometry::Polygon(g) => process_polygon(g, true, idx, processor), - Geometry::MultiPolygon(g) => { + wkt::Wkt::Polygon(g) => process_polygon(g, true, idx, processor), + wkt::Wkt::MultiPolygon(g) => { processor.multipolygon_begin(g.0.len(), idx)?; for (idx2, polygon) in g.0.iter().enumerate() { process_polygon(polygon, false, idx2, processor)?; } processor.multipolygon_end(idx) } - Geometry::GeometryCollection(g) => { + wkt::Wkt::GeometryCollection(g) => { processor.geometrycollection_begin(g.0.len(), idx)?; for (idx2, geometry) in g.0.iter().enumerate() { process_wkt_geom_n(geometry, idx2, processor)?;