Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Basemap "Assertion failed"

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)
like image 928
amaatouq Avatar asked Sep 30 '22 03:09

amaatouq


2 Answers

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
like image 56
josecoto Avatar answered Oct 03 '22 03:10

josecoto


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.

like image 20
amaatouq Avatar answered Oct 03 '22 03:10

amaatouq