I'm trying to get the intersection area between two geodataframes using the overlay method.

gpd_df1 = gpd.read_file("shapefile1.shp") ## US census tract shape file
gpd_df1 = process(gpd_df1) ## merge with another file Census data
gpd_df2 = gpd.read_file("shapefile2.shp") ## city shape file
gpd_df2 = gpd_df2.explode() ### This has multipolygons
gpd_df2 = gpd_df2.to_crs({"proj": "cea"})
gpd_df1 = gpd_df1.to_crs({"proj": "cea"})
intersection = gpd.overlay(gpd_df2, gpd_df1, how="intersection")

I'm getting the following error at the last line of code:

KeyError: "['__idx1' '__idx2'] not found in axis"

I can run a simple toy example of overlay method.

What I'm trying to achieve?
I need to find the percentage area of every polygon of geodataframe1 that overlaps with every polygon of the geodataframe2(kind of cartesian product).

I'm extremely new to spatial dataprocessing.
What I'm doing wrong here? Is there any other approach using geopandas?

  • 1
    Add your code or it will be difficult to help – BERA Dec 3 '18 at 17:53
  • You repeat the gpd_df2 = ... line. Perhaps it should read gpd_df1 = ...? – Jon Dec 3 '18 at 18:30
  • Your code seems to be correct from looking at it. The error you get is in any case a bug in the overlay function. Are you in any possibility to share the data? Or otherwise create some similar looking dummy data that reproduces the issue? – joris Dec 3 '18 at 19:03
  • maybe this is relevant. Can you print the .head()s of your geodataframes? github.com/geopandas/geopandas/issues/174 – RutgerH Dec 3 '18 at 19:08
  • I'm sorry to trouble you all. The problem was in my code. I was supposed to use overlay on the re-projected geodataframes but I was using one of the geodataframes with initial projection. The error was due to the mismatch in the projection of geodataframes. – ashwinids Dec 4 '18 at 5:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.