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

Created on 19 Sep 2016  路  19Comments  路  Source: Toblerity/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

packaging

Most helpful comment

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.

All 19 comments

How did you install Shapely and Fiona?

@snorfalorpagus I believe I used conda install.

The modules are located within my Anaconda library folder:

In [2]: shapely.__file__
Out[2]: '/Users/wiar9509/anaconda/lib/python2.7/site-packages/shapely/__init__.pyc'
In [4]: fiona.__file__
Out[4]: '/Users/wiar9509/anaconda/lib/python2.7/site-packages/fiona/__init__.pyc'

Thanks for your help!

@snorfalorpagus I finally came across this issue (which you also addressed): https://github.com/Toblerity/Shapely/issues/353, which inspired me to check the order in which I'm importing packages. This order makes all the difference.

Import shapely first, works fine:

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

Import fiona first, 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:  1093 Segmentation fault: 11  /Users/wiar9509/anaconda/python.app/Contents/MacOS/python "$@"

I'm not sure why this would be, but at least I can get it to work for now..

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.

@armstrwa I can't reproduce the problem on my macbook.

The script

import fiona
from shapely import geometry

shp = geometry.LinearRing([(0,0),(1,0),(0,1)])
print(shp.centroid.coords.xy)

works no matter the order of the first two lines.

Note that I am not using conda and have installed Fiona and Shapely into a virtual environment using pip:

$ pip install --no-binary shapely shapely==1.5.16
$ pip install --no-binary fiona

The --no-binary option tells pip to skip the binaries wheels I uploaded to PyPI and compile the extension modules from a source distribution, linking to the GEOS library on my system. This simulates what happens when a conda build is performed.

Since I can't duplicate it, there's a chance this is a conda-specific bug. @ocefpaf @phobson can you reproduce the problem?

More data points here:

$ otool -L ~/envs/geos-one/lib/python2.7/site-packages/shapely/speedups/_speedups.so
/Users/sean/envs/geos-one/lib/python2.7/site-packages/shapely/speedups/_speedups.so:
        /usr/local/lib/libgeos_c.1.dylib (compatibility version 10.0.0, current version 10.2.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)

Shapely is a bit of a monstrosity in that it links libgeos_c via the compiler/linker as well as the ctypes FFI but as long as it's the same library there should be no problem.

>>> import shapely.geos
>>> shapely.geos.lgeos._lgeos
<CDLL '/usr/local/lib/libgeos_c.dylib', handle 10052f750 at 102051610>

This is the same lib linked by _speedups.so:

$ ls -l /usr/local/lib/libgeos_c.*
-rwxr-xr-x  1 sean  admin   208056 Jan 28  2016 /usr/local/lib/libgeos_c.1.dylib
-rw-r--r--  1 sean  admin  1732536 Jan 28  2016 /usr/local/lib/libgeos_c.a
lrwxr-xr-x  1 sean  admin       17 Jan 28  2016 /usr/local/lib/libgeos_c.dylib -> libgeos_c.1.dylib
-rwxr-xr-x  1 sean  admin      967 Jan 28  2016 /usr/local/lib/libgeos_c.la

Fiona links libgdal.1

$ otool -L ~/envs/geos-one/lib/python2.7/site-packages/fiona/ogrext.so
/Users/sean/envs/geos-one/lib/python2.7/site-packages/fiona/ogrext.so:
        /usr/local/lib/libgdal.1.dylib (compatibility version 20.0.0, current version 20.1.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)

and that links the same libgeos_c.1 as Shapely does:

$ otool -L /usr/local/lib/libgdal.1.dylib
/usr/local/lib/libgdal.1.dylib:
        /usr/local/lib/libgdal.1.dylib (compatibility version 20.0.0, current version 20.1.0)
        /usr/local/lib/libproj.0.dylib (compatibility version 8.0.0, current version 8.0.0)
        /usr/local/lib/libjson-c.2.dylib (compatibility version 3.0.0, current version 3.1.0)
        /usr/local/lib/libgeos_c.1.dylib (compatibility version 10.0.0, current version 10.2.0)
        /usr/local/lib/libgeos-3.4.2.dylib (compatibility version 0.0.0, current version 0.0.0)
        /usr/lib/libsqlite3.dylib (compatibility version 9.0.0, current version 158.0.0)
        /usr/lib/libexpat.1.dylib (compatibility version 7.0.0, current version 7.2.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
        /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
        /usr/lib/libcurl.4.dylib (compatibility version 7.0.0, current version 8.0.0)
        /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
        /usr/lib/libxml2.2.dylib (compatibility version 10.0.0, current version 10.9.0)
        /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 60.0.0)

I'm not able to do this kind of debugging in a conda environment right now, but I think it would be worth a check to see if Shapely and Fiona are linking the same GEOS lib with conda.

hey @sgillies and @armstrwa -- both scripts work for me on my Windows machine with python 3.4, shapely, fiona, etc coming from @conda-forge. In other words:

conda create --name=gis python=3.4 fiona --channel=conda-forge --yes
source activate gis
# yada yada

@phobson thanks for checking!

@armstrwa did you get shapely and fiona from the conda-forge channel as @phobson shows above? That's the only reliable conda channel for these packages.

@sgillies I can still reproduce this on macOS 10.13.6 with Python 3.7.6 (from Homebrew), Fiona 1.8.13 (from pip) and Shapely 1.7.0 (from pip). Installing Shapely from source still fixes it (pip3 uninstall -y shapely && pip3 install --no-binary :all: shapely). I'm under the impression from the GeoPandas docs that the macOS wheels for Fiona and Shapely are supposed to work together now, is that not the case?

@mje-nz can you provide a small program that will reproduce the problem?

I just ran into this problem on OS X too. I'm using Python 3.7.5 installed via homebrew, and I installed both Fiona and Shapely in a virtual environment created with pipenv.

$ python crashme.py 
Segmentation fault: 11

Here's the content of crashme.py:

import fiona

d = {
    "type": "Feature",
    "id": "0",
    "properties": {
        "ADMINFORES": "99081600010343",
        "REGION": "08",
        "FORESTNUMB": "16",
        "FORESTORGC": "0816",
        "FORESTNAME": "El Yunque National Forest",
        "GIS_ACRES": 55829.81,
        "SHAPE_AREA": 0.0193062316937,
        "SHAPE_LEN": 0.754287568301,
    },
    "geometry": {
        "type": "MultiPolygon",
        "coordinates": [
            [
                [
                    [-65.73293016000002, 18.33284838999998],
                    [-65.73293445000002, 18.331367639999996],
                    [-65.73189660000003, 18.331369719999998],
                    [-65.73040952000002, 18.33137273],
                    [-65.72620770999998, 18.33138113000001],
                    [-65.72303074000001, 18.331387389999975],
                    [-65.71763471000003, 18.331393549999973],
                    [-65.71717587, 18.331394069999988],
                    [-65.71297922999997, 18.331403290000026],
                    [-65.71248787000002, 18.33140437999998],
                    [-65.70898332000002, 18.33141236],
                    [-65.70846269999998, 18.331413540000028],
                    [-65.70470655999998, 18.331422009999983],
                    [-65.70340513999997, 18.33142491000001],
                    [-65.70268779000003, 18.331419400000016],
                    [-65.70098910000002, 18.33140635000001],
                    [-65.69978839999999, 18.33139711000001],
                    [-65.69977925, 18.32948927000001],
                    [-65.69976860000003, 18.32723274],
                    [-65.69976336000002, 18.326155840000013],
                    [-65.69975882, 18.32519180999998],
                    [-65.69975420999998, 18.324281380000002],
                    [-65.69975116, 18.323670390000018],
                    [-65.69974878, 18.323214399999983],
                    [-65.69972460999998, 18.317907339999977],
                    [-65.69972661000003, 18.31559458999999],
                    [-65.69972832000002, 18.314692869999988],
                    [-65.69972934999998, 18.312400700000012],
                    [-65.69973214999999, 18.309193600000015],
                    [-65.69973189000001, 18.308128119999992],
                    [-65.69971594999998, 18.304170699999986],
                    [-65.69971009, 18.302713270000027],
                    [-65.69969680999998, 18.29942688],
                    [-65.69968705999997, 18.297028839999996],
                    [-65.69968439000002, 18.294420890000026],
                    [-65.69968401, 18.294158770000024],
                    [-65.69968397000002, 18.29406161000003],
                    [-65.69968146999997, 18.29031968999999],
                    [-65.69967542, 18.286261500000023],
                    [-65.6996757, 18.286123120000013],
                    [-65.69967338999999, 18.284205750000012],
                    [-65.69967251000003, 18.283497660000023],
                    [-65.69967014000002, 18.281735219999973],
                    [-65.69967000000003, 18.28134633000002],
                    [-65.69994827, 18.28134559],
                    [-65.70099542999998, 18.28134276999998],
                    [-65.70358926, 18.28133575999999],
                    [-65.70616948000003, 18.281328770000016],
                    [-65.70911901, 18.28132070999999],
                    [-65.70971071999998, 18.28131909000001],
                    [-65.71624101999998, 18.28131652000002],
                    [-65.71624542, 18.276418089999993],
                    [-65.71624548, 18.27636744],
                    [-65.71624578000001, 18.275968209999974],
                    [-65.71624845000002, 18.27300660999998],
                    [-65.71624307000002, 18.271180739999977],
                    [-65.71623899999997, 18.26979332000002],
                    [-65.71623254999997, 18.267581380000024],
                    [-65.71623254999997, 18.267578500000013],
                    [-65.71623402, 18.267040029999976],
                    [-65.71623762000002, 18.265657929999975],
                    [-65.71623955000001, 18.26496930000002],
                    [-65.71624981999997, 18.260115170000006],
                    [-65.71625891999997, 18.257678180000028],
                    [-65.71625689000001, 18.25766888999999],
                    [-65.71628033000002, 18.252014929999973],
                    [-65.71628700000002, 18.250603020000028],
                    [-65.71629617000002, 18.248364939999988],
                    [-65.71629643, 18.248011659999975],
                    [-65.71974196999997, 18.248007089999987],
                    [-65.72038055000002, 18.24800706000002],
                    [-65.72076942000001, 18.24800829999998],
                    [-65.72464429000001, 18.248011910000002],
                    [-65.72465315, 18.248011519999977],
                    [-65.72509256000001, 18.24801222000002],
                    [-65.72707300000002, 18.24801083],
                    [-65.73231042999998, 18.2480104],
                    [-65.73397174000002, 18.248009190000005],
                    [-65.73705114, 18.248008589999984],
                    [-65.73750502000001, 18.248008190000007],
                    [-65.73889711999999, 18.24800842000002],
                    [-65.73978022, 18.248008830000003],
                    [-65.74408667, 18.248010669999985],
                    [-65.74502591999999, 18.248009980000006],
                    [-65.74623288999999, 18.248009120000006],
                    [-65.74772324000003, 18.248009149999973],
                    [-65.74924592000002, 18.248014580000017],
                    [-65.74961603999998, 18.248013990000004],
                    [-65.74961524000003, 18.244120570000007],
                    [-65.74961268999999, 18.243257019999987],
                    [-65.74961502999997, 18.235669789999974],
                    [-65.74961267999998, 18.235211540000023],
                    [-65.74961048, 18.234789499999977],
                    [-65.74961128000001, 18.231243000000006],
                    [-65.75090724, 18.231235679999998],
                    [-65.75247086000002, 18.231236500000023],
                    [-65.75309636999998, 18.231236850000016],
                    [-65.75896512000003, 18.231239829999993],
                    [-65.76053288000003, 18.231240590000027],
                    [-65.76145975999998, 18.231241049999994],
                    [-65.76266423999999, 18.23124161999999],
                    [-65.76402088999998, 18.231242259999988],
                    [-65.76422652999997, 18.231242339999994],
                    [-65.76459129, 18.231242520000023],
                    [-65.76506522, 18.231243529999972],
                    [-65.76575971, 18.231245],
                    [-65.77265518000002, 18.231259480000006],
                    [-65.77609515, 18.23126751000001],
                    [-65.77853763000002, 18.231273129999977],
                    [-65.78301661, 18.231283440000027],
                    [-65.78536026, 18.231288749999976],
                    [-65.78565572000002, 18.231289430000004],
                    [-65.78587555000001, 18.23129019999999],
                    [-65.78745778000001, 18.23129352000001],
                    [-65.79147775000001, 18.231303949999983],
                    [-65.80175496999999, 18.23133021000001],
                    [-65.80328739999999, 18.23133408000001],
                    [-65.80925552999997, 18.23135074999999],
                    [-65.81185003000002, 18.231357919999994],
                    [-65.81302187, 18.231352949999973],
                    [-65.81574820999998, 18.23134140000002],
                    [-65.81705820000002, 18.231335829999978],
                    [-65.81733358000002, 18.231334670000024],
                    [-65.82028713, 18.231322050000017],
                    [-65.82052381, 18.23132104000001],
                    [-65.82337763999999, 18.23130882999999],
                    [-65.82649563000001, 18.231295439999997],
                    [-65.82811142999998, 18.231288459999973],
                    [-65.83293057999998, 18.23127384999998],
                    [-65.83292964999998, 18.231761140000003],
                    [-65.83293025, 18.234220730000004],
                    [-65.83292996, 18.23624890000002],
                    [-65.83292955000002, 18.239821380000024],
                    [-65.83292905000002, 18.244286690000024],
                    [-65.83292845, 18.244807849999972],
                    [-65.83292886999999, 18.245117160000007],
                    [-65.83292883000001, 18.24573097000001],
                    [-65.83292870999998, 18.247063589999982],
                    [-65.83292857999999, 18.248008060000018],
                    [-65.83315374, 18.248008760000005],
                    [-65.83325909000001, 18.248009089999982],
                    [-65.83590992, 18.248030509999978],
                    [-65.84442614, 18.248036909999996],
                    [-65.84617400000002, 18.248038199999996],
                    [-65.84807433999998, 18.24803958000001],
                    [-65.84813063000001, 18.248039609999978],
                    [-65.84903366999998, 18.248040240000023],
                    [-65.85197088000001, 18.24804229],
                    [-65.85535651999999, 18.24804193],
                    [-65.85613706999999, 18.248041839999985],
                    [-65.85719701, 18.248041699999987],
                    [-65.8638446, 18.24804075999998],
                    [-65.86544515000003, 18.24804051000001],
                    [-65.87069150999997, 18.248039570000003],
                    [-65.87385301, 18.248038310000027],
                    [-65.87461352999998, 18.248020329999974],
                    [-65.87817146999998, 18.248007959999995],
                    [-65.88441703000001, 18.24800984000001],
                    [-65.89088908999997, 18.248012580000022],
                    [-65.89899125, 18.248013500000013],
                    [-65.89925985999997, 18.24801395999998],
                    [-65.90513017, 18.248014790000013],
                    [-65.90874113000001, 18.248012710000012],
                    [-65.91595359000002, 18.248011819999988],
                    [-65.91629429, 18.248011819999988],
                    [-65.9162887, 18.250010359999976],
                    [-65.9162852, 18.25164811000002],
                    [-65.91628292000001, 18.25191947000002],
                    [-65.91627997, 18.253774229999976],
                    [-65.91627848000002, 18.25477933000002],
                    [-65.91627578999999, 18.255991100000017],
                    [-65.91626445999998, 18.261137089999977],
                    [-65.91625448000002, 18.26512563],
                    [-65.91625524, 18.26536785000002],
                    [-65.91625922999998, 18.266019389999997],
                    [-65.91632637999999, 18.266198929999973],
                    [-65.91632625, 18.266542049999998],
                    [-65.91631202000002, 18.267959780000012],
                    [-65.91631167000003, 18.267977850000022],
                    [-65.91630744000003, 18.268755800000008],
                    [-65.91630715999997, 18.268808560000025],
                    [-65.91625932, 18.270663520000028],
                    [-65.91625911, 18.270671989999983],
                    [-65.91625876, 18.270887870000024],
                    [-65.91625875, 18.27455298000001],
                    [-65.91625871999997, 18.274613149999993],
                    [-65.91625811, 18.279979179999998],
                    [-65.91626000000002, 18.280340190000004],
                    [-65.91625800000003, 18.281121770000027],
                    [-65.91625804, 18.281356930000015],
                    [-65.91618933000001, 18.281356570000014],
                    [-65.91500064000002, 18.281350369999984],
                    [-65.91296770999998, 18.281339800000012],
                    [-65.91253340999998, 18.281337529999973],
                    [-65.91229578999997, 18.281336280000005],
                    [-65.90998387000002, 18.281324219999988],
                    [-65.90871597, 18.281318759999976],
                    [-65.90216367, 18.28129032999999],
                    [-65.90111256, 18.281285760000003],
                    [-65.89913740999998, 18.28127711000002],
                    [-65.89885119000002, 18.28127286],
                    [-65.89237293000002, 18.281247450000023],
                    [-65.89048616000002, 18.281239140000025],
                    [-65.88711766, 18.28122424999998],
                    [-65.88599235999999, 18.281219249999992],
                    [-65.88291291000002, 18.28120555999999],
                    [-65.88291178999998, 18.28584490999998],
                    [-65.88291048999997, 18.291010749999998],
                    [-65.88290905000002, 18.29165870999998],
                    [-65.88291565999998, 18.302684020000015],
                    [-65.88291612, 18.303763930000002],
                    [-65.88291874999999, 18.31314200999998],
                    [-65.88292098, 18.314737100000002],
                    [-65.88292178, 18.316319510000028],
                    [-65.88292336, 18.320099939999977],
                    [-65.88292583999998, 18.325711160000026],
                    [-65.88292658, 18.32707603],
                    [-65.88292819999998, 18.330798640000012],
                    [-65.88292837, 18.331260059999977],
                    [-65.88087401000001, 18.331255440000007],
                    [-65.87894735999998, 18.331251090000023],
                    [-65.87603802000001, 18.33124448000001],
                    [-65.87461601000001, 18.33124122999999],
                    [-65.86804993999999, 18.331420340000022],
                    [-65.86763531000003, 18.331420009999988],
                    [-65.86672666999999, 18.33141931],
                    [-65.86648867999997, 18.331419100000005],
                    [-65.86635653000002, 18.331419170000004],
                    [-65.86273363999999, 18.331421009999985],
                    [-65.85793086000001, 18.331423389999998],
                    [-65.85789242999999, 18.33142171999998],
                    [-65.85542400000003, 18.331424019999986],
                    [-65.85350249999999, 18.331425749999994],
                    [-65.84982063000001, 18.33142908000002],
                    [-65.84969439000002, 18.331429189999994],
                    [-65.84969428, 18.331550279999988],
                    [-65.84969804000002, 18.33796344000001],
                    [-65.84969840999997, 18.338737999999978],
                    [-65.8497021, 18.345083629999976],
                    [-65.84970268000001, 18.346151969999994],
                    [-65.84970370000002, 18.34806388999999],
                    [-65.84281220000003, 18.348051429999998],
                    [-65.83631126, 18.348039400000005],
                    [-65.83572038, 18.348038309999993],
                    [-65.82972193, 18.348027020000018],
                    [-65.82915395999999, 18.348025940000014],
                    [-65.82799924, 18.34802375999999],
                    [-65.82479099, 18.34801637999999],
                    [-65.82399432, 18.34801453],
                    [-65.82321229000001, 18.348012719999986],
                    [-65.82141923, 18.348008540000023],
                    [-65.82131368, 18.34800831000001],
                    [-65.81955477000002, 18.348004189999983],
                    [-65.81593006999998, 18.347995690000005],
                    [-65.81524768000003, 18.347994099999994],
                    [-65.81430688, 18.347991850000028],
                    [-65.81409592, 18.34799134000002],
                    [-65.81219464999998, 18.347986839999976],
                    [-65.81037927, 18.347982520000016],
                    [-65.80875237999999, 18.347978650000016],
                    [-65.80848982999998, 18.34797801000002],
                    [-65.80829098999999, 18.347977609999987],
                    [-65.80772302000003, 18.347976930000016],
                    [-65.80733909999998, 18.34797567999999],
                    [-65.80353065000003, 18.347967859999983],
                    [-65.80071562, 18.347962040000027],
                    [-65.79902959999998, 18.34795853999998],
                    [-65.79798546, 18.34795637000002],
                    [-65.79009180999998, 18.347941110000022],
                    [-65.78932427000001, 18.347939639999993],
                    [-65.78840032, 18.347937820000027],
                    [-65.78753816, 18.347936129999994],
                    [-65.78601164000003, 18.347933119999993],
                    [-65.78038322999998, 18.347921919999976],
                    [-65.77934201, 18.347919479999973],
                    [-65.77871169000002, 18.347918520000007],
                    [-65.77776547000002, 18.347916520000012],
                    [-65.77676473999998, 18.347914670000023],
                    [-65.77662666999998, 18.347914370000012],
                    [-65.77532722000001, 18.347911739999972],
                    [-65.77499889, 18.347911039999985],
                    [-65.77385053, 18.347908700000005],
                    [-65.77354066999999, 18.34790806000001],
                    [-65.76955748, 18.347899840000025],
                    [-65.76888499, 18.347898439999994],
                    [-65.76835487, 18.347897349999982],
                    [-65.76683013000002, 18.34789416000001],
                    [-65.76222604999998, 18.347884490000013],
                    [-65.75909141, 18.347877840000024],
                    [-65.75869390000003, 18.347874339999976],
                    [-65.75078702000002, 18.34780397999998],
                    [-65.74961532999998, 18.347793539999998],
                    [-65.74804139999998, 18.347743690000016],
                    [-65.74783091, 18.347737010000003],
                    [-65.74728348000002, 18.347736259999976],
                    [-65.74297489999998, 18.347730169999977],
                    [-65.74044021999998, 18.347710549999988],
                    [-65.73974084000002, 18.347705140000016],
                    [-65.73561567000002, 18.34767314999999],
                    [-65.73484725999998, 18.347665380000024],
                    [-65.73302854000002, 18.347646950000012],
                    [-65.73294028999999, 18.347646069999996],
                    [-65.73293561999998, 18.346632310000018],
                    [-65.73292482, 18.344269059999988],
                    [-65.73292071999998, 18.343373789999987],
                    [-65.73291719000002, 18.34259155000001],
                    [-65.73290365999998, 18.339655180000022],
                    [-65.73291784000003, 18.337885169999993],
                    [-65.73292518, 18.334980180000002],
                    [-65.73292579000002, 18.334753429999978],
                    [-65.73293016000002, 18.33284838999998],
                ]
            ],
            [
                [
                    [-66.16262245000001, 18.051031109999997],
                    [-66.16184043999999, 18.049737929999992],
                    [-66.1619091, 18.04731941],
                    [-66.16514587, 18.04502678],
                    [-66.16511536000002, 18.044198989999984],
                    [-66.16511725999999, 18.043462750000003],
                    [-66.16511725999999, 18.043279649999988],
                    [-66.16594887000002, 18.04355812],
                    [-66.16832161000002, 18.041448590000016],
                    [-66.16813087000003, 18.040346150000005],
                    [-66.16640091, 18.04031180999999],
                    [-66.16698073999999, 18.03862952999998],
                    [-66.16720580999998, 18.037527080000018],
                    [-66.16765975999999, 18.033853529999988],
                    [-66.16861915999999, 18.034097669999994],
                    [-66.16942024000002, 18.033731460000013],
                    [-66.16954613000001, 18.03507804999998],
                    [-66.16970443999998, 18.036489490000008],
                    [-66.16989517000002, 18.037008290000017],
                    [-66.17005347999998, 18.038480760000027],
                    [-66.17072487000002, 18.03927802999999],
                    [-66.17091750999998, 18.039522169999998],
                    [-66.17117309999998, 18.039552689999994],
                    [-66.17162131999999, 18.039552689999994],
                    [-66.17216492, 18.039308549999987],
                    [-66.17245293000002, 18.039155960000016],
                    [-66.17293358, 18.039094920000025],
                    [-66.17320251000001, 18.039094920000025],
                    [-66.17344666000002, 18.039094920000025],
                    [-66.17376709000001, 18.03928185000001],
                    [-66.17305756000002, 18.042036059999987],
                    [-66.17280005999999, 18.04304695000002],
                    [-66.17234993, 18.044912339999996],
                    [-66.17170142999998, 18.050027849999992],
                    [-66.17182922, 18.050394059999974],
                    [-66.17035484000002, 18.051618580000024],
                    [-66.16718483, 18.05198096999999],
                    [-66.16692733999997, 18.051458360000026],
                    [-66.16661072, 18.050817489999986],
                    [-66.16660117999999, 18.050874710000016],
                    [-66.16659355000002, 18.05092811999998],
                    [-66.16641808000003, 18.052057269999978],
                    [-66.16641426000001, 18.052072529999975],
                    [-66.16576958000002, 18.05623436000002],
                    [-66.16262245000001, 18.051031109999997],
                ]
            ],
            [
                [
                    [-66.53508758999999, 18.392507550000005],
                    [-66.53519820999998, 18.391786579999973],
                    [-66.53970336999998, 18.392427440000006],
                    [-66.53828812, 18.397306440000023],
                    [-66.53822708000001, 18.39755821],
                    [-66.53777313, 18.398542399999997],
                    [-66.53761481999999, 18.400304790000007],
                    [-66.53463554000001, 18.40027046],
                    [-66.53440475000002, 18.399271010000007],
                    [-66.53497124, 18.39718819000001],
                    [-66.53505897999997, 18.396612170000026],
                    [-66.53450774999999, 18.395158770000023],
                    [-66.53466796999999, 18.394887919999974],
                    [-66.53466796999999, 18.39454841999998],
                    [-66.53477286999998, 18.394208909999975],
                    [-66.53480911000003, 18.393922809999992],
                    [-66.53482628, 18.39348030000002],
                    [-66.5349865, 18.393175129999975],
                    [-66.53508758999999, 18.392507550000005],
                ]
            ],
        ],
    },
}


