Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertion failed: (0), function query #260

Closed
phargogh opened this issue Mar 29, 2015 · 10 comments
Closed

Assertion failed: (0), function query #260

phargogh opened this issue Mar 29, 2015 · 10 comments

Comments

@phargogh
Copy link
Contributor

Hello,

When I use shapely.ops.cascaded_union, I encounter this error:

Assertion failed: (0), function query, file AbstractSTRtree.cpp, line 285.
Abort trap: 6

It looks like it might be a compatibility issue with GDAL (which I believe uses a version of GEOS). Here's a script that fails:

from osgeo import ogr
from shapely.geometry import Point
import shapely.ops

def synth_geom():
    polygons = [
        Point(1, 1).buffer(1),
        Point(1, 2).buffer(1),
    ]
    biggest_feature = shapely.ops.cascaded_union(polygons)
    print biggest_feature

if __name__ == '__main__':
    synth_geom()

I noticed that if I change the order of the import statements, cascaded_union works as expected.

from shapely.geometry import Point
import shapely.ops
from osgeo import ogr

Is this something that can or should be addressed by Shapely?

@sgillies
Copy link
Contributor

@phargogh did you pip install shapely? Since December, on OS X, you'll get a binary Shapely wheel if you do and the wheel includes a GEOS shared library. It's possible that these Shapely wheels are not compatible with the Homebrew GEOS lib and that errors will occur if the GEOS lib has already been loaded by osgeo.ogr.

I've got a potential workaround for you: do a pip uninstall shapely && pip install --no-use-wheel shapely. This will grab the Shapely source distribution instead of a binary wheel and it should have no problems with Homebrew's GEOS.

Can you report back to me if that gets you out of this jam?

@sgillies
Copy link
Contributor

Anything to report about a fresh from-source install @phargogh?

@phargogh
Copy link
Contributor Author

Yep! The fresh, from-source install of shapely works as expected. Guess this should teach me to be more aware of the dependencies I've installed and am building against :)

@dfelikson
Copy link

I was having the same issue and resolved it by importing shapely before importing osgeo. I didn't need to do the "pip install --no-use-wheel shapely". Just for future reference, could someone explain what's going on when shapely is imported before osgeo and why it causes the error?

@sgillies
Copy link
Contributor

sgillies commented Apr 7, 2015

@dfelikson please see #262. I don't understand exactly what's going on yet. Specific details (operating system, sources of software -- Homebrew? PyPI? -- versions) will be needed to track this down.

@ozak
Copy link

ozak commented May 18, 2015

@sgillies there is definitely an issue with Homebrew and the wheeled version of Shapely. I did not have the issue reported here (although I did not import shapely before osgeo) but a completely different one #273 which got resolved using pip uninstall shapely && pip install --no-use-wheel shapely.

@lkilcher
Copy link

I was having this issue too, thank you!

@dmwelch
Copy link

dmwelch commented Jan 4, 2017

@sgillies I was using shapely in a virtualenv - did the pip install --no-use-wheel shapely thing with no luck. I added this line before importing pyproj just to check that I was importing from the right location:

import shapely
shapely.__file__

Now it works like magic... unlike @phargogh, I'm not importing osgeo so maybe that lends a little more light on it?

@dmwelch
Copy link

dmwelch commented Jan 5, 2017

@sgillies I did some digging and tracked this down in my case. I also found it is a known issue with fiona and other osgeo-based tools (Toblerity/Fiona#383).

Here's my notebook:

Description

When running the line:

combined = g2.intersection(g3)

the kernel will crash and Jupyter throws the error:

Assertion failed: (0), function query, file AbstractSTRtree.cpp, line 285.
Abort trap: 6

A possible solution was to reinstall shapely from source:

pip uninstall shapely && pip install --no-binary :all: shapely

but @guziy's suggestion on geoplex/elasticsearch-spatial#1 got me to wonder, so I tried replacing the fiona import line.

%load_ext watermark
%watermark
2017-01-05T11:44:44

CPython 2.7.11
IPython 5.1.0

compiler   : GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)
system     : Darwin
release    : 15.6.0
machine    : x86_64
processor  : i386
CPU cores  : 8
interpreter: 64bit
%%sh
pip uninstall -y shapely  # remove the shapely from the virtualenv and use the global package
import shapely
shapely.__file__  # returns '/Library/Frameworks/GEOS.framework/Versions/3/Python/2.7/site-packages/shapely/__init__.pyc'

import fiona  # <--- doesn't crash when commented out
from shapely.geometry import shape
scene_metadata = {u'geometry': {u'coordinates': [[[5.4438, 30.7100517],
                                                  [6.2335518, 30.6927744],
                                                  [6.2013482, 29.7034878],
                                                  [5.1922031, 29.7240552],
                                                  [5.2265358, 29.8585064],
                                                  [5.2640662, 30.0064961],
                                                  [5.3019095, 30.1543621],
                                                  [5.4438, 30.7100517]]],
                                u'type': u'Polygon'}}

g1 = shape(scene_metadata['geometry'])

from shapely import affinity
g2 = affinity.rotate(g1, 30)

combined = g2.intersection(g1)  # <----- ***CRASH***

@denadai2
Copy link
Contributor

I was having this issue too, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants