-
Notifications
You must be signed in to change notification settings - Fork 65
Fix writing WKT with z/m dimensions #237
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| self.to_wkt_with_opts(WktDialect::Ewkt, CoordDimensions::xy(), srid) | ||
| } | ||
|
|
||
| fn to_wkt_ndim(&self, dims: CoordDimensions) -> Result<String> { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 { | ||
|
|
@@ -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")] | ||
|
|
@@ -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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| } | ||
|
|
||
| #[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()); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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
xyzdoesn't matter? I thought at first below was a typo and that theLineStringwas meant to be 3d, but this entire test is otherwise the exact same as the one before it.