When attempting to union multiple polygons with Shapely 1.5.6 in Python 2.7.9, using GEOS 3.4.2, I get the following error in the underlying C++ code:

Assertion failed: (!"should never be reached"), function itemsTree, file AbstractSTRtree.cpp, line 371

The polygons are in a Python list and then I call shapely.ops.unary_union(polygon_list). The polygon list has 1998 items, all of which are proper polygons. I have tried running the unary_union operation in a separate python session with a couple manually created polygons and it works.

Could the number of polygons be a problem, or the import order in the file (I have seen a mention of shapely needing to be imported before Basemap, but I am not using that package)?


I figured this out on my own after testing some rearranging of import statements. In my case, rasterio needed to be imported after shapely.

For example:

import shapely
import rasterio
| improve this answer | |
  • Shapely and Rasterio shouldn't be sensitive to import order. Where are you getting the software from? PyPI or lfd.uci.edu/~gohlke/pythonlibs or elsewhere? – sgillies Mar 2 '15 at 15:59
  • I installed both packages from PyPi using pip install ... I am using a Mac with OS X 10.9, python installed via MacPorts – Damian Manda Mar 3 '15 at 18:38

I also encountered this issue with Shapely 1.5.7, installed on my mac via the wheel available on the shapely PyPI page. The solution for me was to:

pip install --upgrade --no-use-wheel shapely

After recompiling, Shapely worked as expected.

I'm on a mac (OS 10.10.2), with geospatial dependencies (including GEOS) installed via homebrew.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.