Parse a WKT string into a Geometry. Returns `None` if the input is malformed.
(input: &str)
| 69 | /// |
| 70 | /// Returns `None` if the input is malformed. |
| 71 | pub fn geometry_from_wkt(input: &str) -> Option<Geometry> { |
| 72 | let s = input.trim(); |
| 73 | if let Some(rest) = strip_prefix_ci(s, "GEOMETRYCOLLECTION") { |
| 74 | parse_geometry_collection(rest.trim()) |
| 75 | } else if let Some(rest) = strip_prefix_ci(s, "MULTIPOLYGON") { |
| 76 | parse_multipolygon(rest.trim()) |
| 77 | } else if let Some(rest) = strip_prefix_ci(s, "MULTILINESTRING") { |
| 78 | parse_multilinestring(rest.trim()) |
| 79 | } else if let Some(rest) = strip_prefix_ci(s, "MULTIPOINT") { |
| 80 | parse_multipoint(rest.trim()) |
| 81 | } else if let Some(rest) = strip_prefix_ci(s, "POLYGON") { |
| 82 | parse_polygon(rest.trim()) |
| 83 | } else if let Some(rest) = strip_prefix_ci(s, "LINESTRING") { |
| 84 | parse_linestring(rest.trim()) |
| 85 | } else if let Some(rest) = strip_prefix_ci(s, "POINT") { |
| 86 | parse_point(rest.trim()) |
| 87 | } else { |
| 88 | None |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | // ── Serialization helpers ── |
| 93 |