I'm new to ArcPy and to Python in general.
I have a huge raster dataset of all over the World (~1000 tiles .tif) and i'd like to automatically copy the tiles which are intersecting with 24 polygons (one shapefile containing polygons for 24 cities in Africa) in order to keep only the tiles that partially or completely contains my cities. I try using the script below. But when I do, he gives me all the tiles that are in between those cities (so pretty much all tiles in Africa). Probably because he uses the total extent of my shapefile, and not the polygons that are in that shapefile.
Does anyone knows how I could correct this so I get as result only the tiles that are intersecting with the 24 polygons inside that shapefile?
import os, sys, arcpy AOI = "C:/Users/jbihin/Desktop/testGufPython/To_Jeremie/Cities24_50km.shp" # the area of interest to find the rasters for rFolder = "D:/GUF/GUF04" # the folder containing the rasters to search from oFolder = "C:/Users/jbihin/Desktop/testGufPython/To_Jeremie/gufSelect" # the folder to copy to desc = arcpy.Describe(AOI) # get the extent of the AOI sExt = desc.extent arcpy.env.workspace = rFolder for ThisRas in arcpy.ListRasters(): rDesc = arcpy.Describe(ThisRas) rExt = rDesc.extent # check if this extent is related spatially # by using not disjoint if sExt.disjoint(rExt): arcpy.AddMessage("Raster %s is outside" % (ThisRas)) else: arcpy.AddMessage("Raster %s overlaps" % (ThisRas)) outFile = os.path.join(oFolder,ThisRas) arcpy.Copy_management(os.path.join(rFolder,ThisRas),outFile)