I'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')

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

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

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

While the incorrectly functioning Ubuntu install has:

$> pip2 freeze | grep GDAL

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? 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'

Turns out that it's not GDAL or GEOS. It was rtree. I asked the same question over here on github, and they suggested I check the version of rtree. The version on Ubuntu was 0.8.2, and the version on the Mac was 0.8.3. I upgraded to 0.8.3 on Ubuntu, and the spatial join worked correctly.

Specifically, the command I used to fix the problem was:

pip2 install --upgrade --user rtree

Your solution could be different depending on how you originally installed rtree.

  • Confirm this. Very difficult to find! This solution should be written in GeoPandas's documentation! – kennyut Mar 13 '19 at 14:51

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.