1

I'm trying to use GEOJSON files to visualise some data in Python using GeoPandas (GDAL, fiona, shapely, numpy, matplotlib are all installed). I'm having success in loading some files but not others; those that can be read appear to be pointers whilst lines and polygons cannot (this is based on the names of the files).

On using geopandas.read_file I get the below error:

Traceback (most recent call last):

  File "C:/......../PycharmProjects/Mapping/Mapping Code.py", line 41, in <module>
    gambia_map = gpd.read_file(

  File "C:\Python3.8\lib\site-packages\geopandas\io\file.py", line 127, in read_file
    gdf = GeoDataFrame.from_features(f_filt, crs=crs, columns=columns)

  File "C:\Python3.8\lib\site-packages\geopandas\geodataframe.py", line 300, in from_features
    d = {"geometry": shape(f["geometry"]) if f["geometry"] else None}

  File "C:\Python3.8\lib\site-packages\shapely\geometry\geo.py", line 44, in shape
    return MultiPolygon(ob["coordinates"], context_type='geojson')

  File "C:\Python3.8\lib\site-packages\shapely\geometry\multipolygon.py", line 64, in __init__
    self._geom, self._ndim = geos_multipolygon_from_py(polygons)

  File "C:\Python3.8\lib\site-packages\shapely\geometry\multipolygon.py", line 143, in geos_multipolygon_from_py
    geom, ndims = polygon.geos_polygon_from_py(ob[l][0], ob[l][1:])

  File "C:\Python3.8\lib\site-packages\shapely\geometry\polygon.py", line 509, in geos_polygon_from_py
    ret = geos_linearring_from_py(shell)

  File "shapely\speedups\_speedups.pyx", line 401, in shapely.speedups._speedups.geos_linearring_from_py

ValueError: GEOSGeom_createLinearRing_r returned a NULL pointer

Process finished with exit code 1```

2 Answers 2

1

Are you importing any other packages before geopandas, such as rasterio or contextily? If so, try importing geopandas before anything else. That's a quick fix that worked for me when I was getting the same error. However, it might break other features, so I don't recommend leaving it like that.

To fix the deeper problem, this is the process I used:

  1. Run pip uninstall shapely
  2. Go here and download the appropriate wheel for shapely
  3. Run pip install C://Users//username//Shapely-1.7.0-cp38-cp38-win_amd64.whl, substituting the appropriate location and file name.
  4. You should be able to import packages in any order now without causing errors. If you're still having issues, I'd try repeating these steps for all of the related packages and dependencies.

You can also take a look here, where a related issue and solution are discussed.

1

I have been getting the same error and found the solution here.

Accordingly, I just added this at the start of the script.

from shapely import speedups
speedups.disable()

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.