diff --git a/geozero/src/error.rs b/geozero/src/error.rs index 5d99cce3..6c6cae68 100644 --- a/geozero/src/error.rs +++ b/geozero/src/error.rs @@ -32,7 +32,7 @@ pub enum GeozeroError { // GeometryProcessor #[error("accessing requested coordinate")] Coord, - #[error("expected a valid srid value but found `{0}`")] + #[error("invalid SRID value `{0}`")] Srid(i32), #[error("processing geometry `{0}`")] Geometry(String), diff --git a/geozero/src/wkb/wkb_reader.rs b/geozero/src/wkb/wkb_reader.rs index 15d06c8e..b3a2a3d5 100644 --- a/geozero/src/wkb/wkb_reader.rs +++ b/geozero/src/wkb/wkb_reader.rs @@ -1,10 +1,8 @@ use crate::error::{GeozeroError, Result}; use crate::wkb::{WKBGeometryType, WkbDialect}; use crate::{GeomProcessor, GeozeroGeometry}; -use scroll::{ - ctx::{FromCtx, SizeWith}, - Endian, IOread, -}; +use scroll::ctx::{FromCtx, SizeWith}; +use scroll::{Endian, IOread}; use std::io::Read; #[cfg(feature = "with-postgis-diesel")] @@ -130,16 +128,13 @@ pub(crate) fn read_wkb_header(raw: &mut R) -> Result { let is_little_endian = byte_order != 0; let endian = Endian::from(is_little_endian); let type_id = raw.ioread_with::(endian)?; - let base_type = WKBGeometryType::from_u32(type_id % 1000); let type_id_dim = type_id / 1000; - let has_z = type_id_dim == 1 || type_id_dim == 3; - let has_m = type_id_dim == 2 || type_id_dim == 3; let info = WkbInfo { endian, - base_type, - has_z, - has_m, + base_type: WKBGeometryType::from_u32(type_id % 1000), + has_z: matches!(type_id_dim, 1 | 3), + has_m: matches!(type_id_dim, 2 | 3), srid: None, is_compressed: false, envelope: Vec::new(), @@ -156,12 +151,7 @@ fn read_ewkb_header(raw: &mut R) -> Result { let byte_order = raw.ioread::()?; let is_little_endian = byte_order != 0; let endian = Endian::from(is_little_endian); - let type_id = raw.ioread_with::(endian)?; - let base_type = WKBGeometryType::from_u32(type_id & 0xFF); - let has_z = type_id & 0x8000_0000 == 0x8000_0000; - let has_m = type_id & 0x4000_0000 == 0x4000_0000; - let srid = if type_id & 0x2000_0000 == 0x2000_0000 { Some(raw.ioread_with::(endian)?) } else { @@ -170,9 +160,9 @@ fn read_ewkb_header(raw: &mut R) -> Result { let info = WkbInfo { endian, - base_type, - has_z, - has_m, + base_type: WKBGeometryType::from_u32(type_id & 0xFF), + has_z: type_id & 0x8000_0000 == 0x8000_0000, + has_m: type_id & 0x4000_0000 == 0x4000_0000, srid, is_compressed: false, envelope: Vec::new(), @@ -233,26 +223,22 @@ pub(crate) fn read_spatialite_header(raw: &mut R) -> Result { let flags = raw.ioread::()?; let is_little_endian = flags & 0b0000_0001 != 0; let endian = Endian::from(is_little_endian); - let is_tinypoint = flags & 0b1000_0000 != 0; + let is_tiny_point = flags & 0b1000_0000 != 0; let srid = match raw.ioread_with::(endian)? { 0 => None, val => Some(val), }; - let info = if is_tinypoint { - let envelope = Vec::::new(); - let base_type = WKBGeometryType::Point; + let info = if is_tiny_point { let type_id_dim = raw.ioread_with::(endian)?; - let has_z = matches!(type_id_dim, 2 | 4); - let has_m = matches!(type_id_dim, 3 | 4); WkbInfo { endian, srid, - envelope, - base_type, - has_z, - has_m, + envelope: Vec::::new(), + base_type: WKBGeometryType::Point, + has_z: matches!(type_id_dim, 2 | 4), + has_m: matches!(type_id_dim, 3 | 4), is_compressed: false, } } else { @@ -264,19 +250,15 @@ pub(crate) fn read_spatialite_header(raw: &mut R) -> Result { return Err(GeozeroError::GeometryFormat); } let type_id = raw.ioread_with::(endian)?; - let is_compressed = type_id > 1000000; let type_id_dim = (type_id % 1000000) / 1000; - let has_z = matches!(type_id_dim, 1 | 3); - let has_m = matches!(type_id_dim, 2 | 3); - let base_type = WKBGeometryType::from_u32(type_id % 1000); WkbInfo { endian, srid, envelope, - base_type, - has_z, - has_m, - is_compressed, + base_type: WKBGeometryType::from_u32(type_id % 1000), + has_z: matches!(type_id_dim, 1 | 3), + has_m: matches!(type_id_dim, 2 | 3), + is_compressed: type_id > 1000000, } }; @@ -292,11 +274,9 @@ pub(crate) fn read_spatialite_nested_header( return Err(GeozeroError::GeometryFormat); } let type_id = raw.ioread_with::(info.endian)?; - let base_type = WKBGeometryType::from_u32(type_id % 1000); - let is_compressed = type_id > 1000000; Ok(WkbInfo { - base_type, - is_compressed, + base_type: WKBGeometryType::from_u32(type_id % 1000), + is_compressed: type_id > 1000000, endian: info.endian, srid: info.srid, envelope: Vec::new(), diff --git a/geozero/src/wkb/wkb_writer.rs b/geozero/src/wkb/wkb_writer.rs index 4d098f56..db1e2fbc 100644 --- a/geozero/src/wkb/wkb_writer.rs +++ b/geozero/src/wkb/wkb_writer.rs @@ -195,11 +195,10 @@ impl<'a, W: Write> WkbWriter<'a, W> { /// MySQL WKB header according to https://dev.mysql.com/doc/refman/8.0/en/gis-data-formats.html fn write_mysql_header(&mut self) -> Result<()> { - let srid: u32 = self - .srid - .unwrap_or(0) - .try_into() - .map_err(|_| GeozeroError::Srid(self.srid.unwrap()))?; + let srid: u32 = match self.srid { + None => 0, + Some(v) => v.try_into().map_err(|_| GeozeroError::Srid(v))?, + }; self.out.iowrite_with(srid, self.endian)?; Ok(()) } @@ -401,14 +400,19 @@ impl FeatureProcessor for WkbWriter<'_, W> {} mod test { use super::*; use crate::wkb::process_wkb_type_geom; + use crate::wkb::WkbDialect::{Ewkb, Geopackage, MySQL, SpatiaLite}; use crate::ToWkb; + const DIM_XY: CoordDimensions = CoordDimensions::xy(); + const DIM_XYZ: CoordDimensions = CoordDimensions::xyz(); + const DIM_XYZM: CoordDimensions = CoordDimensions::xyzm(); + fn roundtrip( dialect: WkbDialect, - ewkb_str: &str, dims: CoordDimensions, srid: Option, envelope: Vec, + ewkb_str: &str, ) { let wkb_in = hex::decode(ewkb_str).unwrap(); let mut wkb_out: Vec = Vec::new(); @@ -425,147 +429,145 @@ mod test { fn ewkb_geometries() { // SELECT 'POINT(10 -20)'::geometry roundtrip( - WkbDialect::Ewkb, - "0101000000000000000000244000000000000034C0", - CoordDimensions::default(), + Ewkb, + DIM_XY, None, Vec::new(), + "0101000000000000000000244000000000000034C0", ); // SELECT 'SRID=4326;MULTIPOINT (10 -20 100, 0 -0.5 101)'::geometry - roundtrip(WkbDialect::Ewkb, "01040000A0E6100000020000000101000080000000000000244000000000000034C0000000000000594001010000800000000000000000000000000000E0BF0000000000405940", - CoordDimensions::xyz(), Some(4326), Vec::new()); + roundtrip(Ewkb, DIM_XYZ, Some(4326), Vec::new(), + "01040000A0E6100000020000000101000080000000000000244000000000000034C0000000000000594001010000800000000000000000000000000000E0BF0000000000405940"); // SELECT 'SRID=4326;LINESTRING (10 -20 100, 0 -0.5 101)'::geometry - roundtrip(WkbDialect::Ewkb, "01020000A0E610000002000000000000000000244000000000000034C000000000000059400000000000000000000000000000E0BF0000000000405940", - CoordDimensions::xyz(), Some(4326), Vec::new()); + roundtrip(Ewkb, DIM_XYZ, Some(4326), Vec::new(), + "01020000A0E610000002000000000000000000244000000000000034C000000000000059400000000000000000000000000000E0BF0000000000405940"); // SELECT 'SRID=4326;MULTILINESTRING ((10 -20, 0 -0.5), (0 0, 2 0))'::geometry - roundtrip(WkbDialect::Ewkb, "0105000020E610000002000000010200000002000000000000000000244000000000000034C00000000000000000000000000000E0BF0102000000020000000000000000000000000000000000000000000000000000400000000000000000", - CoordDimensions::default(), Some(4326), Vec::new()); + roundtrip(Ewkb, DIM_XY, Some(4326), Vec::new(), + "0105000020E610000002000000010200000002000000000000000000244000000000000034C00000000000000000000000000000E0BF0102000000020000000000000000000000000000000000000000000000000000400000000000000000"); // SELECT 'SRID=4326;POLYGON ((0 0, 2 0, 2 2, 0 2, 0 0))'::geometry - roundtrip(WkbDialect::Ewkb, "0103000020E610000001000000050000000000000000000000000000000000000000000000000000400000000000000000000000000000004000000000000000400000000000000000000000000000004000000000000000000000000000000000", - CoordDimensions::default(), Some(4326), Vec::new()); + roundtrip(Ewkb, DIM_XY, Some(4326), Vec::new(), + "0103000020E610000001000000050000000000000000000000000000000000000000000000000000400000000000000000000000000000004000000000000000400000000000000000000000000000004000000000000000000000000000000000"); // SELECT 'SRID=4326;MULTIPOLYGON (((0 0, 2 0, 2 2, 0 2, 0 0)), ((10 10, -2 10, -2 -2, 10 -2, 10 10)))'::geometry - roundtrip(WkbDialect::Ewkb, "0106000020E610000002000000010300000001000000050000000000000000000000000000000000000000000000000000400000000000000000000000000000004000000000000000400000000000000000000000000000004000000000000000000000000000000000010300000001000000050000000000000000002440000000000000244000000000000000C0000000000000244000000000000000C000000000000000C0000000000000244000000000000000C000000000000024400000000000002440", - CoordDimensions::default(), Some(4326), Vec::new()); + roundtrip(Ewkb, DIM_XY, Some(4326), Vec::new(), + "0106000020E610000002000000010300000001000000050000000000000000000000000000000000000000000000000000400000000000000000000000000000004000000000000000400000000000000000000000000000004000000000000000000000000000000000010300000001000000050000000000000000002440000000000000244000000000000000C0000000000000244000000000000000C000000000000000C0000000000000244000000000000000C000000000000024400000000000002440"); // SELECT 'GeometryCollection(POINT (10 10),POINT (30 30),LINESTRING (15 15, 20 20))'::geometry - roundtrip(WkbDialect::Ewkb, "01070000000300000001010000000000000000002440000000000000244001010000000000000000003E400000000000003E400102000000020000000000000000002E400000000000002E4000000000000034400000000000003440", - CoordDimensions::default(), None, Vec::new()); + roundtrip(Ewkb, DIM_XY, None, Vec::new(), + "01070000000300000001010000000000000000002440000000000000244001010000000000000000003E400000000000003E400102000000020000000000000000002E400000000000002E4000000000000034400000000000003440"); } #[test] fn ewkb_curves() { // SELECT 'CIRCULARSTRING(0 0,1 1,2 0)'::geometry - roundtrip(WkbDialect::Ewkb, "01080000000300000000000000000000000000000000000000000000000000F03F000000000000F03F00000000000000400000000000000000", - CoordDimensions::default(), None, Vec::new()); + roundtrip(Ewkb, DIM_XY, None, Vec::new(), + "01080000000300000000000000000000000000000000000000000000000000F03F000000000000F03F00000000000000400000000000000000"); // SELECT 'COMPOUNDCURVE (CIRCULARSTRING (0 0,1 1,2 0),(2 0,3 0))'::geometry - roundtrip(WkbDialect::Ewkb, "01090000000200000001080000000300000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000004000000000000000000102000000020000000000000000000040000000000000000000000000000008400000000000000000", - CoordDimensions::default(), None, Vec::new()); + roundtrip(Ewkb, DIM_XY, None, Vec::new(), + "01090000000200000001080000000300000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000004000000000000000000102000000020000000000000000000040000000000000000000000000000008400000000000000000"); // SELECT 'CURVEPOLYGON(COMPOUNDCURVE(CIRCULARSTRING(0 0,1 1,2 0),(2 0,3 0,3 -1,0 -1,0 0)))'::geometry - roundtrip(WkbDialect::Ewkb, "010A0000000100000001090000000200000001080000000300000000000000000000000000000000000000000000000000F03F000000000000F03F0000000000000040000000000000000001020000000500000000000000000000400000000000000000000000000000084000000000000000000000000000000840000000000000F0BF0000000000000000000000000000F0BF00000000000000000000000000000000", - CoordDimensions::default(), None, Vec::new()); + roundtrip(Ewkb, DIM_XY, None, Vec::new(), + "010A0000000100000001090000000200000001080000000300000000000000000000000000000000000000000000000000F03F000000000000F03F0000000000000040000000000000000001020000000500000000000000000000400000000000000000000000000000084000000000000000000000000000000840000000000000F0BF0000000000000000000000000000F0BF00000000000000000000000000000000"); // SELECT 'MULTICURVE((0 0, 5 5),CIRCULARSTRING(4 0, 4 4, 8 4))'::geometry - roundtrip(WkbDialect::Ewkb, "010B000000020000000102000000020000000000000000000000000000000000000000000000000014400000000000001440010800000003000000000000000000104000000000000000000000000000001040000000000000104000000000000020400000000000001040", - CoordDimensions::default(), None, Vec::new()); + roundtrip(Ewkb, DIM_XY, None, Vec::new(), + "010B000000020000000102000000020000000000000000000000000000000000000000000000000014400000000000001440010800000003000000000000000000104000000000000000000000000000001040000000000000104000000000000020400000000000001040"); // SELECT 'MULTISURFACE (CURVEPOLYGON (COMPOUNDCURVE (CIRCULARSTRING (0 0,1 1,2 0),(2 0,3 0,3 -1,0 -1,0 0))))'::geometry - roundtrip(WkbDialect::Ewkb, "010C00000001000000010A0000000100000001090000000200000001080000000300000000000000000000000000000000000000000000000000F03F000000000000F03F0000000000000040000000000000000001020000000500000000000000000000400000000000000000000000000000084000000000000000000000000000000840000000000000F0BF0000000000000000000000000000F0BF00000000000000000000000000000000", - CoordDimensions::default(), None, Vec::new()); + roundtrip(Ewkb, DIM_XY, None, Vec::new(), + "010C00000001000000010A0000000100000001090000000200000001080000000300000000000000000000000000000000000000000000000000F03F000000000000F03F0000000000000040000000000000000001020000000500000000000000000000400000000000000000000000000000084000000000000000000000000000000840000000000000F0BF0000000000000000000000000000F0BF00000000000000000000000000000000"); } #[test] fn ewkb_surfaces() { // 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 - roundtrip(WkbDialect::Ewkb, "010F000080060000000103000080010000000500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F000000000000F03F0000000000000000000000000000F03F0000000000000000000000000000000000000000000000000000000000000000010300008001000000050000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F000000000000F03F0000000000000000000000000000F03F0000000000000000000000000000000000000000000000000000000000000000000000000000000001030000800100000005000000000000000000000000000000000000000000000000000000000000000000F03F00000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F00000000000000000000000000000000000000000000F03F00000000000000000000000000000000000000000000000001030000800100000005000000000000000000F03F000000000000F03F0000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F0000000000000000000000000000F03F000000000000F03F00000000000000000000000000000000000000000000F03F000000000000F03F0000000000000000010300008001000000050000000000000000000000000000000000F03F00000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000F03F00000000000000000000000000000000000000000000F03F00000000000000000103000080010000000500000000000000000000000000000000000000000000000000F03F000000000000F03F0000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F0000000000000000000000000000F03F000000000000F03F00000000000000000000000000000000000000000000F03F", - CoordDimensions::xyz(), None, Vec::new()); + roundtrip(Ewkb, DIM_XYZ, None, Vec::new(), + "010F000080060000000103000080010000000500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F000000000000F03F0000000000000000000000000000F03F0000000000000000000000000000000000000000000000000000000000000000010300008001000000050000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F000000000000F03F0000000000000000000000000000F03F0000000000000000000000000000000000000000000000000000000000000000000000000000000001030000800100000005000000000000000000000000000000000000000000000000000000000000000000F03F00000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F00000000000000000000000000000000000000000000F03F00000000000000000000000000000000000000000000000001030000800100000005000000000000000000F03F000000000000F03F0000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F0000000000000000000000000000F03F000000000000F03F00000000000000000000000000000000000000000000F03F000000000000F03F0000000000000000010300008001000000050000000000000000000000000000000000F03F00000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000F03F00000000000000000000000000000000000000000000F03F00000000000000000103000080010000000500000000000000000000000000000000000000000000000000F03F000000000000F03F0000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F0000000000000000000000000000F03F000000000000F03F00000000000000000000000000000000000000000000F03F"); // 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 - roundtrip(WkbDialect::Ewkb, "0110000080020000000111000080010000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F0000000000000000000000000000000000000000000000000000000000000000011100008001000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F000000000000F03F0000000000000000000000000000000000000000000000000000000000000000", - CoordDimensions::xyz(), None, Vec::new()); + roundtrip(Ewkb, DIM_XYZ, None, Vec::new(), + "0110000080020000000111000080010000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F0000000000000000000000000000000000000000000000000000000000000000011100008001000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F000000000000F03F0000000000000000000000000000000000000000000000000000000000000000"); // SELECT 'TRIANGLE((0 0,0 9,9 0,0 0))'::geometry - roundtrip(WkbDialect::Ewkb, "0111000000010000000400000000000000000000000000000000000000000000000000000000000000000022400000000000002240000000000000000000000000000000000000000000000000", - CoordDimensions::default(), None, Vec::new()); + roundtrip(Ewkb, DIM_XY, None, Vec::new(), + "0111000000010000000400000000000000000000000000000000000000000000000000000000000000000022400000000000002240000000000000000000000000000000000000000000000000"); } #[test] fn gpkg_geometries() { // pt2d - roundtrip(WkbDialect::Geopackage, "47500003E61000009A9999999999F13F9A9999999999F13F9A9999999999F13F9A9999999999F13F01010000009A9999999999F13F9A9999999999F13F", - CoordDimensions::default(), Some(4326), vec![1.1, 1.1, 1.1, 1.1]); + roundtrip(Geopackage, DIM_XY, Some(4326), vec![1.1, 1.1, 1.1, 1.1], + "47500003E61000009A9999999999F13F9A9999999999F13F9A9999999999F13F9A9999999999F13F01010000009A9999999999F13F9A9999999999F13F"); // mln3dzm - roundtrip(WkbDialect::Geopackage, "47500003E6100000000000000000244000000000000034400000000000002440000000000000344001BD0B00000100000001BA0B0000020000000000000000003440000000000000244000000000000008400000000000001440000000000000244000000000000034400000000000001C400000000000000040", - CoordDimensions::xyzm(), Some(4326), vec![10.0, 20.0, 10.0, 20.0]); + roundtrip(Geopackage, DIM_XYZM, Some(4326), vec![10.0, 20.0, 10.0, 20.0], + "47500003E6100000000000000000244000000000000034400000000000002440000000000000344001BD0B00000100000001BA0B0000020000000000000000003440000000000000244000000000000008400000000000001440000000000000244000000000000034400000000000001C400000000000000040"); // gc2d - roundtrip(WkbDialect::Geopackage, "47500003e6100000000000000000f03f0000000000003640000000000000084000000000000036400107000000020000000101000000000000000000f03f00000000000008400103000000010000000400000000000000000035400000000000003540000000000000364000000000000035400000000000003540000000000000364000000000000035400000000000003540", - CoordDimensions::default(), Some(4326), vec![1.0, 22.0, 3.0, 22.0]); + roundtrip(Geopackage, DIM_XY, Some(4326), vec![1.0, 22.0, 3.0, 22.0], + "47500003e6100000000000000000f03f0000000000003640000000000000084000000000000036400107000000020000000101000000000000000000f03f00000000000008400103000000010000000400000000000000000035400000000000003540000000000000364000000000000035400000000000003540000000000000364000000000000035400000000000003540"); } #[test] fn spatialite_geometries() { // SELECT HEX(ST_GeomFromText('POINT(1.1 1.1)', 4326)); - roundtrip(WkbDialect::SpatiaLite, "0001E61000009A9999999999F13F9A9999999999F13F9A9999999999F13F9A9999999999F13F7C010000009A9999999999F13F9A9999999999F13FFE", - CoordDimensions::default(), Some(4326), vec![1.1, 1.1, 1.1, 1.1]); + roundtrip(SpatiaLite, DIM_XY, Some(4326), vec![1.1, 1.1, 1.1, 1.1], + "0001E61000009A9999999999F13F9A9999999999F13F9A9999999999F13F9A9999999999F13F7C010000009A9999999999F13F9A9999999999F13FFE"); // SELECT HEX(ST_GeomFromText('MULTIPOINT(1 2,3 4)')); - roundtrip(WkbDialect::SpatiaLite, "000100000000000000000000F03F0000000000000040000000000000084000000000000010407C04000000020000006901000000000000000000F03F0000000000000040690100000000000000000008400000000000001040FE", - CoordDimensions::default(), None, vec![1.0, 2.0, 3.0, 4.0]); + roundtrip(SpatiaLite, DIM_XY, None, vec![1.0, 2.0, 3.0, 4.0], + "000100000000000000000000F03F0000000000000040000000000000084000000000000010407C04000000020000006901000000000000000000F03F0000000000000040690100000000000000000008400000000000001040FE"); // SELECT HEX(ST_GeomFromText('MULTILINESTRINGZM((20 10 5 1,10 20 30 40))')); - roundtrip(WkbDialect::SpatiaLite, "00010000000000000000000024400000000000002440000000000000344000000000000034407CBD0B00000100000069BA0B000002000000000000000000344000000000000024400000000000001440000000000000F03F000000000000244000000000000034400000000000003E400000000000004440FE", - CoordDimensions::xyzm(), None, vec![10.0, 10.0, 20.0, 20.0]); + roundtrip(SpatiaLite, DIM_XYZM, None, vec![10.0, 10.0, 20.0, 20.0], + "00010000000000000000000024400000000000002440000000000000344000000000000034407CBD0B00000100000069BA0B000002000000000000000000344000000000000024400000000000001440000000000000F03F000000000000244000000000000034400000000000003E400000000000004440FE"); // SELECT HEX(ST_GeomFromText('GEOMETRYCOLLECTION(POINT(1 3),POLYGON((21 21,22 21,21 22,21 21)))')); - roundtrip(WkbDialect::SpatiaLite, "000100000000000000000000F03F0000000000000840000000000000364000000000000036407C07000000020000006901000000000000000000F03F00000000000008406903000000010000000400000000000000000035400000000000003540000000000000364000000000000035400000000000003540000000000000364000000000000035400000000000003540FE", - CoordDimensions::default(), None, vec![1.0, 3.0, 22.0, 22.0]); + roundtrip(SpatiaLite, DIM_XY, None, vec![1.0, 3.0, 22.0, 22.0], + "000100000000000000000000F03F0000000000000840000000000000364000000000000036407C07000000020000006901000000000000000000F03F00000000000008406903000000010000000400000000000000000035400000000000003540000000000000364000000000000035400000000000003540000000000000364000000000000035400000000000003540FE"); } #[test] fn mysql_geometries() { // SELECT HEX(ST_GeomFromText('POINT(10 -20)', 4326, 'axis-order=long-lat')); roundtrip( - WkbDialect::MySQL, - "E61000000101000000000000000000244000000000000034C0", - CoordDimensions::default(), + MySQL, + DIM_XY, Some(4326), Vec::new(), + "E61000000101000000000000000000244000000000000034C0", ); // SELECT HEX(ST_GeomFromText('MULTIPOINT(1 2,3 4)', 0, 'axis-order=long-lat')); - roundtrip(WkbDialect::MySQL, "000000000104000000020000000101000000000000000000F03F0000000000000040010100000000000000000008400000000000001040", - CoordDimensions::default(), None, Vec::new()); + roundtrip(MySQL, DIM_XY, None, Vec::new(), + "000000000104000000020000000101000000000000000000F03F0000000000000040010100000000000000000008400000000000001040"); // SELECT HEX(ST_GeomFromText('MULTILINESTRING((20 10,10 20))', 0, 'axis-order=long-lat')); - roundtrip(WkbDialect::MySQL, "000000000105000000010000000102000000020000000000000000003440000000000000244000000000000024400000000000003440", - CoordDimensions::default(), None, Vec::new()); + roundtrip(MySQL, DIM_XY, None, Vec::new(), + "000000000105000000010000000102000000020000000000000000003440000000000000244000000000000024400000000000003440"); // SELECT HEX(ST_GeomFromText('GEOMETRYCOLLECTION(POINT(1 3),POLYGON((21 21,22 21,21 22,21 21)))', 0, 'axis-order=long-lat')); - roundtrip(WkbDialect::MySQL, "000000000107000000020000000101000000000000000000F03F00000000000008400103000000010000000400000000000000000035400000000000003540000000000000364000000000000035400000000000003540000000000000364000000000000035400000000000003540", - CoordDimensions::default(), None, Vec::new()); + roundtrip(MySQL, DIM_XY, None, Vec::new(), + "000000000107000000020000000101000000000000000000F03F00000000000008400103000000010000000400000000000000000035400000000000003540000000000000364000000000000035400000000000003540000000000000364000000000000035400000000000003540"); } #[test] #[cfg(feature = "with-geo")] fn conversions() { let geom: geo_types::Geometry = geo_types::Point::new(10.0, -20.0).into(); - let wkb = geom.to_ewkb(CoordDimensions::default(), None).unwrap(); + let wkb = geom.to_ewkb(DIM_XY, None).unwrap(); assert_eq!( &wkb, // SELECT 'POINT(10 -20)'::geometry &hex::decode("0101000000000000000000244000000000000034C0").unwrap() ); - let wkb = geom - .to_ewkb(CoordDimensions::default(), Some(4326)) - .unwrap(); + let wkb = geom.to_ewkb(DIM_XY, Some(4326)).unwrap(); assert_eq!( &wkb, &[1, 1, 0, 0, 32, 230, 16, 0, 0, 0, 0, 0, 0, 0, 0, 36, 64, 0, 0, 0, 0, 0, 0, 52, 192] @@ -573,11 +575,7 @@ mod test { let geom: geo_types::Geometry = geo_types::Point::new(1.1, 1.1).into(); let wkb = geom - .to_gpkg_wkb( - CoordDimensions::default(), - Some(4326), - vec![1.1, 1.1, 1.1, 1.1], - ) + .to_gpkg_wkb(DIM_XY, Some(4326), vec![1.1, 1.1, 1.1, 1.1]) .unwrap(); assert_eq!( &wkb, @@ -586,11 +584,7 @@ mod test { let geom: geo_types::Geometry = geo_types::Point::new(1.1, 1.1).into(); let wkb = geom - .to_spatialite_wkb( - CoordDimensions::default(), - Some(4326), - vec![1.1, 1.1, 1.1, 1.1], - ) + .to_spatialite_wkb(DIM_XY, Some(4326), vec![1.1, 1.1, 1.1, 1.1]) .unwrap(); assert_eq!( &wkb,