Empty overlay intersection causes error
See original GitHub issueThe new implementation of overlay generates an error if the intersection is empty. Here is a reproducible code:
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.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Problem: Some Overlay tools, such as Intersect, return ...
Cause · Short segments · Null geometry · Incorrect ring ordering · Incorrect segment orientation · Unclosed rings · Self-intersections or empty parts...
Read more >python - Missing result of GeoPandas.overlay() for polygons ...
In this particular case, the result of the intersection is geometry collection containing Polygon and Point, hence the result is dropped.
Read more >Non-noded intersection issues from overlapping buffer objects
These kinds of problems are due to the fact that the current GEOS overlay (intersection in this case) algorithm is not totally robust....
Read more >geopandas.overlay - GeoDataFrame
Method of spatial overlay: 'intersection', 'union', 'identity', 'symmetric_difference' or 'difference'. keep_geom_typebool. If True, return only geometries ...
Read more >Identity (Analysis)—ArcGIS Pro | Documentation
Computes a geometric intersection of the input features and identity features. The input features or portions thereof that overlap identity features will ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

For people searching for it, the error was: KeyError: “[‘__idx1’ ‘__idx2’] not found in axis”
@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:
I also created a small pyenv to reproduce the problem. Its pip freeze follows:
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