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
# 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) else: # 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 print(arcpy.GetMessages())