Scripting to Batch project raster issue

5160
4
10-03-2013 05:40 PM
SamHuang
New Contributor II
Hi guys, I'm trying to write a script that will reproject my tiff files(450 of em). The script also includes a loop that will loops through my files in a folder.

Here's my code that i've already started off with and i'm not exactly sure where my problem is as I am still fairly new to it. Any pointers, suggestions and solution will be greatly appreciated! Thanks in advance!


import arcpy 

try:

        arcpy.env.workspace = r"D:Project Scripting\A1-4"
    
            # Get a list of Tiffs in the workspace.
            #
        rasters = arcpy.ListRasters("*", "TIF")
        for raster in rasters:
                print "Processing: " + raster

                outRaster = raster+"_reprojected"

                arcpy.ProjectRaster_management(raster, outRaster,\
                               "PSAD_1956_UTM_Zone_19S", "NEAREST", "",\
                               "Peru96_UTM_Zone_19S", "", "")




except:
    print "Project Raster example failed."
    print arcpy.GetMessages()


When i ran the code it gave me the following response.....

Project Raster example failed.
ERROR 000622: Failed to execute (Project Raster). Parameters are not valid.
ERROR 000628: Cannot set input into parameter out_coor_system.
Tags (2)
0 Kudos
4 Replies
ArkadiuszMatoszka
Occasional Contributor II
Hi,

In cases like this I prefer defining out_coor_system as path to .prj file representing reference system usually it solves problem.
Also I don't think "Peru96_UTM_Zone_19S" is name of geographic transformation - at least I didn't find such (refer to <install location>\ArcGIS\Desktop10.1\Documentation\geographic_transformations.pdf).

Best Regards
Arek
0 Kudos
AnnaLabetski1
New Contributor
Another option that works for me is to manually run the reproject tool in ArcGIS once and in the results window you can right click on the output and click "Copy as Python Snippet", you'll notice that once you paste this into your Python editor the result is quite long because it defines the projection in detail. Of course this will only work if you are reprojecting a series of rasters that have the same extent and the same initial projection.
0 Kudos
TimBarnes
Occasional Contributor III
1) Is your workspace path valid? i.e. should it be  r"D:\Project Scripting\A1-4" ?
2) This part might cause you issues: outRaster = raster+"_reprojected" - what does the raster variable print as? If it's 'raster1.tiff', then your raster + _reprojected will equal raster1.tiff_reprojected. You will likely need to use a python split or replace to get just the name of the raster, then add the _projected and then add the .tiff back in again

i.e. raster = raster.replace('.tiff', '_reprojected.tiff')
0 Kudos
NeilAyres
MVP Alum
Aside from the tiff renaming problems pointed out by others..
Note you are going from PSAD_1956_UTM_Zone_19S (based on D_Provisional_S_American_1956) & WKID 24879 to
Peru96_UTM_Zone_19S (based on D_SIRGAS-Chile) & WKID 5389.
So the coordinate system is not changing but the datum is. You need to specify a datum transformation for this operation, otherwise your output and input will be no different.
As I do not have any data available which is in either of these systems, I cannot comment here as to which transformation will be appropriate for your data. But I suggest that you do some by hand tests first and get the transformation issue properly sorted out before you write a script to reproject all of your imagery.
Cheers,
Neil
0 Kudos