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.
The documentation on
MultiPointsays that I can pass to it a sequence ofPoints. But it doesn't warn us against passing emptyPoints. Interestingly enough, if I pass an emptyPointas the first element, it will throw anAssertionError:But if the empty
Pointgoes after a nonemptyPoint, then it works fine:But the resulting object will throw an exception after trying to get its wkt:
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.