Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.14.6
hooks:
- id: ruff
- id: ruff-check
types_or: [python, pyi, jupyter]
- id: ruff-format
types_or: [python, pyi, jupyter]
11 changes: 10 additions & 1 deletion src/antimeridian/_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,19 @@ def fix_polygon(
if shapely.is_ccw(polygon.exterior):
return polygon
else:
return Polygon(
pole_covering_polygon = Polygon(
[(-180, 90), (-180, -90), (180, -90), (180, 90)],
[polygon.exterior.coords],
)
if shapely.is_valid(pole_covering_polygon):
return pole_covering_polygon
else:
raise ValueError(
"Fixed polygon is invalid, check your input polygon for validity. "
"Reason your polygon is invalid: "
+ shapely.is_valid_reason(polygon)
)

else:
return MultiPolygon(polygons)

Expand Down
28 changes: 28 additions & 0 deletions tests/data/input/issues-182.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"coordinates": [
[
[41.701686, 27.555683],
[41.677091, 27.556499],
[41.701686, 27.555683],
[41.701676, 27.552681],
[41.694555, 27.537487],
[41.69456, 27.536652],
[41.684332, 27.538833],
[41.683195, 27.539543],
[41.674979, 27.541187],
[41.672853, 27.540324],
[41.671549, 27.538989],
[41.671067, 27.537625],
[41.665152, 27.538274],
[41.664217, 27.538102],
[41.661835, 27.538401],
[41.66299, 27.541284],
[41.667426, 27.54781],
[41.67182, 27.554058],
[41.674274, 27.555888],
[41.677091, 27.556499],
[41.701686, 27.555683]
]
],
"type": "Polygon"
}
11 changes: 9 additions & 2 deletions tests/test_polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
"complex-split",
"crossing-latitude",
"extra-crossing",
"issues-81",
"issues-171",
"issues-187",
"issues-81",
"latitude-band",
"north-pole",
"one-hole",
Expand All @@ -30,7 +31,6 @@
"south-pole",
"split",
"two-holes",
"issues-187",
],
)
@pytest.mark.parametrize(
Expand Down Expand Up @@ -253,3 +253,10 @@ def test_great_circle(
output = read_output("great-circle", subdirectory)
fixed = antimeridian.fix_polygon(input, great_circle=great_circle)
assert fixed.normalize() == output.normalize()


def test_invalid_polygon(read_input: Reader) -> None:
input = read_input("issues-182")
with pytest.warns(FixWindingWarning):
with pytest.raises(ValueError):
antimeridian.fix_polygon(input)