Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion geozero/src/gdal/gdal_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ mod test {

#[test]
fn line_3d() {
let wkt = "LINESTRING(1 1 10,2 2 20)";
let wkt = "LINESTRING Z(1 1 10,2 2 20)";
let geo = Geometry::from_wkt(wkt).unwrap();
assert_eq!(
geo.to_wkt_ndim(CoordDimensions {
Expand Down
4 changes: 2 additions & 2 deletions geozero/src/geojson/geojson_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,11 @@ mod test {
let mut out = WktWriter::with_dims(&mut wkt_data, CoordDimensions::xyz());
assert!(read_geojson_geom(&mut geojson.as_bytes(), &mut out).is_ok());
let wkt = std::str::from_utf8(&wkt_data).unwrap();
assert_eq!(wkt, "LINESTRING(1 1 10,2 2 20)");
assert_eq!(wkt, "LINESTRING Z(1 1 10,2 2 20)");

let geojson = r#"{"type": "LineString", "coordinates": [[1,1],[2,2]]}"#;
let mut wkt_data: Vec<u8> = Vec::new();
let mut out = WktWriter::with_dims(&mut wkt_data, CoordDimensions::xyz());
let mut out = WktWriter::with_dims(&mut wkt_data, CoordDimensions::xy());

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not sure what this is supposed to test. Is it supposed to test that setting xyz doesn't matter? I thought at first below was a typo and that the LineString was meant to be 3d, but this entire test is otherwise the exact same as the one before it.

assert!(read_geojson_geom(&mut geojson.as_bytes(), &mut out).is_ok());
let wkt = std::str::from_utf8(&wkt_data).unwrap();
assert_eq!(wkt, "LINESTRING(1 1,2 2)");
Expand Down
2 changes: 1 addition & 1 deletion geozero/src/geos/geos_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ mod test {

#[test]
fn line_geom_3d() {
let wkt = "LINESTRING(1 1 10,2 2 20)";
let wkt = "LINESTRING Z(1 1 10,2 2 20)";
let ggeom = GGeometry::new_from_wkt(wkt).unwrap();

let mut wkt_data: Vec<u8> = Vec::new();
Expand Down
8 changes: 4 additions & 4 deletions geozero/src/wkb/wkb_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ mod test {
assert!(process_ewkb_geom(&mut ewkb.as_slice(), &mut writer).is_ok());
assert_eq!(
std::str::from_utf8(&wkt_data).unwrap(),
"POINT(10 -20 100 1)"
"POINT ZM(10 -20 100 1)"
);

// SELECT 'SRID=4326;MULTIPOINT ((10 -20 100), (0 -0.5 101))'::geometry
Expand Down Expand Up @@ -697,7 +697,7 @@ mod test {
// SELECT 'SRID=4326;MULTIPOINT (10 -20 100, 0 -0.5 101)'::geometry
assert_eq!(
&ewkb_to_wkt("01040000A0E6100000020000000101000080000000000000244000000000000034C0000000000000594001010000800000000000000000000000000000E0BF0000000000405940", true),
"MULTIPOINT(10 -20 100,0 -0.5 101)"
"MULTIPOINT Z(10 -20 100,0 -0.5 101)"
//OGR: MULTIPOINT ((10 -20 100),(0 -0.5 101))
);

Expand Down Expand Up @@ -776,7 +776,7 @@ mod test {
// SELECT 'POLYHEDRALSURFACE(((0 0 0,0 0 1,0 1 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,1 0 1,0 0 1,0 0 0)),((1 1 0,1 1 1,1 0 1,1 0 0,1 1 0)),((0 1 0,0 1 1,1 1 1,1 1 0,0 1 0)),((0 0 1,1 0 1,1 1 1,0 1 1,0 0 1)))'::geometry
assert_eq!(
&ewkb_to_wkt("010F000080060000000103000080010000000500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F000000000000F03F0000000000000000000000000000F03F0000000000000000000000000000000000000000000000000000000000000000010300008001000000050000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F000000000000F03F0000000000000000000000000000F03F0000000000000000000000000000000000000000000000000000000000000000000000000000000001030000800100000005000000000000000000000000000000000000000000000000000000000000000000F03F00000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F00000000000000000000000000000000000000000000F03F00000000000000000000000000000000000000000000000001030000800100000005000000000000000000F03F000000000000F03F0000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F0000000000000000000000000000F03F000000000000F03F00000000000000000000000000000000000000000000F03F000000000000F03F0000000000000000010300008001000000050000000000000000000000000000000000F03F00000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000F03F00000000000000000000000000000000000000000000F03F00000000000000000103000080010000000500000000000000000000000000000000000000000000000000F03F000000000000F03F0000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F0000000000000000000000000000F03F000000000000F03F00000000000000000000000000000000000000000000F03F", true),
"POLYHEDRALSURFACE(((0 0 0,0 0 1,0 1 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,1 0 1,0 0 1,0 0 0)),((1 1 0,1 1 1,1 0 1,1 0 0,1 1 0)),((0 1 0,0 1 1,1 1 1,1 1 0,0 1 0)),((0 0 1,1 0 1,1 1 1,0 1 1,0 0 1)))"
"POLYHEDRALSURFACE Z(((0 0 0,0 0 1,0 1 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,1 0 1,0 0 1,0 0 0)),((1 1 0,1 1 1,1 0 1,1 0 0,1 1 0)),((0 1 0,0 1 1,1 1 1,1 1 0,0 1 0)),((0 0 1,1 0 1,1 1 1,0 1 1,0 0 1)))"
);
// SELECT 'TIN(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 1 0,0 0 0)))'::geometry
assert_eq!(
Expand Down Expand Up @@ -832,7 +832,7 @@ mod test {
assert!(process_spatialite_geom(&mut ewkb.as_slice(), &mut writer).is_ok());
assert_eq!(
std::str::from_utf8(&wkt_data).unwrap(),
"POINT(10 -20 100 1)"
"POINT ZM(10 -20 100 1)"
);

// SELECT HEX(TinyPointEncode(ST_GeomFromText('POINTZM(10 -20 100 1)', 4326)));
Expand Down
2 changes: 1 addition & 1 deletion geozero/src/wkt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub(crate) mod conversion {
}

fn to_ewkt(&self, srid: Option<i32>) -> Result<String> {
self.to_wkt_with_opts(WktDialect::Ewkt, CoordDimensions::xyzm(), srid)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not sure the right way to fix this, but as I understand it, setting CoordDimensions says "this output will have these given geometries", and so defaulting to xyzm seems incorrect.

self.to_wkt_with_opts(WktDialect::Ewkt, CoordDimensions::xy(), srid)
}

fn to_wkt_ndim(&self, dims: CoordDimensions) -> Result<String> {
Expand Down
42 changes: 35 additions & 7 deletions geozero/src/wkt/wkt_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ impl<W: Write> WktWriter<W> {
if tagged {
self.out.write_all(tag)?;
}
if is_z(self.dims) {
self.out.write_all(b" Z")?;
} else if is_m(self.dims) {
self.out.write_all(b" M")?;
} else if is_zm(self.dims) {
self.out.write_all(b" ZM")?;
}
self.geometry_sizes.push(size);
if size == 0 {
if tagged {
Expand Down Expand Up @@ -235,13 +242,24 @@ impl<W: Write> PropertyProcessor for WktWriter<W> {}

impl<W: Write> FeatureProcessor for WktWriter<W> {}

fn is_z(dims: CoordDimensions) -> bool {
dims.z && !dims.m
}

fn is_m(dims: CoordDimensions) -> bool {
dims.m && !dims.z
}

fn is_zm(dims: CoordDimensions) -> bool {
dims.z && dims.m
}

#[cfg(test)]
mod test {
#[cfg(feature = "with-wkb")]
use crate::wkb::{FromWkb, WkbDialect};
#[cfg(feature = "with-wkb")]
use crate::wkt::Ewkt;
use crate::ToWkt;
use crate::wkb::Ewkb;
use crate::wkt::{Wkt, WktDialect};
use crate::{CoordDimensions, ToWkt};

#[test]
#[cfg(feature = "with-geo")]
Expand All @@ -255,8 +273,18 @@ mod test {
#[cfg(feature = "with-wkb")]
fn from_wkb() {
let blob = hex::decode("01040000A0E6100000020000000101000080000000000000244000000000000034C0000000000000594001010000800000000000000000000000000000E0BF0000000000405940").unwrap();
let mut cursor = std::io::Cursor::new(blob);
let ewkt = Ewkt::from_wkb(&mut cursor, WkbDialect::Ewkb).unwrap();
assert_eq!(ewkt.0, "SRID=4326;MULTIPOINT(10 -20 100,0 -0.5 101)")
let ewkt = Ewkb(blob)
.to_wkt_with_opts(WktDialect::Ewkt, CoordDimensions::xyz(), Some(4326))
.unwrap();
assert_eq!(ewkt, "SRID=4326;MULTIPOINT Z(10 -20 100,0 -0.5 101)")
Comment on lines +276 to +279

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Similarly, the API just isn't sufficient... There's no way to get the coordinate dimension from the EWKB without consuming it. And so there's no way right now to know the SRID and CoordDimensions of the input and pass that on to the writer at the beginning.

}

#[test]
fn read_write_wkt_point_z() {
let s = "POINT Z(40 10 50)";
let wkt = Wkt(s);

let out = wkt.to_wkt_ndim(CoordDimensions::xyz()).unwrap();
assert_eq!(s, out.as_str());
}
}