Skip to content

Instantly share code, notes, and snippets.

@amarinelli
Created January 9, 2015 22:30
Show Gist options
  • Save amarinelli/bac1dc95a2c4aad00e86 to your computer and use it in GitHub Desktop.
Save amarinelli/bac1dc95a2c4aad00e86 to your computer and use it in GitHub Desktop.
This script using arcpy to consolidate all the feature layers in a map document into a single File GDB
import arcpy
import time
import os
mxd = arcpy.mapping.MapDocument(r'C:\<path>\<to>\<map>.mxd')
dfs = arcpy.mapping.ListDataFrames(mxd)
file_gdb = r'C:\<path>\<to>\<file>.gdb'
def copy_features(in_layer):
try:
if arcpy.Exists(os.path.join(file_gdb, layer.datasetName)):
print 'Already exists, renaming'
new_name = in_layer.datasetName + str(time.time())
else:
new_name = layer.datasetName
arcpy.CopyFeatures_management(layer, os.path.join(file_gdb, new_name))
except:
print 'Error copying', layer.name
for df in dfs:
print 'Dataframe:', df.name
layers = arcpy.mapping.ListLayers(mxd, '', df)
for layer in layers:
if layer.isFeatureLayer:
print 'Copying:', layer.name
copy_features(layer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment