Problem projecting rasters

619
2
Jump to solution
06-07-2017 10:27 AM
DanielSchatt
New Contributor III

hi, I'm simply trying to take a bunch of rasters in a directory and process each of them in my "for" loop.  The first thing I need to do is project it.  For some mysterious reason, the code goes through the loop the first time and processes the first raster fine, but I get an exception on the second raster (second loop iteration) on the ProjectRaster line (line 22) with the error "Undefined coordinate system for input dataset".   All the rasters have the same defined coordinate system, and this happens no matter what rasters are in the list.  It does the first one just fine, but when it loops back again to do the second one, I get the error.  I can see it is reading the file list properly by looking at the string values it is using so no idea what the problem is.  Here's the relevant code, thanks for any help!

# Import necessary modules
import arcpy
import glob, os

from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")

os.chdir("I:/SCHISM_project/HPC/input")

arcpy.env.workspace = "I:/SCHISM_project/HPC/output"
arcpy.env.overwriteOutput = True

for originalElevationRasterString in glob.glob("*.tif"):
    
      rasterTimeString = originalElevationRasterString[8:23]
      originalElevationRasterBaseString = originalElevationRasterString[0:23]
        
      # Project surface water elevation from Geographic to UTM
      UTMProjection = arcpy.SpatialReference(26918)
      originalElevationRasterUTMString = originalElevationRasterBaseString + "_UTM.tif"
      print "Projecting water elevation to UTM..."
      arcpy.ProjectRaster_management(originalElevationRasterString, originalElevationRasterUTMString, UTMProjection)
0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

Hi Dan,

Just troubleshooting, but maybe try removing glob and replacing it with arcpy.ListRasters.  Ex:

for originalElevationRasterString in arcpy.ListRasters("*", "TIF"):

View solution in original post

2 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Dan,

Just troubleshooting, but maybe try removing glob and replacing it with arcpy.ListRasters.  Ex:

for originalElevationRasterString in arcpy.ListRasters("*", "TIF"):
DanielSchatt
New Contributor III

thanks Jake, that did the trick!

0 Kudos