jonmulder

Compare Raster Mosaic Extent Against DOQQ Extent

Discussion created by jonmulder on Dec 2, 2013
Latest reply on Dec 6, 2013 by jonmulder
Greetings,

I have a large raster mosaic that covers the same general area as about 50 DOQQ tifs.  I am trying to automate a process where I can go through my directory of 256 DOQQ tifs, check if the raster moasic extent overlaps with the DOQQ extent, then invoke arcpy.Clip_management to create a tif of the mosaic that is the same extent as the DOQQ.

In looking at several thrads on here, it seems "(DOQQExtent.overlaps(TargetRasterExtent))" should work where

  • DOQQExtent = Extent of DOQQ

  • TargetRasterExtent = Extent of raster mosaic

In debugging, I get a FALSE for every single DOQQ that is compared, and I know about 50 DOQQs do overlap (pulled both raster mosaic and DOQQs into a project and visibly confirmed.  Any idea why the extent comparison NEVER returns a TRUE?

Thanks for any help you can provide.  I'm a relative newby to Python scripting.

Jonathan Mulder
California Department of Water Resources

import os
import fnmatch
import arcpy
arcpy.CheckOutExtension("Spatial")

'''
# Get name of raster mosaic
in_rastermosaic = arcpy.GetParameterAsText(0)
# Get directories of DOQQ images
in_directories = arcpy.GetParameterAsText(1)
# Get directory of outputted rasters
out_directory = arcpy.GetParameterAsText(2)
'''

in_rastermosaic = r'G:\Documents\GIS\BaseData\Raster\Imagery\AerialPhotos\1958\MosaicGeoDatabase\1958_ButtePhotos.gdb\ButtePhotos_1958_20131123'
x = r'G:\Documents\GIS\BaseData\Raster\Imagery\DOQQs\39121'
in_directories = [x]
out_directory = r'G:\Documents\GIS\BaseData\Raster\Imagery\AerialPhotos\1958\MosaicedRastersForDOQQs'

#Function definition for getting file list.
def get_filelist(in_directory, pattern='*.tif'):
    file_list = []
    for item in os.listdir(in_directory):
        if os.path.isfile(os.path.join(in_directory, item)):
            if fnmatch.fnmatch(os.path.basename(item), pattern):
                filepath = os.path.join(in_directory,item)
                file_list.append(filepath)
    return file_list

print 'Hi'
arcpy.env.workspace = out_directory
TargetRasterExtent = arcpy.Describe(in_rastermosaic).extent
print TargetRasterExtent
try:
    for CurrentDirectory in in_directories:
        print CurrentDirectory
        file_list = get_filelist(CurrentDirectory, '*.tif')
        for tif_file in file_list:
##            print tif_file
            DOQQExtent = arcpy.Describe(tif_file).extent
##            print DOQQExtent
##            int = arcpy.Intersect_analysis(TargetRasterExtent,DOQQExtent)
##            print int
            Extent_Overlap = str(DOQQExtent.overlaps(TargetRasterExtent))
            print Extent_Overlap
            if Extent_Overlap == 'True':
                print "Extent_Overlaps"
                arcpy.AddMessage("Extent Overlaps")

##            if DOQQExtent.within(TargetRasterExtent)== 'True':
#                arcpy.Clip_management(in_rastermosaic,"#","1958_" + tif_file + ".tif",tif_file,0,"NONE","NO_MAINTAIN_EXTENT")
            else:
                print "Extent does not Overlap"

except:
    print(arcpy.GetMessages())

Outcomes