scverse / scverse/spatialdata

Check validity of shapely geometries in `ShapesModel.parse()`

Open
#429 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

element: shapes ▲ needs: triage priority: low
Dominant language
Python
Stars
394
Forks
95
Avg merge
4d 3h
Merged PRs (30d)
7

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with ShapesModel.parse() and validate(), then inspect the invalid multipoly fixture in tests/conftest.py. Reproduce the failing geometry operation using polygons.geometry.intersects(bounding_box_non_axes_aligned). Done means invalid shapely geometries are rejected during ShapesModel parsing and validation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.