GeoPandas returning incorrect spatial join results on Ubuntu, but correct on OS X.
See original GitHub issueI’m having a problem that I can reproduce on an Ubuntu installation of GeoPandas (0.3.0), but not on my local OS X intallation (same geopandas version). Here’s the example (taken from the geopandas documentation):
import geopandas as gpd
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
cities = gpd.read_file(gpd.datasets.get_path('naturalearth_cities'))
countries = world[['geometry', 'name']]
countries = countries.rename(columns={'name':'country'})
cities_with_country = gpd.sjoin(cities, countries, how="inner", op='intersects')
cities_with_country.head()
The correct result, as shown here and as obtained on my OS X installation, is:
name geometry index_right \
0 Vatican City POINT (12.45338654497177 41.90328217996012) 79
1 San Marino POINT (12.44177015780014 43.936095834768) 79
192 Rome POINT (12.481312562874 41.89790148509894) 79
2 Vaduz POINT (9.516669472907267 47.13372377429357) 9
184 Vienna POINT (16.36469309674374 48.20196113681686) 9
country
0 Italy
1 Italy
192 Italy
2 Austria
184 Austria
However, on my Ubuntu install, I get this:
name geometry index_right \
183 Kabul POINT (69.18131419070505 34.51863614490031) 0
183 Kabul POINT (69.18131419070505 34.51863614490031) 0
183 Kabul POINT (69.18131419070505 34.51863614490031) 0
country
183 Afghanistan
183 Afghanistan
183 Afghanistan
and len(cities_with_country) is only 3. The same problem happens with other data as well.
I’ve check all the listed dependencies on both installs and verified that they’re the same versions. However, the GDAL versions are different. The correctly functioning OS X install has:
$> pip2 freeze | grep GDAL
GDAL==1.11.5
While the incorrectly functioning Ubuntu install has:
$> pip2 freeze | grep GDAL
GDAL==2.2.2
I’m reluctant to start messing with downgrading my GDAL installation, so I’m hoping that someone can confirm or refute my theory that geopandas is (indirectly) dependent on GDAL and that version 2.2.2 could be causing the problem. …and I’m wondering if downgrading is the only solution.
After revisiting this and looking through the geopandas and shapely code, it seems more likely that this would be related to GEOS rather than GDAL, right? I don’t think GDAL is even involved here. As far as I can tell, both installations are using GEOS from the wheel installed with shapely. Both give the same geos version string:
>>> import shapely
>>> shapely.geos.geos_version_string
'3.6.2-CAPI-1.10.2 4d2925d6'
So, I don’t know if this is a installation/configuration problem on our Ubuntu server of if this is an upstream shapely/GEOS problem? I’d be grateful for help sorting this out. The Ubuntu machine is where I’d like to be doing most of my work. If it is an upstream problem, I could use some help it isolating it and coming up with coherent example to take to the shapely folks. Thanks in advance.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)

Top Related StackOverflow Question
@jorisvandenbossche Right, I guess it doesn’t seem that likely that it would be GDAL in this case, and probably marginal value in actually testing against GDAL versions here, since fiona is testing it upstream. I’ve had enough issues that were eventually related to GDAL version that my personal bias is to always consider it a possibility. @jkibele what version of rtree are you using on your Ubuntu install? I did once have spatial join related issues related to using an older rtree version.
@jkibele Glad that worked for you!