Skip to content

chore: Handle unsupported geometries (e.g. point empty) in GeoExecutor #473

@petern48

Description

@petern48

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,
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions