Select to view content in your preferred language

Batch reproject

4481
5
Jump to solution
03-23-2015 08:41 AM
RobertRossell1
Deactivated User

Trying to get this script to find all .tif and .shp files and reproject them as shown.  Having trouble getting it to run.

import sys, arcpy, os

mypath = r'C:\input '

Images = []

arcpy.env.workspace = mypath

for ThisFile in os.listdir(mypath):

    thisName,thisExt = os.path.splitext(ThisFile)

    if thisExt.upper == ".TIF":

        Images.append(ThisFile)

out_workspace = r'C:\output'

OutSR = arcpy.SpatialReference(26916)  

for ThisFile in Images:

    desc = arcpy.Describe(ThisFile)

    SR = desc.spatialReference

    if SR.factoryCode != 26916:

        arcpy.ProjectRaster_management(ThisFile,out_workspace + "\\" + ThisFile,OutSR)

ShapeFiles = []

for ThisFile in os.listdir(mypath):

    thisName,thisExt = os.path.splitext(ThisFile)

    if thisExt.upper == ".SHP":

        ShapeFiles.append(ThisFile)

for ThisFile in ShapeFiles:

    desc = arcpy.Describe(ThisFile)

    SR = desc.spatialReference

    if SR.factoryCode != 26916:

        arcpy.Project_management(ThisFile,out_workspace + "\\" + ThisFile,OutSR)

0 Kudos
1 Solution

Accepted Solutions
PeteCrosier
Frequent Contributor

Instances of ".upper ==" should be changed to ".upper() ==" - you need to call the upper method that belongs to the string.

View solution in original post

5 Replies
DarrenWiens2
MVP Alum

What's the error message?

0 Kudos
RobertRossell1
Deactivated User

After hitting "Enter", it simply returns to >>> without doing anything.

0 Kudos
DarrenWiens2
MVP Alum

May have trouble with mypath backslash. Try mypath = r'C:\input '

0 Kudos
RobertRossell1
Deactivated User

I changed the input as shown.  Still nothing.

0 Kudos
PeteCrosier
Frequent Contributor

Instances of ".upper ==" should be changed to ".upper() ==" - you need to call the upper method that belongs to the string.