In multiple PRs implementing geo kernels (e.g. 1 and 2), we've run across the item_to_geometry() lack of support for certain geometries like point empty. The root of the problem is that geo's methods simply return None for many of those cases.
In #233 (comment), @paleolimbot proposed creating a new enum to allow the caller to access the WKB directly.
enum ItemToGeometryResult { Unsupported(Wkb), Supported(Geometry))
I thought about taking this one step further, what if we instead do something like this:
enum ItemToGeometryResult {
PointEmpty,
MultiPointEmpty, // we'd have to be extra careful here for cases like `MULTIPOINT (EMPTY, 1 0)`
Supported(Geometry),
Unsupported(Wkb), // or just continue allowing these cases to panic since these are complicated cases anyway
}
This would allow us to avoid re-parsing the Unsupported geom's bytes again to determine that it's an empty point/polygon. This should work because we know what method is returning the None inside of the following function
|
fn to_geometry(item: impl GeometryTrait<T = f64>) -> Option<Geometry> { |
|
match item.as_type() { |
|
Point(geom) => geom.try_to_point().map(Geometry::Point), |
|
LineString(geom) => Some(Geometry::LineString(geom.to_line_string())), |
|
Polygon(geom) => Some(Geometry::Polygon(geom.to_polygon())), |
|
MultiPoint(geom) => geom.try_to_multi_point().map(Geometry::MultiPoint), |
|
MultiLineString(geom) => Some(Geometry::MultiLineString(geom.to_multi_line_string())), |
|
MultiPolygon(geom) => Some(Geometry::MultiPolygon(geom.to_multi_polygon())), |
|
GeometryCollection(geom) => geometry_collection_to_geometry(geom), |
|
_ => None, |
|
} |
|
} |
In multiple PRs implementing
geokernels (e.g. 1 and 2), we've run across the item_to_geometry() lack of support for certain geometries like point empty. The root of the problem is thatgeo's methods simply returnNonefor many of those cases.In #233 (comment), @paleolimbot proposed creating a new enum to allow the caller to access the WKB directly.
I thought about taking this one step further, what if we instead do something like this:
This would allow us to avoid re-parsing the Unsupported geom's bytes again to determine that it's an empty point/polygon. This should work because we know what method is returning the
Noneinside of the following functionsedona-db/rust/sedona-geo/src/to_geo.rs
Lines 76 to 87 in e0e1d10