Friday 1 March 2019

arcpy - Iterating through layers in mxd and describing coordinate system


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
else:
print layer + ": " + sr.name + "\n"


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...