0

Using GeoPandas 0.4.0 with Python 3.5, I'm finding that geopandas.intersects does not behave as I expect it to. For example, a buffer around Switzerland does not appear to intersect with neighbouring countries.

import matplotlib.pyplot as plt
import geopandas as gp

>>> world = gp.read_file(gp.datasets.get_path('naturalearth_lowres'))
>>> eur = world.loc[world['name'].isin(['Switzerland','Austria', 'Germany', 'Italy', 'Slovenia']),  ]
>>> ch = world.loc[world['name'] == 'Switzerland', ]
>>> buff = ch.buffer(1)

>>> eur.intersects(buff)
9      False
28      True
41     False
79     False
150    False
dtype: bool

Ie, the buffer only intersects with index 28 from eur, which is Switzerland. But the buffer clearly overlaps with the other countries as well, as demonstrated when plotting:

>>> fig, ax= plt.subplots()
>>> ax.set_aspect('equal')
>>> eur.plot(ax=ax)
>>> buff.plot(ax=ax, color='red' 

Buffer around Switzerland

What am I doing wrong that's preventing me from seeing the buffer intersecting with the other countries?

1

The intersects predicate is for GeoSeries and is elementwise thus with all the lines/polygons in eur

print(eur.index)
Int64Index([9, 28, 41, 79, 150], dtype='int64')
for i in eur.index:
    print(i,"-->", buff.intersects(eur.loc[i].geometry))
9 --> 28    True
28 --> 28    True
41 --> 28    True
79 --> 28    True
150 --> 28    False

With two GeoDataFrames use overlay

buffer = gp.GeoDataFrame({'geometry':buff})
result = gp.overlay(buffer,eur, how='intersection')
  • Thanks! I'll use overlay, since I'll be working with 2 geodataframes. – HDR Jul 1 at 13:33

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.