Skip to content

Commit

Permalink
Handle linearrings in is_closed (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
caspervdw committed Aug 23, 2021
1 parent 10f27ca commit 6e06901
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Version 0.11 (unreleased)

**Bug fixes**

* ...
* Return True instead of False for LINEARRING geometries in ``is_closed`` (#379).

**Acknowledgments**

Expand Down
23 changes: 22 additions & 1 deletion pygeos/tests/test_predicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
import pygeos
from pygeos import Geometry

from .common import all_types, empty, geometry_collection, point, polygon
from .common import (
all_types,
empty,
geometry_collection,
line_string,
linear_ring,
point,
polygon,
)

UNARY_PREDICATES = (
pygeos.is_empty,
Expand Down Expand Up @@ -104,6 +112,19 @@ def test_equals_exact_tolerance():
assert pygeos.equals_exact(p1, p2).item() is False


@pytest.mark.parametrize(
"geometry,expected",
[
(point, False),
(line_string, False),
(linear_ring, True),
(empty, False),
],
)
def test_is_closed(geometry, expected):
assert pygeos.is_closed(geometry) == expected


def test_relate():
p1 = pygeos.points(0, 0)
p2 = pygeos.points(1, 1)
Expand Down
2 changes: 1 addition & 1 deletion src/ufuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static char GEOSisClosedAllTypes_r(void* context, void* geom) {
int type = GEOSGeomTypeId_r(context, geom);
if (type == -1) {
return 2; // Predicates use a return value of 2 for errors
} else if ((type == 1) || (type == 5)) {
} else if ((type == 1) || (type == 2) || (type == 5)) {
return GEOSisClosed_r(context, geom);
} else {
return 0;
Expand Down

0 comments on commit 6e06901

Please sign in to comment.