Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for latest wkt #221

Merged
merged 6 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = [
kylebarron marked this conversation as resolved.
Show resolved Hide resolved
"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 = "0.11"

[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 @@ -4,7 +4,6 @@ use crate::{FeatureProcessor, GeomProcessor, GeozeroDatasource, GeozeroGeometry}
use std::io::Read;
use std::str::FromStr;
use wkt::types::{Coord, LineString, Polygon};
use wkt::Geometry;

/// A wrapper around a WKT String or String slice.
#[derive(Debug)]
Expand Down Expand Up @@ -85,22 +84,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<()> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we simplify all these with use wkt::Wkt ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are already other entities in the local module scope called Wkt. You could use an alias, but it's unlikely to be any more concise than wkt::Wkt.

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 @@ -109,7 +108,7 @@ pub(crate) fn process_wkt_geom_n<P: GeomProcessor>(
processor.empty_point(idx)
}
}
Geometry::MultiPoint(g) => {
wkt::Wkt::MultiPoint(g) => {
nyurik marked this conversation as resolved.
Show resolved Hide resolved
processor.multipoint_begin(g.0.len(), idx)?;
let multi_dim1 = processor.multi_dim();
for (idxc, point) in g.0.iter().enumerate() {
Expand All @@ -123,23 +122,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
Loading