question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GeoPandas returning incorrect spatial join results on Ubuntu, but correct on OS X.

See original GitHub issue

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')
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:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jdmcbrcommented, Jan 13, 2018

@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.

0reactions
jdmcbrcommented, Jan 22, 2018

@jkibele Glad that worked for you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

GeoPandas returning incorrect spatial join results. GDAL ...
3 on Ubuntu, and the spatial join worked correctly. Specifically, the command I used to fix the problem was: pip2 install --upgrade --user...
Read more >
BUG: Spatial join returns incorrect results with Shapely 1.8
Problem description. The spatial join behaviour (with PyGeos) has changed between Shapely 1.7.1 (correct behaviour) and Shapely 1.8 (incorrect ...
Read more >
Geopandas Spatial Join Fails - Unsupported Format String
So I've actually figured this out. The dataframe just had an index, the geometry, and some numeric data tagged to the geometry.
Read more >
How To Joint Two Geopandas Data Framesm Due To 'Rtree ...
GeoPandas returning incorrect spatial join results on Ubuntu but correct on OS X. #637 The same problem happens with other data as well....
Read more >
Make a Location-Based Web App With Django and GeoDjango
Use the GeoDjango sub-framework to implement geolocation features in your Django application. Use a spatial database (PostgreSQL and PostGIS) to get benefits ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found