Reprojecting Rasters Issue

2179
9
08-09-2011 07:19 AM
EricaNewton
New Contributor
Hi there,

I am new to python and attempting to set up a batch process to reproject rasters in a folder. 

This is the script and error message I am getting.  I defined the projection of the rasters in the folder to WGS 1984 UTM Zone 16N before starting.

>>> import arcpy
... arcpy.env.workspace = r"C:/GIS/NDVI/Georef_27_21_TIFFs/test"
... rasterList = arcpy.ListRasters("*", "All")
... for raster in rasterList:
...     print raster
... outraster = raster+"_ontlambproj"
... arcpy.ProjectRaster_management("raster", "outraster", "MNR_LAMBERT_PROJECTION_3161.prj", "NEAREST", "30", "WGS_1984_(ITRF00)_To_NAD_1983", "#", r"C:/Program Files/ArcGIS/Desktop10.0/Coordinate Systems/Projected Coordinate Systems/UTM/WGS 1984/Northern Hemisphere/WGS 1984 UTM Zone 16N.prj")
...
L5027021_02119850802_B30.TIF

LT5027021008516650_B3.tif

Runtime error <class 'arcgisscripting.ExecuteError'>: Undefined coordinate system for input dataset.

Can anyone help me determine why I am getting this error?

Thank you so much!

Erica
Tags (2)
0 Kudos
9 Replies
MathewCoyle
Frequent Contributor
"raster" and "outraster" are variables not string names, so remove the quotes and try that.
0 Kudos
EricaNewton
New Contributor
THANK YOU!!!  I thought it must have been a simple solution, but being very new to this,  I have been working on it for days.  I'm still having a problem with the file name (it renames the files as originalfilename.tif_olp.tif - need to fix that to originalfilename_olp.tif but I think I can figure that out - here is the final script that properly reprojects the tif.

... import arcpy
... arcpy.env.workspace = r"C:/GIS/NDVI/Georef_27_21_TIFFs/test"
... rasterList = arcpy.ListRasters("*", "All")
... for raster in rasterList:
...     print raster
... outraster = raster+"_olp.tif"
... arcpy.ProjectRaster_management(raster, outraster, "MNR_LAMBERT_PROJECTION_3161.prj", "NEAREST", "30", "WGS_1984_(ITRF00)_To_NAD_1983", "#", r"C:/Program Files/ArcGIS/Desktop10.0/Coordinate Systems/Projected Coordinate Systems/UTM/WGS 1984/Northern Hemisphere/WGS 1984 UTM Zone 16N.prj")
...
L5027021_02119850802_B30.TIF

LT5027021008516650_B3.tif
0 Kudos
MathewCoyle
Frequent Contributor
Yes that is just simple string manipulation, since raster = "originalfilename.tif" when you do outraster = raster+"_olp.tif" you get the logical originalfilename.tif_olp.tif

There are a couple ways to solve that issue.

raster = raster.rpartition(".")[0]
0 Kudos
JamieDrisdelle
New Contributor III
You can also use this to get the base name of a raster without its extension like this.  Both options will work.  

desc = arcpy.Describe(raster)
name = desc.baseName

Jamie
0 Kudos
EricaNewton
New Contributor
Perfect.  Thanks to both of you very much.  Now I can keep going !

Erica
0 Kudos
EricaNewton
New Contributor
There is one final tweak that I can't seem to figure out with this script.  Both of the following only return one reprojected file, not both that are in the "test" folder.  Any ideas on how to get it to process both .tif files?

import arcpy
arcpy.env.workspace = r"C:/GIS/NDVI/Georef_27_21_TIFFs/test"
rasters = arcpy.ListRasters("*", "All")
for raster in rasters:
    print raster
outraster = raster.rpartition(".")[0]+"_olp.tif"
arcpy.ProjectRaster_management(raster, outraster, "MNR_LAMBERT_PROJECTION_3161.prj", "NEAREST", "30", "WGS_1984_(ITRF00)_To_NAD_1983", "#", r"C:/Program Files/ArcGIS/Desktop10.0/Coordinate Systems/Projected Coordinate Systems/UTM/WGS 1984/Northern Hemisphere/WGS 1984 UTM Zone 16N.prj")


import arcpy
arcpy.env.workspace = r"C:/GIS/NDVI/Georef_27_21_TIFFs/test"
rasters = arcpy.ListRasters("*", "TIF")
for raster in rasters:
    print raster
    outraster = raster.rpartition(".")[0]+"_olp.tif"
    arcpy.ProjectRaster_management(raster, outraster, "MNR_LAMBERT_PROJECTION_3161.prj", "NEAREST", "30", "WGS_1984_(ITRF00)_To_NAD_1983", "#", r"C:/Program Files/ArcGIS/Desktop10.0/Coordinate Systems/Projected Coordinate Systems/UTM/WGS 1984/Northern Hemisphere/WGS 1984 UTM Zone 16N.prj")
0 Kudos
EricaNewton
New Contributor
Sorry, the first script only has one indent for "print raster"

The second script is indented at "print raster" and all following lines.
0 Kudos
MathewCoyle
Frequent Contributor
Wrapping your code in [ CODE][/CODE ] tags lets you preserve your formatting.

As to the question, do both Rasters have unique names? Same coordinate systems? When you list the rasters do both come up? The syntax for limiting the list by .tif images is "TIFF" I believe.
0 Kudos
EricaNewton
New Contributor

[HTML]

Apparently I just wasn't waiting long enough.  The second code (below) works for both. 

import arcpy
arcpy.env.workspace = r"C:/GIS/NDVI/Georef_27_21_TIFFs/test"
rasters = arcpy.ListRasters("*", "TIF")
for raster in rasters:
    print raster
    outraster = raster.rpartition(".")[0]+"_olp.tif"
    arcpy.ProjectRaster_management(raster, outraster, "MNR_LAMBERT_PROJECTION_3161.prj", "NEAREST", "30", "WGS_1984_(ITRF00)_To_NAD_1983", "#", r"C:/Program Files/ArcGIS/Desktop10.0/Coordinate Systems/Projected Coordinate Systems/UTM/WGS 1984/Northern Hemisphere/WGS 1984 UTM Zone 16N.prj")

[/HTML]

0 Kudos