Skip to content

Consider LinearRing as "closed"? #337

@jorisvandenbossche

Description

@jorisvandenbossche

I didn't directly find a previous discussion about this, but currently the is_closed ufunc will always return False for LinearRings:

>>> ring = pygeos.linearrings(((0, 0), (0, 1), (1 ,1 ), (1, 0)))
>>> print(ring)
LINEARRING (0 0, 0 1, 1 1, 1 0, 0 0)
>>> pygeos.is_closed(ring)
False

This is following GEOS' behaviour where GEOSisClosed only works for LineStrings and not any other geometry (and thus also not LinearRings).

However, in Shapely, a LinearRing is also considered as "closed" (by simply hardcoded always True for a LinearRing):

>>> from shapely.geometry import LinearRing
>>> ring = LinearRing( ((0, 0), (0, 1), (1 ,1 ), (1, 0)))
>>> print(ring)
LINEARRING (0 0, 0 1, 1 1, 1 0, 0 0)
>>> ring.is_closed
True

PostGIS (https://postgis.net/docs/ST_IsClosed.html) seems to return True as well. It's not directly documented, but from a quick test (creating a polygon and extracting the exterior ring, as creating the LinearRing from WKT doesn't seem to be supported):

test_db=# SELECT ST_IsClosed(ST_ExteriorRing('POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))'::geometry));
 st_isclosed 
-------------
 t
(1 row)

Although PostGIS also returns True for Polygon

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions