I am trying to automate a workflow and I am working with the first 'piece' of the code which should check the feature classes for spatial reference and project them out if they do not equal the defined projection.
The following is the code I am using:
# Import arcpy and numpy
import os
import arcpy
import numpy
arcpy.env.workspace = r"C:\Users\GIS\Python\Distances.gdb"
outWorkspace = r"C:\Users\GIS\Python\Distances.gdb"
try:
# Use ListFeatureClasses to generate a list of inputs
for fc in arcpy.ListFeatureClasses():
# Determine if the input has a defined coordinate system, can't project it if it does not
dsc = arcpy.Describe(fc)
if dsc.spatialReference.Name != "NAD 1983 StatePlane California III FIPS 0403 (US Feet)":
# Determine the new output feature class path and name
outfc = os.path.join(outWorkspace, fc + "_NAD1983")
# Set output coordinate system
outCS = arcpy.SpatialReference('NAD 1983 StatePlane California III FIPS 0403 (US Feet)')
# run project tool
arcpy.Project_management(fc, outfc, outCS)
# check messages
print(arcpy.GetMessages())
else:
print(fc)
except arcpy.ExecuteError:
print(arcpy.GetMessages(2))
except Exception as ex:
print(ex.args[0])
The code above just outputs all of the feature classes into the defined projection rather than discriminating between the ones that are properly projected and the ones that are not.
-Side Note- numpy is not used here but will be later.