diff --git a/src/sql/geometry.rs b/src/sql/geometry.rs index 1d8d0419..051418c7 100644 --- a/src/sql/geometry.rs +++ b/src/sql/geometry.rs @@ -253,8 +253,110 @@ impl Geometry { impl fmt::Display for Geometry { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - Geometry::Point(v) => write!(f, "({}, {})", v.x(), v.y()), - _ => write!(f, "{}", serde_json::to_string(self).unwrap_or(String::from(""))), + Geometry::Point(v) => { + write!(f, "{{ type: 'Point', coordinates: [{}, {}] }}", v.x(), v.y()) + } + Geometry::Line(v) => write!( + f, + "{{ type: 'LineString', coordinates: [{}] }}", + v.points_iter() + .map(|ref v| format!("[{}, {}]", v.x(), v.y())) + .collect::>() + .join(", ") + ), + Geometry::Polygon(v) => write!( + f, + "{{ type: 'Polygon', coordinates: [[{}]{}] }}", + v.exterior() + .points_iter() + .map(|ref v| format!("[{}, {}]", v.x(), v.y())) + .collect::>() + .join(", "), + match v.interiors().len() { + 0 => format!(""), + _ => format!( + ", [{}]", + v.interiors() + .iter() + .map(|i| { + format!( + "[{}]", + i.points_iter() + .map(|ref v| format!("[{}, {}]", v.x(), v.y())) + .collect::>() + .join(", ") + ) + }) + .collect::>() + .join(", "), + ), + } + ), + Geometry::MultiPoint(v) => { + write!( + f, + "{{ type: 'MultiPoint', coordinates: [{}] }}", + v.iter() + .map(|v| format!("[{}, {}]", v.x(), v.y())) + .collect::>() + .join(", ") + ) + } + Geometry::MultiLine(v) => write!( + f, + "{{ type: 'MultiLineString', coordinates: [{}] }}", + v.iter() + .map(|v| format!( + "[{}]", + v.points_iter() + .map(|ref v| format!("[{}, {}]", v.x(), v.y())) + .collect::>() + .join(", ") + )) + .collect::>() + .join(", ") + ), + Geometry::MultiPolygon(v) => write!( + f, + "{{ type: 'MultiPolygon', coordinates: [{}] }}", + v.iter() + .map(|v| format!( + "[[{}]{}]", + v.exterior() + .points_iter() + .map(|ref v| format!("[{}, {}]", v.x(), v.y())) + .collect::>() + .join(", "), + match v.interiors().len() { + 0 => format!(""), + _ => format!( + ", [{}]", + v.interiors() + .iter() + .map(|i| { + format!( + "[{}]", + i.points_iter() + .map(|ref v| format!("[{}, {}]", v.x(), v.y())) + .collect::>() + .join(", ") + ) + }) + .collect::>() + .join(", "), + ), + } + )) + .collect::>() + .join(", "), + ), + Geometry::Collection(v) => { + write!( + f, + "{{ type: 'GeometryCollection', geometries: [{}] }}", + v.iter().map(|v| format!("{}", v)).collect::>().join(", ") + ) + } } } }