I have mxd's that have information loaded from many different locations (some FCs from FGDB, shps, FCs in EGDB) and I want to check the coordinate reference system quickly for them. I have attempted the code below but get a error on line 16 for unsupoported operand type for +: 'layer' and 'str'.

import arcpy

mxd = arcpy.mapping.MapDocument("CURRENT")  # Uses your currently open MXD
df = arcpy.mapping.ListDataFrames(mxd, '')[0] # Chooses the first dataframe
layerlist = arcpy.mapping.ListLayers

for layer in layerlist(mxd, '', df): # Loop through layers
    sr = arcpy.Describe(layer).spatialReference
    if sr.name == "Unknown":
        print layer + " has an unknown spatial reference\n"

    # Otherwise, print out the feature class name and
    #   spatial reference
    print layer + ": " + sr.name + "\n"
  • 2
    Should the else line have the same indentation as the if statement?
    – mkennedy
    Sep 4 '17 at 18:38
  • 5
    Use layer.name + sr.name
    – FelixIP
    Sep 4 '17 at 18:46
  • 1
    and use spatialReference.type (if sr.type == 'Unknown':) instead of sr.name resources.arcgis.com/en/help/main/10.2/index.html#//… . If you create a spatial reference with parameters the name could be 'Unknown' but the spatial reference is not unknown, just custom. Spatial reference type property knows if the spatial reference is Geographic, Projected or Unknown, even if it is custom. It's also a good idea to check if a layer is feature (isFeatureLayer) or raster and if it is indeed valid (isBroken == False). Sep 4 '17 at 20:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.