Skip to content

Allow creating empty geometries in constructive functions #149

@jorisvandenbossche

Description

@jorisvandenbossche

Currently, those functions like polygons etc raise an error if you try:

In [13]: pygeos.polygons(np.random.randn(3, 2))
Out[13]: <pygeos.Geometry POLYGON ((1.07 0.401, 0.386 -0.151, 0.133 0.257, 1.07 0.401))>

In [15]: pygeos.polygons(np.empty((0, 2)))  
---------------------------------------------------------------------------
GEOSException                             Traceback (most recent call last)
<ipython-input-15-301ca2e69111> in <module>
----> 1 pygeos.polygons(np.empty((0, 2)))

~/scipy/repos/pygeos/pygeos/creation.py in polygons(shells, holes)
     85     shells = np.asarray(shells)
     86     if not isinstance(shells, Geometry) and np.issubdtype(shells.dtype, np.number):
---> 87         shells = linearrings(shells)
     88 
     89     if holes is None:

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

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

GEOSException: IllegalArgumentException: point array must contain 0 or >1 elements

This is a GEOS exception, so I am not fully this can be worked around (didn't check yet). This is from the linearrings function, so we might need a custom check if we want to allow this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions