I'm attempting to use a script to check a folder of data sets to see if they match a projection of another data set in a target folder. I need to be able to re project any that don't match the same projection as the file in the target folder and then copy the datasets to a projected folder. If the projections do match I need to copy this to the projected folder without re projecting.

I'm coming unstuck with my if/else statement at line 28 where:

if srcDesc.SpatialReference.Name == targetDesc.SpatialReference.Name:

When i run the script via a custom toolbox in Arcmap 10.4 i get the following error:

***line 27, in <module>

 if srcDesc.SpatialReference.Name==targetDesc.SpatialReference.Name:
AttributeError: DescribeData: Method SpatialReference does not exist***

My code is not perfect in other areas and I'm hoping someone may be able to help me work out where I've gone wrong? Please excuse the over excessive commenting also :)

I'm thinking my error is something to do with describing the two datasets and with the spatialReference usage.

# Import arcpy module
import arcpy
import os

# Get input, target projection and output locations
datasetFolder = arcpy.GetParameterAsText(0)
targetProjectionDataset = arcpy.GetParameterAsText(1)
projectedDataset = arcpy.GetParameterAsText(2)

# set workspace to the dataset folder
arcpy.env.workspace = datasetFolder

# returns a list of files in the dataset folder
for inputFC in arcpy.ListFeatureClasses():

    # Use AddMessage to print feature classes in dataset folder
    arcpy.AddMessage("Datasets in the dataset folder are: " + str(inputFC))

    # describe the dataset in the dataset folder
    srcDesc = arcpy.Describe(inputFC)

    # describe the target dataset
    targetDesc = arcpy.Describe(targetProjectionDataset)

    outputFC = projectedDataset

    # test for matching coord systems
    if srcDesc.SpatialReference.Name == targetDesc.SpatialReference.Name:
        arcpy.CopyFeatures_management(inputFC, outputFC)
        # set the output name to match the input name
        outputNewFC = os.path.join(projectedDataset, inputFC)

        # Set projection to be used
        outCS = arcpy.SpatialReference(targetDesc)

        # run projection tool
        arcpy.Project_management(datasetFolder, outputNewFC, outCS)

        # check messages
  • it needs to be srcDesc.spatialReference.Name with the "S" being lowercase as it is a class property.
    – crmackey
    Commented Apr 14, 2016 at 0:25
  • Thanks mate! Turns out I didn't have the correct parameters set when I added my script to my custom tool box :(
    – Dave.m
    Commented Apr 16, 2016 at 7:27

1 Answer 1


I did a test with this code and it worked (tested in Python terminal in Arcgis 10.3)

import arcpy
src1 = r"D:\layer1.shp"
src2 = r"D:\layer2.shp"
srcDesc1 = arcpy.Describe(src1)
srcDesc2 = arcpy.Describe(src2)
if srcDesc1.spatialReference.Name == srcDesc2.spatialReference.Name:
    print("no match")

I already knew the results would produce no match as the CRS are different. I also tried using layers with matching CRS and the results were match.

In this code I have used .spatialReference.Name with a lower case s as referenced on this site.

  • 1
    You could also use the factoryCode property which is an integer value. Just as an alternative.
    – dslamb
    Commented Apr 14, 2016 at 12:32
  • 1
    @tsvGis Thanks for the help. I had some parameters set incorrectly within my Arc custom toolbox! I fixed those and it seems to work. Thank-you again!
    – Dave.m
    Commented Apr 16, 2016 at 7:28
  • 1
    @dslamb Using the factory code actually worked first attempt for me once I got my toolbox parameters correct! Thanks so much for the knowledge!!
    – Dave.m
    Commented Apr 16, 2016 at 7:29

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.