Repository: geopandas/geopandas

Issue:
Empty overlay intersection causes error
The new implementation of ``overlay`` generates an error if the intersection is empty. Here is a reproducible code:

```python
import geopandas as gpd
from geopandas.tools import overlay
from shapely.geometry import Polygon
polys1 = gpd.GeoSeries([Polygon([(0,0), (2,0), (2,2), (0,2)]),Polygon([(2,2), (4,2), (4,4), (2,4)])])
polys2 = gpd.GeoSeries([Polygon([(-1,-1), (-3,-1), (-3,-3), (-1,-3)]),Polygon([(-3,-3), (-5,-3), (-5,-5), (-3,-5)])])
df1 = gpd.GeoDataFrame({'geometry': polys1, 'df1':[1,2]}, crs={'init': 'epsg:4326', 'no_defs': True})
df2 = gpd.GeoDataFrame({'geometry': polys2, 'df2':[1,2]}, crs={'init': 'epsg:4326', 'no_defs': True})
gpd.tools.overlay(df1, df2, 'intersection')
```

I will try to provide a PR tonight.


Discussion:
Closed by #800
For people searching for it, the error was: KeyError: "['__idx1' '__idx2'] not found in axis"
Shouldn't this issue be closed? 
Yes, thanks @drnextgis 
Has the problem fixed by PR #800 mentioned above creeped in again. I'm on 0.10.1. Checking [overlay.py](https://github.com/geopandas/geopandas/blob/ce285d2cc671a12a85f166ce6a3fbf1713b7879b/geopandas/tools/overlay.py#L388) on master it looks like the `if` statement introduced on August 24 2018 is not there anymore.

As a result I get the `KeyError: "['__idx1' '__idx2'] not found in axis"` error when trying to overlay two dataframes with no intersections.
@GCBallesteros Can you provide an example code? This should not happen.
Looking at the PR where we updated this, we might have removed those columns again: https://github.com/geopandas/geopandas/commit/0c9d04ec808f6a953eff96b02762945bc3b39f30#r57884483
@martinfleis  Sure thing. At the bottom you have two GDrive links to tiny feather files that can reproduce the issue. The code in that case is simply:
```
import geopandas as gpd

gdf1 = gpd.read_feather("gdf_1.feather")
gdf2 = gpd.read_feather("gdf_2.feather")

gpd.overlay(gdf1, gdf2)
```
I also created a small pyenv to reproduce the problem. Its pip freeze follows:
```
attrs==21.2.0
certifi==2021.10.8
click==8.0.3
cligj==0.7.2
Fiona==1.8.20
geopandas==0.10.1
munch==2.5.0
numpy==1.21.2
pandas==1.3.3
pyarrow==5.0.0
pyproj==3.2.1
python-dateutil==2.8.2
pytz==2021.3
Rtree==0.9.7
Shapely==1.7.1
six==1.16.0
```

DataFrame 1: https://drive.google.com/file/d/1QclfH3k51Lu0kux9ImY3vznRrt5bdmLE/view?usp=sharing
DataFrame 2: https://drive.google.com/file/d/1t2Ub6Iy3OrssWQZj2YY-6DofdKsBKXDP/view?usp=sharing



Resolving patch:
diff --git a/geopandas/tools/overlay.py b/geopandas/tools/overlay.py
--- a/geopandas/tools/overlay.py
+++ b/geopandas/tools/overlay.py
@@ -65,6 +65,8 @@ def _overlay_intersection(df1, df2):
             right_index=True,
             suffixes=("_1", "_2"),
         )
+        result["__idx1"] = None
+        result["__idx2"] = None
         return result[
             result.columns.drop(df1.geometry.name).tolist() + [df1.geometry.name]
         ]


Test patch:
diff --git a/geopandas/tests/test_overlay.py b/geopandas/tests/test_overlay.py
--- a/geopandas/tests/test_overlay.py
+++ b/geopandas/tests/test_overlay.py
@@ -723,3 +723,14 @@ def test_non_overlapping(how):
         )
 
     assert_geodataframe_equal(result, expected)
+
+
+def test_no_intersection():
+    # overlapping bounds but non-overlapping geometries
+    gs = GeoSeries([Point(x, x).buffer(0.1) for x in range(3)])
+    gdf1 = GeoDataFrame({"foo": ["a", "b", "c"]}, geometry=gs)
+    gdf2 = GeoDataFrame({"bar": ["1", "3", "5"]}, geometry=gs.translate(1))
+
+    expected = GeoDataFrame(columns=["foo", "bar", "geometry"])
+    result = overlay(gdf1, gdf2, how="intersection")
+    assert_geodataframe_equal(result, expected, check_index_type=False)