1

I want to select only the raster files that overlap or intersect my AOI. I have a list of 900 raster files, and I calculate their footprints. Besides, I have my AOI.

Both, the footprints and the AOI are GeoDataFrames. I have troubles constructing my if statement. How can I check if two GeoDataFrames intersect with GeoPandas?

intersect_footprints = []

AOI = load_vector("AOI.geojson")
footprint = import_files("footprints.geojson")

if footprint["geometry"].intersects(AOI["geometry"]):
    intersected_raster.append(files_path)

I have an error:

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()

1
  • files_path is the path of the raster file. I want to save in the list only the paths of the rasters that intersect my AOI Commented Nov 3, 2022 at 11:38

1 Answer 1

1

Use the spatial join:

import geopandas as gpd

extents = gpd.read_file(r"C:\GIS\temp\extents.shp")
aoi = gpd.read_file(r"C:\GIS\data\testdata\aoi.shp")
intersecting = gpd.sjoin(left_df=extents, right_df=aoi, how="inner")
intersecting.to_file(r"C:\GIS\data\testdata\extents_intersecting_aoi.shp")

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.