[GIS] Select rasters from a folder that intersect the tiles of a polygon shapefile

arcgis-10.3arcgis-desktopmodelbuilder

Ideally I want to create a model in ArcGIS ModelBuilder that will iterate a folder of rasters and output the ones that intersect polygon tiles in another shapefile.

I have the polygon shapefiles saved to a file location and can read them into the model, I have an iterator that is reading through the folder of rasters.
What tool (if existing) will allow me to output the rasters that intersect the polygons in the shapefile?

Tile Index

Selection from Tile Index: Desired Rasters to pull from folder

Attribute table of selection from Tile Index. Name column highlighted matches naming convention of Raster DEMs

Raster DEM folder, expanded in Arc Catalog

EDIT:
I was able to run a batch process since the names of the polygon tiles matched the correlated names of the raster DEMs:
Create a file list to be used for batch processes
Create a file list (export attribute table as dbf in ArcMap)
Open up file list in excel (delete all columns except common name field)

Column B – type in copy “ ” type in location of files you want to copy

Ex: copy Y:\Data\RasterDEMs\

Column C – copy/paste special Column A AS VALUES
Delete column A contents

Column D – .*

Column E – type in location for files to be saved

Column F – concatenate columns B – E
Ex: =CONCATENATE(B1,C1,D1," ",E1)

Sheet 2, Column A – copy/paste special Column F AS VALUES

Save Sheet 2 as tab delimited .txt
close excel and open Sheet2.txt
Save As with extension .bat (batch file)
double click that file and it should open the CMP box and start running

[ “ “ = Space]

For those who wanted to see the data I've added the images.

I'm running ArcGIS 10.3.1
extensions:
Spatial Analyst
3D Analyst

Best Answer

This is a problem that I've encountered many times, getting a disc full of tiles and needing to find the ones that are in/near an area to subset the rasters for building VRT, mosaic dataset or mosaicing (depending on requirements)...

I am not aware of any tool in Model Builder that will help with this, there is a limit to what can be done in model builder, however this kind of operation is very easy in python:

import os, sys, arcpy

AOI     = sys.argv[1] # the area of interest to find the rasters for
rFolder = sys.argv[2] # the folder containing the rasters to search from
oFolder = sys.argv[3] # 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(ThisRas,outFile)

This is a very cut-down tool that I use regularly; beware the AOI and the rasters must be in the same coordinate system.. You can use this in model builder after you have created your own toolbox and added a python script tool, the parameters are Feature Class, Folder and Folder (make them all input for simplicity).

I use sys.argv[] over arcpy.GetParameterAsText() - they both do the same thing but less typing.

This can be further refined using the geometries in the file (point, line or polygon - it doesn't matter):

import os, sys, arcpy

AOI     = sys.argv[1] # the area of interest to find the rasters for
rFolder = sys.argv[2] # the folder containing the rasters to search from
oFolder = sys.argv[3] # the folder to copy to

desc = arcpy.Describe(AOI) # get the extent of the AOI
sExt = desc.extent

arcpy.env.workspace = rFolder

# could use walk here to do this folder and all subfolders
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 is a canditate" % (ThisRas))
        outFile = os.path.join(oFolder,ThisRas)

        # refine further with geometry
        with arcpy.da.SearchCursor(AOI,"SHAPE@") as sCur:
            IntersectsShape = False
            for ft in sCur:
                if not ft[0].disjoint(rExt):
                    IntersectsShape = True
                    break
            if IntersectsShape:
                arcpy.AddMessage("Copy Raster %s" % (ThisRas))
                arcpy.Copy_management(ThisRas,outFile)
Related Question