[Tutor] Re-Project Vector Datasets

Steven Douglas 0007sd at gmail.com
Tue Oct 27 15:37:40 EDT 2020


I am writing a script that re-projects vector datasets in a folder.  From
this, it will then create a script tool.  The final script tool will have
only two textboxes for input.  The first will be to input the target data
folder and the second calls for a shape file or featureclass that calls for
the target projection dataset.  In short, it will re-project the shapefile
vector datasets in the folder to match the target dataset's projection.
*****************
The script will not contain any hard-coded values such as dataset, path, or
projection names.  Here's what I've got so far (error mentioned afterwards
below):
import arcpy

#set up the paths
targetFC = "C:\\GISData\\CountyLines.shp"
folderEnvironment = "C:\\GISData"

#get spatial reference for the target feature class
targetDescribe = arcpy.Describe(targetFC)
targetSR = targetDescribe.SpatialReference
targetSRName = targetSR.Name

# Get a list of my feature classes
arcpy.env.workspace = folderEnvironment
listOfFCs = arcpy.ListFeatureClasses()

#Loop through the list of FCs
for currentFC in listOfFCs:
#Read the spatial reference of the current one
    currentFCDescribe = arcpy.Describe(currentFC)
    currentFCSR = currentFCDescribe.SpatialReference
    currentFCSRName = currentFCSR.Name

    if currentFCSRName != targetSRName:
        print ("Spatial references don't match")
    else:
        print ("Spatial references do match")

    if currentFCSRName == targetSRName:

    else:
# Determine the new output feature class path and name
       outCS = currentFC[:-4] +"_projected.shp"
       arcpy.Project_management(currentFC, outCS, targetSR)
       rootName = currentFC[:-4]
       print (rootName)
       print (rootName +"_projected.shp")
*****************
Error:  IndentationError:  expected an Indented block -- on line 36 (the
last "else:"

It's not working.  Please help!


More information about the Tutor mailing list