Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basemap causes python to abort

I need to map some data points onto a map. I downloaded the basemap module for python to do this. I get the following error message each time I attempt to even make a map. The code I use for this is below. How can I fix this?

The version of geos I am using is 3.4.2, the version of basemap I am using is 1.0.7. The version of python I am using is 2.7. The version of gdal I am using is 1.11.2.

error message:

Assertion failed: (0), function query, file AbstractSTRtree.cpp, line 285.
aborted

code:

from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plot

def main():
    map = Basemap(projection = 'cyl', llcrnrlon= -100, llcrnrlat = -18, urcrnrlon =-80, urcrnrlat = 31)
    map.drawcoastlines(linewidth = .01)
    map.drawmapboundary(fill_color='aqua')
    plot.show()
main()
like image 804
K. Shores Avatar asked Oct 20 '22 04:10

K. Shores


1 Answers

This bug was driving me nuts. There are quite a few other SE questions and websites that have a similar issue: 1, 2, 3, but they all recommend importing mpl_toolkits.Basemap before shapely.geometry. The problem is, this is the import order that causes the problem for myself and @K.Shores. If I reverse the import order (shapely first), I don't get the problem.

I think I found a more satisfying fix to this issue here. Apparently there is a conflict between the Homebrew GEOS library and one that is bundled with the precompiled shapely wheel. So, to fix the problem, do:

$ pip uninstall shapely
$ pip install --no-use-wheel shapely
like image 92
farenorth Avatar answered Oct 21 '22 21:10

farenorth