3

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

  • You are mixing terminology here so I'm not sure what you are asking. First you talk about testing if a raster intersects a polygon (a spatial relationship) then you talk about clipping and losing what is outside the polygon (a geo-processing type operation). Are you asking to find which rasters intersect ANY polygon and then copy that entire raster to some new location? – Hornbydd May 26 '15 at 19:29
  • I'll try to clarify: I have a folder of rasters that spread across an area that I need separated into two different folders. I also have a tile index with polygons associated to each raster... I'm basically looking for a way to run a model to pick out the rasters that match or intersect a polygon in a shapefile and output these rasters in a new folder. – LMHall May 26 '15 at 20:02
  • So lets say you have a folder with a shapefile with 10 polygons, named 1-10 respectively. You have a folder with 10 rasters named 1-10 respectively. You want to select rasters that match polygons 1-5 and export them to another folder, while moving rasters 6-10 to another folder as well. – LMHall May 26 '15 at 20:04
  • 1
    Would you be able to use the edit button rather than a comment trail to provide these clarifications to your question, please? – PolyGeo May 26 '15 at 20:21
  • These comments sound right - If you've got the tile index, you'd start with a simple selection - select by location, select features from [tile index], source layer [polygon features layer], intersect the source layer features. You'd then have a table you could use to reference the rasters you want. – That Idiot May 26 '15 at 20:24
5

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)
  • This is great, unfortunately I am not that comfortable in Python. I will try this out though! Thanks! Your answer actually gave me insight on how to get this to work in Excel since the names on the index tiles matches the associated raster DEM. – LMHall May 27 '15 at 15:26
  • 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\Orthos\2007_CIR\FromAxis20090401\Blocks_ALL\ 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 – LMHall May 27 '15 at 15:27
  • 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] – LMHall May 27 '15 at 15:27
  • Yeh, batch by Excel was how I did this for many years (late 90's to ArcGis 9.0) sometimes I find it faster to do it that way (like sort by X or Y and grab anything less/greater depending on circumstances).. this ties in with another script that creates extent boxes for images; quite often we are given images but no key and making a key is the first step in QA to ensure we have all the images and they're georeferenced. I would encourage you to give python a try, you might be surprised how easy it is – Michael Stimson May 27 '15 at 21:38
1

Thanks Michael, I used your Python but I got the following error:

ERROR 000840: The value is not a Data Element. Failed to execute (Copy).

I just changed arcpy.Copy_management(ThisRas,outFile) to arcpy.Copy_management(os.path.join(rFolder,ThisRas),outFile)

and it is working fine now.

Your Answer

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

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