Fiona: Segmentation fault with simple geometry operations using Shapely and Fiona

Hi,

I am having trouble making sense of an issue I’m having using Shapely and Fiona. I keep getting segmentation faults. even when doing very simple tasks. I’ve narrowed it down to being a problem having shapely and fiona loaded at the same time, which makes either package much less useful.

I’ve included a minimal working example below. The first runs just fine with only shapely loaded. The second produces a segmentation fault running the same processes with shapely and fiona loaded.

Example 1, works:

In [1]: %paste
from shapely import geometry
shp = geometry.LinearRing([(0,0),(1,0),(0,1)])
shp.centroid.coords.xy
Out[1]: (array('d', [0.35355339059327373]), array('d', [0.35355339059327373]))

Example 2, segfault:

In [1]: %paste
import fiona
from shapely import geometry
shp = geometry.LinearRing([(0,0),(1,0),(0,1)])
shp.centroid.coords.xy
## -- End pasted text --
/Users/wiar9509/anaconda/bin/python.app: line 3:   849 Segmentation fault: 11  /Users/wiar9509/anaconda/python.app/Contents/MacOS/python "$@"

I am running this in iPython, using an Anaconda install. My Python information is: Python 2.7.12 |Anaconda custom (x86_64)| (default, Jul 2 2016, 17:43:17)

My iPython version is:

engr2-2-77-37-dhcp:~ wiar9509$ conda list ipython
# packages in environment at /Users/wiar9509/anaconda:
#
ipython                   4.2.0                    py27_1  
ipython_genutils          0.1.0                    py27_0 

Fiona version:

In [2]: fiona.__version__
Out[2]: '1.7.0'

Shapely version:

In [3]: shapely.__version__
Out[3]: '1.5.16'

Please let me know how I might be able to solve this issue. I am excited to use these packages!

Billy

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 19 (11 by maintainers)

Most upvoted comments

If you do the following, the program does not crash.

from shapely.geometry import shape
from shapely import speedups

speedups.disable()
print(shape(d["geometry"]))

I think I understand why, but I need to do a little more testing and writing.

@mje-nz @simonw I’ve made a 1.8.13.post1 release of fiona that includes GEOS 3.8.0 (see https://github.com/Toblerity/Fiona/issues/862). I’ve tested them with shapely 1.7.0 wheels and the segmentation fault does not occur.

Here are two recipes for shapely and fiona binary wheel compatibility:

With GEOS 3.8.0: pip install fiona==1.8.13.post1 shapely==1.7.0 or pip install -U fiona shapely.

With GEOS 3.6.2: pip install fiona==1.8.13 shapely==1.6.4.post2

The first is the best option.

I just wanted to follow up on this. I have the same issue when running from osgeo import ogr or from gdalconst import * above from shapely import geometry.

However, everything runs fine as long as I call from shapely import geometry above other osgeo-related imports (including fiona).

Let me know if there’s any other information I could provide to help track this problem down, but I am content with my current solution that has things working.