Skip to content

Keep polygon holes in force_2d() - #1304

Open
RClaudiuM wants to merge 1 commit into
scverse:mainfrom
RClaudiuM:fix/1234-force-2d-holes
Open

RClaudiuM wants to merge 1 commit into
scverse:mainfrom
RClaudiuM:fix/1234-force-2d-holes

Conversation

@RClaudiuM

Copy link
Copy Markdown

Fixes #1234.

force_2d() rebuilt each 3D Polygon (and each part of a MultiPolygon) from its exterior ring only, so any holes were lost and the geometry came back filled in. It now carries the interior rings over when it drops the z coordinate.

I added test_force2d_preserves_holes in tests/models/test_models.py and a line to the changelog.

Before / after (reproducer from the issue, a 10x10 square with a 2x2 hole, as a polygon and as a multipolygon):

before fix:  area before [96.0, 96.0] -> after force_2d [100.0, 100.0]
after fix:   area before [96.0, 96.0] -> after force_2d [96.0, 96.0]

Checks

  • pytest tests/models -k force2d: the new test fails on main and passes with the fix
  • pytest tests/models: 431 passed, 1 xfailed
  • ruff check / ruff format --check pass on the changed files
  • mypy reports the same result as on main

force_2d() rebuilt 3D polygons from their exterior ring only, so a polygon or
multipolygon with holes came back filled in. Carry the interior rings over
when dropping the z coordinate.
@codecov

codecov Bot commented Nov 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.43%. Comparing base (af431ef) to head (d653a01).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1304   +/-   ##
=======================================
  Coverage   91.43%   91.43%           
=======================================
  Files          53       53           
  Lines        8395     8397    +2     
=======================================
+ Hits         7676     7678    +2     
  Misses        719      719           
Files with missing lines Coverage Δ
src/spatialdata/models/_utils.py 89.07% <100.00%> (+0.12%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

spatialdata.models.force_2d() silently drops interior rings (holes) of polygons

1 participant