Comparing extents of Rasters for selection

Discussion created by corea on Aug 14, 2011
Latest reply on Aug 28, 2011 by corea
I am writing a script that takes an input of an Area of Interest (AOI) and then walks through the base directories to find any file that has an extent that intersects with the AOI, clip it and generate a text output file. I've got most of it working except comparing the raster extent to the AOI extent. It is not giving errors but just doesn't work...

Any advise?

I am also having issues with trying to clip the extent to a polygon, it clips but maintains the MAX/MIN and doesn't clip to the mask. I have tried three methods as in the comments in the script.

Extract by Mask says I don't have Spatial Analyst but it is on.

Thanks guys,

import arcpy, glob, os, sys, string
from arcpy import env
from import *

RootDirectories = [r'P:\2011\Job_154_PythonScript_for_AOI\Working\Orthophotomosaic', r'P:\2011\Job_154_PythonScript_for_AOI\Working\Contours']
RasterTypes = ['tif','jpg'] #boolean, valuelist

path = os.getcwd()
#AOI = arcpy.mapping.Layer('AOI.shp')
AOI = 'AOI.tif'

#print AOIextent
SR = 0
for RootDirectory in RootDirectories:
    for root, dirs, files in os.walk(RootDirectory):
        for RasterType in RasterTypes:
            FileList = [os.path.join(root, fi) for fi in files if fi.endswith(RasterType)]
            for File in FileList:
                SR = FileDesc.spatialReference
                if != "Unknown":
                    FileObj = arcpy.Raster(File)
                    FileExtent = FileObj.extent
                    print File, FileExtent
                    if FileExtent.within(AOIobj.extent):
                        print "WITHIN extent"

                        print "outside extent"
# NOTE: The following should be executed in the within loop above but is here as the extent comparison isn't working

                        f = open(path+'\\AOI_Clip\\AOI_SubsetGenerator.txt', 'a')
#Method 1
                        #arcpy.Clip_management(File, "#", outRaster, AOI, "0", "ClippingGeometry")
#Method 2
                        desc = arcpy.Describe("AOI.shp")
                        frame = str(desc.extent)
                        arcpy.Clip_management (File, frame, outRaster)
#Method 3
                        #outExtractByMask = ExtractByMask(File, 'AOI.shp')
                        print "Created: " + str(outRaster)
            print "Changing Directory to: " + str(dirs)
print "Exiting"