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"


    # 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



except arcpy.ExecuteError:

except Exception as ex:

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.

1 Answer 1


Try printing out the "dsc.spatialReference.Name". When I did, none of my Spatial Reference Names had spaces and instead had underscores "_". I suspect that may be why none of your spatial references match "NAD 1983 StatePlane California III FIPS 0403 (US Feet)".

So it instead should be "NAD_1983_StatePlane_California_III_FIPS_0403_(US_Feet)".

  • This didn't work. Adding " _ " still output all of the feature classes with the extension _NAD1983 -- which is what it should do if all feature classes do not meet this classification.
    – Therow
    Commented Feb 12, 2020 at 21:25
  • The only reason it would do that is because the "dsc.spatialReference.Name" doesn't match the string. Like I had said, try printing "dsc.spatialReference.Name" to the console and see what it returns. My guess is there's a typo that's causing the if block to run
    – MattM
    Commented Feb 12, 2020 at 21:48
  • This was a very odd issue. I had run print on dsc previously which produced the following: "NAD_1983_StatePlane_California_III_FIPS_0403_Feet" *However, when trying to output the spatial reference it requires "NAD 1983 StatePlane California III FIPS 0403 (US Feet)" with arcpy.SpatialReference. I have no idea why there is a need for one over the other.
    – Therow
    Commented Feb 12, 2020 at 22:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.