spatialdata
spatialdata copied to clipboard
Check validity of shapely geometries in `ShapesModel.parse()`
In tests/conftest.py the second multipolygon of the multipoly object is invalid, i.e.
multipoly = GeoDataFrame(
{
"geometry": [
MultiPolygon(
[
Polygon(((0, 0), (0, 1), (1, 1), (1, 0))),
Polygon(((0, 0), (0, -1), (-1, -1), (-1, 0))),
]
),
MultiPolygon(
[
Polygon(((0, 0), (0, 1), (1, 10))),
Polygon(((0, 0), (0, 1), (1, 1))),
Polygon(((0, 0), (0, 1), (1, 1), (1, 0), (1, 0))),
]
),
]
}
leads to multipoly.is_valid having False at the second entry.
This may cause subtle problems when operating on those objects; for instance this query fails:
indices = polygons.geometry.intersects(bounding_box_non_axes_aligned)
A solution is to prevent such geometries to pass the validation step when invoking parse() and validate() in ShapesModel.