From 556a3db60e0bb5b0cf3b57172b4da000f480b817 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Fri, 11 Feb 2022 01:57:52 +0000 Subject: [PATCH] Fix geometry collection parsing --- src/sql/geometry.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/sql/geometry.rs b/src/sql/geometry.rs index d23a4876..1d8d0419 100644 --- a/src/sql/geometry.rs +++ b/src/sql/geometry.rs @@ -342,7 +342,7 @@ impl Serialize for Geometry { let mut map = s.serialize_map(Some(2))?; map.serialize_key("type")?; map.serialize_value("GeometryCollection")?; - map.serialize_key("coordinates")?; + map.serialize_key("geometries")?; map.serialize_value(v)?; map.end() } @@ -521,11 +521,11 @@ fn collection(i: &str) -> IResult<&str, Geometry> { |i| { let (i, _) = preceded(key_type, collection_type)(i)?; let (i, _) = delimited(mightbespace, tag(","), mightbespace)(i)?; - let (i, v) = preceded(key_vals, collection_vals)(i)?; + let (i, v) = preceded(key_geom, collection_vals)(i)?; Ok((i, v)) }, |i| { - let (i, v) = preceded(key_vals, collection_vals)(i)?; + let (i, v) = preceded(key_geom, collection_vals)(i)?; let (i, _) = delimited(mightbespace, tag(","), mightbespace)(i)?; let (i, _) = preceded(key_type, collection_type)(i)?; Ok((i, v)) @@ -712,6 +712,18 @@ fn key_vals(i: &str) -> IResult<&str, &str> { Ok((i, v)) } +fn key_geom(i: &str) -> IResult<&str, &str> { + let (i, v) = alt(( + tag("geometries"), + delimited(tag(SINGLE), tag("geometries"), tag(SINGLE)), + delimited(tag(DOUBLE), tag("geometries"), tag(DOUBLE)), + ))(i)?; + let (i, _) = mightbespace(i)?; + let (i, _) = tag(":")(i)?; + let (i, _) = mightbespace(i)?; + Ok((i, v)) +} + #[cfg(test)] mod tests {