0

I get an odd error when I run this overlay intersection using geopandas:

grid = grid.overlay(national_outline, how='intersection')

The error states no attribute 'overlay' is available despite both grid and national_outline being functioning geopandas dataframes:

Traceback (most recent call last):
  File "C:\Users\eoughton\Desktop\Github\ccdr-basic\scripts\wealth.py", line 238, in <module>
    create_regional_grid(country)
  File "C:\Users\eoughton\Desktop\Github\ccdr-basic\scripts\wealth.py", line 62, in create_regional_grid
    grid = grid.overlay(national_outline, how='intersection')
  File "C:\Users\eoughton\Anaconda3\envs\ga\lib\site-packages\pandas\core\generic.py", line 5575, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'GeoDataFrame' object has no attribute 'overlay'

I've only found one other similar question here which identified libspatialindex and rtree as potential culprits.

However, I've exported my conda environment from another computer where this works fine, and created it on a new machine which produces this error. Both libspatialindex and rtree are installed. The .yml environment file with all package versions is here.

Any ideas why this would be happening?

Thirst for Knowledge
  • 1,606
  • 2
  • 26
  • 43
  • 1
    The `overlay` method was only added in GeoPandas version 0.10.0, maybe you have an older version? (you can check `geopandas.__version__`) On older versions, you can use the function instead: `grid = geopandas.overlay(grid, national_outline, ..)` – joris Apr 30 '23 at 07:30
  • Thanks, Joris. This actually worked when I changed the function specification to the one you state. Do you want to add it as a proper answer and I will then be able to fully close the question? – Thirst for Knowledge Apr 30 '23 at 15:01

1 Answers1

1

The overlay method was only added in GeoPandas version 0.10.0, so based on the error, you probably have an older version (you can check geopandas.__version__).

On older versions, you can use the function instead:

grid = geopandas.overlay(grid, national_outline, ..)
joris
  • 133,120
  • 36
  • 247
  • 202