Skip to content

Instantly share code, notes, and snippets.

@cindygis
Created May 11, 2015 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cindygis/828c4925d668bc7b7f9c to your computer and use it in GitHub Desktop.
Save cindygis/828c4925d668bc7b7f9c to your computer and use it in GitHub Desktop.
Writes certain properties of a feature layer within a group layer to csv.
#
# @date 11/05/2015
# @author Cindy Williams
#
# Writes certain properties of a layer within a group
# layer in a mxd to csv.
#
# For use in the Python window in ArcMap.
#
import arcpy
import csv
mxd = arcpy.mapping.MapDocument("CURRENT")
lyrs = [lyr for lyr in arcpy.mapping.ListLayers(mxd) if lyr.isFeatureLayer]
outcsv = r"C:\Some\Arb\Folder\comp.csv"
with open(outcsv, 'wb') as csvfile:
csvwriter = csv.writer(csvfile)
csvwriter.writerow(["Group Layer Name", "Dataset Name", "Projection", "Number of features"])
for lyr in lyrs:
desc = arcpy.Describe(lyr)
csvwriter.writerow(lyr.longName.split("\\")[0],
lyr.datasetName,
desc.spatialReference.name,
str(len([row[0] for row in arcpy.da.SearchCursor(lyr, desc.OIDFieldName)])))
print("Wrote properties for " + lyr.name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment