Skip to content

Commit

Permalink
Update for latest wkt
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebarron committed Jul 23, 2024
1 parent ab5486a commit a95c332
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
11 changes: 8 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <pka@sourcepole.ch>", "Yuri Astrakhan <YuriAstrakhan@gmail.com>"]
authors = [
"Pirmin Kalberer <pka@sourcepole.ch>",
"Yuri Astrakhan <YuriAstrakhan@gmail.com>",
]
edition = "2021"
homepage = "https://github.com/georust/geozero"
repository = "https://github.com/georust/geozero"
Expand All @@ -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"
Expand Down Expand Up @@ -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" }
Expand Down
14 changes: 6 additions & 8 deletions geozero/src/csv/csv_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
21 changes: 10 additions & 11 deletions geozero/src/wkt/wkt_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -78,22 +77,22 @@ pub fn read_wkt<R: Read, P: GeomProcessor>(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<P: GeomProcessor>(geometry: &Geometry<f64>, processor: &mut P) -> Result<()> {
fn process_wkt_geom<P: GeomProcessor>(geometry: &wkt::Wkt<f64>, processor: &mut P) -> Result<()> {
process_wkt_geom_n(geometry, 0, processor)
}

pub(crate) fn process_wkt_geom_n<P: GeomProcessor>(
geometry: &Geometry<f64>,
geometry: &wkt::Wkt<f64>,
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)?;
Expand All @@ -102,7 +101,7 @@ pub(crate) fn process_wkt_geom_n<P: GeomProcessor>(
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() {
Expand All @@ -116,23 +115,23 @@ pub(crate) fn process_wkt_geom_n<P: GeomProcessor>(
}
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)?;
Expand Down

0 comments on commit a95c332

Please sign in to comment.