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.

Empty overlay intersection causes error

See original GitHub issue

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

github_iconTop GitHub Comments

1reaction
jorisvandenbosschecommented, Dec 9, 2018

For people searching for it, the error was: KeyError: “[‘__idx1’ ‘__idx2’] not found in axis”

0reactions
GCBallesteroscommented, Oct 13, 2021

@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

Read more comments on GitHub >

github_iconTop 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 >

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