question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inconsistent behavior when passing empty Points to MultiPoint

See original GitHub issue

The documentation on MultiPoint says that I can pass to it a sequence of Points. But it doesn’t warn us against passing empty Points. Interestingly enough, if I pass an empty Point as the first element, it will throw an AssertionError:

>>> from shapely.geometry import Point, MultiPoint
>>> MultiPoint([Point()])
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-30-8942eaebd9a2> in <module>
----> 1 MultiPoint([Point()])

~\Miniconda3\lib\site-packages\shapely\geometry\multipoint.py in __init__(self, points)
     56             pass
     57         else:
---> 58             self._geom, self._ndim = geos_multipoint_from_py(points)
     59 
     60     def shape_factory(self, *args):

~\Miniconda3\lib\site-packages\shapely\geometry\multipoint.py in geos_multipoint_from_py(ob)
    162     except TypeError:
    163         n = ob[0]._ndim
--> 164     assert n == 2 or n == 3
    165 
    166     # Array of pointers to point geometries

AssertionError: 
>>> MultiPoint([Point(), Point(1, 2)])
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-31-08a0b83c889a> in <module>
----> 1 MultiPoint([Point(), Point(1, 2)])

~\Miniconda3\lib\site-packages\shapely\geometry\multipoint.py in __init__(self, points)
     56             pass
     57         else:
---> 58             self._geom, self._ndim = geos_multipoint_from_py(points)
     59 
     60     def shape_factory(self, *args):

~\Miniconda3\lib\site-packages\shapely\geometry\multipoint.py in geos_multipoint_from_py(ob)
    162     except TypeError:
    163         n = ob[0]._ndim
--> 164     assert n == 2 or n == 3
    165 
    166     # Array of pointers to point geometries

AssertionError: 

But if the empty Point goes after a nonempty Point, then it works fine:

>>> MultiPoint([Point(1, 2), Point()])
>>> # no error here

But the resulting object will throw an exception after trying to get its wkt:

>>> MultiPoint([Point(1, 2), Point()]).wkt
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-38-c645b8b312e6> in <module>
----> 1 MultiPoint([Point(1, 2), Point()]).wkt

~\Miniconda3\lib\site-packages\shapely\geometry\base.py in wkt(self, **kw)
    365     def wkt(self, **kw):
    366         """WKT representation of the geometry"""
--> 367         return WKTWriter(lgeos, **kw).write(self)
    368 
    369     @property

~\Miniconda3\lib\site-packages\shapely\geos.py in write(self, geom)
    361         if geom is None or geom._geom is None:
    362             raise ValueError("Null geometry supports no operations")
--> 363         result = self._lgeos.GEOSWKTWriter_write(self._writer, geom._geom)
    364         text = string_at(result)
    365         lgeos.GEOSFree(result)

OSError: exception: access violation reading 0x0000000000000000

I assume there needs to be a guard against a presence of empty points in the passed sequence, and the docs should be updated too.


Shapely version: 1.6.4.post1, installed from conda.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
sgilliescommented, Apr 22, 2020

I’d like to avoid too much validation, because it’s expensive, but in this case I think filtering out empty parts and warning that this has been done is a good approach. Warn instead of log, because user code could handle the warning and change its behavior if desired.

1reaction
jorisvandenbosschecommented, Apr 20, 2020

I reported it in the meantime: https://github.com/libgeos/geos/issues/305

I still think it warrants some preventative action from Shapely, though.

For sure! The question might be if Shapely should raise an error upon creation, or when converting to WKT.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inconsistent behavior when passing empty Points to MultiPoint
The documentation on MultiPoint says that I can pass to it a sequence of Points. But it doesn't warn us against passing empty...
Read more >
#3031 ("POINT EMPTY" as WKB defaults to "MULTIPOINT ...
To demonstrate the problem behaviour: SELECT ST_GeomFromText('POINT EMPTY') —> producess '010400000000000000'. SELECT ST_GeomFromText('MULTIPOINT EMPTY') ...
Read more >
Shapely Documentation - Read the Docs
POLYGON EMPTY. Shapely 1.8 does not yet change this inconsistent behaviour, but starting with Shapely 2.0, the different methods will.
Read more >
Rat sensitivity to multipoint statistics is predicted by efficient ...
Here we selected four image statistics (from single- to four-point correlations) and trained four groups of rats to discriminate between white noise ......
Read more >
RPL: IPv6 Routing Protocol for Low-Power and Lossy Networks
A RPL node often combines host and router behaviors. ... Point-to-Multipoint Traffic Point-to-multipoint (P2MP) is a traffic pattern required by several LLN ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found