I'm trying to create a relatively basic batch reprojection tool with Python by projecting all shapefiles in a folder to NAD83 UTM Zone 11N.
I want them to go to a specified folder that I have defined as a variable. I want the outputs to maintain the same name but have "_projected" appended to the final outputs. I also have defined a variable that is the file path to a vector dataset whose spatial reference will be used in the reprojection. I want to do all this with a For loop.
At this point, the outputs go to this file path below and the wrong name, which is not what I want:
How to make it go this file path below and to have the string, "_projected" appended to each newly projected shapefile?:
Right now I'm trying this part of the code I'm posting just below to have the outputs go to the folder called Project2Output and it keeps on giving me names like Project2OutputCityBoundaries, Project2OutputFerries, Project2OutputStateRoads, etc, and to "C:\WCGIS".
outPath = outLocation + sFile + "_projected" arcpy.Project_management(sFile, outPath, outProjection)
I will eventually be turning the variable paths targetData and out projection as arcpy.GetParameterAsText variables for my Python tool but just want to see this work in my IDE first. Here is all my code below:
import arcpy import os arcpy.env.overwriteOutput = True targetData = "C:\\WCGIS\\Project2Data" # Shapefiles that need to be projected outLocation = "C:\\WCGIS\\Project2Output" # Where the projected shapefiles will be stored outProjection = "C:\\WCGIS\\Project2Data\\CountyLines.shp" # Shapefiles with correct target projection: NAD 1983 UTM Zone 10 # Get a list of all feature classes in the Project2Data folder arcpy.env.workspace = targetData try: for sFile in arcpy.ListFeatureClasses(): dsc = arcpy.Describe(sFile) if dsc.spatialReference.Name == "NAD_1983_UTM_Zone_10N": print "Skip this shapefile because it already has the correct projection:" + sFile else: outPath = outLocation + sFile + "_projected" arcpy.Project_management(sFile, outPath, outProjection) print arcpy.GetMessages() except arcpy.ExecuteError: print(arcpy.GetMessages(2)) except Exception as ex: print (ex.args)