bjebn

Batch Reprojection

Discussion created by bjebn on Nov 17, 2011
Latest reply on Nov 18, 2011 by mdenil
Hi Everyone,

I've been working on some code to automatically sort a list of subdirectores and then to reproject those dems which end with *dem.tif. The function to find those files has worked (on its own) but the reprojection function does not seem to work at all, either on its own or with the find function described above. Here is the code...

# Batch Processing Script used to redefine projection 

import os, fnmatch, arcpy, sys, string

# Sort files by a Specified Filename
def File_Find(filepat,top):
    for path, dirlist, filelist in os.walk(top):
        for name in fnmatch.filter(filelist,filepat):
            yield os.path.join(path,name)

        
#Reproject Raster Datasets
def DefineProjection():
#Variables 
    InFolder = sys.argv[1] 
    OutFolder = sys.argv[2]
    incoordinate = sys.argv[3]
    outcoordinate = sys.argv[4]
    SFiles = File_Find('*dem.tif',InFolder) # Files Used in Reprojection
    arcpy.env.workspace = SFiles

#Reprojection Function   

try:
    RasterList = arcpy.ListRasters()
    RasterList.Reset()
    RasterImage = RasterList.Next()
    arcpy.AddMessage('\n' + 'Begin Processing.......' + '\n')

    while RasterImage:  
        arcpy.AddMessage(' Projecting  ' + RasterImage)
        InFileName = ReProject + "\\" + RasterImage
        arcpy.AddMessage( 'infilename = ' + InFileName)
        OutFileName = OutFolder + '\\ ' + RasterImage
        arcpy.AddMessage('outfilename = ' + OutFileName)
        arcpy.ProjectRaster_management(InFileName, OutFileName, outcoordinate, 'CUBIC', '#', '#', '#', incoordinate)
        arcpy.AddMessage(RasterImage + '  Projected')
        arcpy.AddMessage('\n')
        RasterImage = RasterClassList.Next()
except:
    print arcpy.GetMessages(2)
    print 'No Files Match That Criteria!'



The code runs without any error in ArcGIS, but it does not produce any results, so I suspect it has something to do with the way I have used the list rasters function.

Any help would be most appreciated,

Sincerely,
Bjorn

Outcomes