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
Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Sep 18, 2020 at 20:42
1
  • Try to update numpy. i don't know if it helps. Commented 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)])
answered May 17, 2022 at 17:12

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.