问题
I am using Anaconda 2.1.0 and Basemap installation is successful
conda install basemap
conda install gdal
I have geos version 3.3.3 and proj4 4.8.0-0. However, I keep getting the following error when I try to project (lat,lon) degrees to a planar:
Assertion failed: (0), function query, file AbstractSTRtree.cpp, line 286.
My code looks like this:
import shapely.geometry as sg
from pymongo import MongoClient
from mpl_toolkits.basemap import Basemap
p = Basemap(projection='sinu',lon_0=0,resolution='c')
projected_xy = p(24.4,45.1)
回答1:
I was running into the same issues when working with geopandas. Again, the order of imports was relevant. In this case, I had to import geopandas after Basemap. My list of imports looks as follows:
from mpl_toolkits.basemap import Basemap
import geopandas as gp
from shapely.geometry import Point, Polygon, MultiPoint, MultiPolygon
from shapely.prepared import prep
Note that if you are working in a Jupyter notebook your Kernel connection will crash and no information of the error will be given. After using the python shell, the following error was given:
Assertion failed: (0), function query, file AbstractSTRtree.cpp, line 285.
Abort trap: 6
回答2:
For some reason, Basemap has to be imported before shapely.
from mpl_toolkits.basemap import Basemap
import shapely.geometry as sg
Doing the import the other way around will cause the error.
来源:https://stackoverflow.com/questions/27675734/python-basemap-assertion-failed