Created
January 9, 2015 22:30
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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