from shapely.geometry import shape

print(shape(d["geometry"]))

If you comment out that first import fiona line the script runs without crashing.

If you move the from shapely... import to the very top of the file it runs without crashing as well:

from shapely.geometry import shape
import fiona

...

Confirmed.

(lldb) run crasher.py
There is a running process, kill it and restart?: [Y/n] Y
Process 18850 exited with status = 9 (0x00000009)
Process 19061 launched: '/Users/seang/envs/crasher/bin/python' (x86_64)
Process 19061 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x1)
    frame #0: 0x0000000104b02cbd libgeos_c.1.dylib`GEOSCoordSeq_create_r + 1133
libgeos_c.1.dylib`GEOSCoordSeq_create_r:
->  0x104b02cbd <+1133>: movq   (%rax), %rcx
    0x104b02cc0 <+1136>: movq   0x18(%rcx), %rcx
    0x104b02cc4 <+1140>: movl   -0x13c(%rbp), %edx
    0x104b02cca <+1146>: movl   -0x140(%rbp), %esi
Target 0: (python) stopped.
(lldb) up
frame #1: 0x0000000104ac2050 _speedups.cpython-37m-darwin.so`__pyx_pf_7shapely_8speedups_9_speedups_6geos_linearring_from_py + 12352
_speedups.cpython-37m-darwin.so`__pyx_pf_7shapely_8speedups_9_speedups_6geos_linearring_from_py:
    0x104ac2050 <+12352>: movq   %rax, %r13
    0x104ac2053 <+12355>: movl   -0x74(%rbp), %eax
    0x104ac2056 <+12358>: movl   %eax, -0xe0(%rbp)
    0x104ac205c <+12364>: testl  %eax, %eax

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.

We have an incompatibility between the GEOS library that comes with the latest fiona 1.8.x wheels, version 3.6.2, and the GEOS library that comes with the latest shapely wheels, version 3.8.0. I need to build and upload fiona post-release wheels that include GEOS 3.8.0. This can be done by Monday morning, 2/23. Meanwhile, I suggest either disabling the shapely speedups or temporarily reverting to shapely 1.7a2, which also used GEOS 3.6.2.

@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.

Works for me, thanks @sgillies! Any chance of getting this covered in CI so the bug doesn't pop back up again? #661

@mje-nz i've hesitated to add tests for shapely-fiona integration and GEOS compatibility to this project's CI because in a well-configured system there is never any such problem. I think I should add a check to the the wheel building project, however, to check before wheels are published to PyPI.

I'm reopening this issue. It wasn't actually resolved, only covered up by a regression in the fiona wheels we have been publishing to PyPI. The solution, for now, will be to include a libgdal without GEOS support in the fiona wheels for OS X. I'll close this again when that work has been done.

Was this page helpful?
0 / 5 - 0 ratings