Fix geometry collection parsing

This commit is contained in:
Tobie Morgan Hitchcock 2022-02-11 01:57:52 +00:00
parent c3579b98a4
commit 556a3db60e

View file

@ -342,7 +342,7 @@ impl Serialize for Geometry {
let mut map = s.serialize_map(Some(2))?; let mut map = s.serialize_map(Some(2))?;
map.serialize_key("type")?; map.serialize_key("type")?;
map.serialize_value("GeometryCollection")?; map.serialize_value("GeometryCollection")?;
map.serialize_key("coordinates")?; map.serialize_key("geometries")?;
map.serialize_value(v)?; map.serialize_value(v)?;
map.end() map.end()
} }
@ -521,11 +521,11 @@ fn collection(i: &str) -> IResult<&str, Geometry> {
|i| { |i| {
let (i, _) = preceded(key_type, collection_type)(i)?; let (i, _) = preceded(key_type, collection_type)(i)?;
let (i, _) = delimited(mightbespace, tag(","), mightbespace)(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)) Ok((i, v))
}, },
|i| { |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, _) = delimited(mightbespace, tag(","), mightbespace)(i)?;
let (i, _) = preceded(key_type, collection_type)(i)?; let (i, _) = preceded(key_type, collection_type)(i)?;
Ok((i, v)) Ok((i, v))
@ -712,6 +712,18 @@ fn key_vals(i: &str) -> IResult<&str, &str> {
Ok((i, v)) 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)] #[cfg(test)]
mod tests { mod tests {