Skip to content

BUG: cannot create linearring from 3 coordinate pairs if they are equal #213

@jorisvandenbossche

Description

@jorisvandenbossche

It's certainly a corner case, but this seems a bit inconsistent (ran into this in a Shapely test, where this is currently working):

In general, creating a LinearRing from 3 coordinate pairs works, and the first one is repeated as 4th pair ("ring_closure"):

In [5]: import pygeos

In [6]: pygeos.linearrings([(0, 0), (0, 1), (1, 1)])
Out[6]: <shapely.geometry.LinearRing LINEARRING (0 0, 0 1, 1 1, 0 0) >

But, when the three coordinate pairs are equal, this doesn't happen:

In [7]: pygeos.linearrings([(0, 0), (0, 0), (0, 0)])
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-7-76cb9a3993ed> in <module>
----> 1 pygeos.linearrings([(0, 0), (0, 0), (0, 0)])

~/scipy/repos/pygeos/pygeos/creation.py in linearrings(coords, y, z)
     70     z : array_like
     71     """
---> 72     return _wrap_construct_ufunc(lib.linearrings, coords, y, z)
     73 
     74 @multithreading_enabled

~/scipy/repos/pygeos/pygeos/creation.py in _wrap_construct_ufunc(func, coords, y, z)
     19 def _wrap_construct_ufunc(func, coords, y=None, z=None):
     20     if y is None:
---> 21         return func(coords)
     22     x = coords
     23     if z is None:

ValueError: Provide at least 4 coordinates to create a linearring.

However, creating such LinearRing manually actually works:

In [8]: pygeos.linearrings([(0, 0), (0, 0), (0, 0), (0, 0)])
Out[8]: <shapely.geometry.LinearRing LINEARRING (0 0, 0 0, 0 0, 0 0) >

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions