1

I am creating a linestring from points using shapely, but I could not generate the linestring using the points on my local system. This code is running fine on Google Colab. Is there any package dependency which I don't have installed on my system?

import shapely
from shapely import speedups
from shapely import geometry
from shapely.geometry import shape, Point, LineString, Polygon

a = LineString([(0, 0), (1, 1), (1,2), (2,2)])
a

Error massage 
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-18-02826fee6746> in <module>
----> 1 a = LineString([(0, 0), (1, 1), (1,2), (2,2)])
      2 a

c:\python37\lib\site-packages\shapely\geometry\linestring.py in __init__(self, coordinates)
     46         BaseGeometry.__init__(self)
     47         if coordinates is not None:
---> 48             self._set_coords(coordinates)
     49 
     50     @property

c:\python37\lib\site-packages\shapely\geometry\linestring.py in _set_coords(self, coordinates)
     95     def _set_coords(self, coordinates):
     96         self.empty()
---> 97         ret = geos_linestring_from_py(coordinates)
     98         if ret is not None:
     99             self._geom, self._ndim = ret

c:\python37\lib\site-packages\shapely\speedups\_speedups.pyx in shapely.speedups._speedups.geos_linestring_from_py()

ValueError: GEOSGeom_createLineString_r returned a NULL pointer
1
  • Try to update numpy. i don't know if it helps.
    – menes
    Sep 21, 2020 at 14:32

1 Answer 1

0

As you can see here, the error message is an old problem, and you can fix it by changing the order of the import process like this:

import shapely
from shapely import speedups
from shapely import geometry
from shapely.geometry import shape, Point, LineString, Polygon
import fiona
    
a = LineString([(0, 0), (1, 1), (1,2), (2,2)])

Another way is to disable speedups:

import shapely
from shapely import speedups
from shapely import geometry
from shapely.geometry import shape, Point, LineString, Polygon
speedups.disable()

a = LineString([(0, 0), (1, 1), (1,2), (2,2)])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.