Old thread, but helped me in Arc 10.2 with very little tweaking. Thanks a million, Caleb Mackey.
Works!Only thing is that it only renames the .shp files and none of the associated files (.dbf,.prj, ect.) so the merge gives an error saying it cannot be completed probably because it cannot see the associated filetypes. However, I assume that I can just rewrite this for each of the filetypes and once they are all renamed the merge should work as expected? Fingers crossed.
import arcpy, os ws = "D:/eCognition Results/Landcover/Buildings" arcpy.env.workspace = ws out = "D:/eCognition Results/Landcover/Buildings/Outputs" for file in arcpy.ListFeatureClasses(): arcpy.CopyFeatures_management(file, os.path.join(out,file.replace('.','_')[:-4] + '.shp')) arcpy.env.workspace = out Listing = arcpy.ListFeatureClasses() arcpy.Merge_management(Listing,"MergedFile.shp")
I tried the first one and the logic seems to make sense to me but I get an 'exeptions.NameError'>: name 'ws' is not defined' So I am looking over the rename function to see what those parameters are all about. Can't be far from it now. Again man thanks for all the help.
import arcpy, os ws = "D:/eCognition Results/Landcover/Buildings" arcpy.env.workspace = ws for file in arcpy.ListFeatureClasses(): os.rename(os.path.join(ws,file), os.path.join(ws,file.replace('.','_')[:-4] + '.shp')) Listing = arcpy.ListFeatureClasses() arcpy.Merge_management(Listing,"MergedFile.shp")
Caleb, I went and renamed the files by hand and it worked like a charm. Thanks for the help. Now I just have to get the rename code to work so I don't have to do them all by hand.
import arcpy, os arcpy.env.workspace = "D:/eCognition Results/Landcover/Buildings" for file in arcpy.ListFeatureClasses(): os.rename(os.path.join(ws,file), os.path.join(ws,file.replace('.','_')[:-4] + '.shp')) Listing = arcpy.ListFeatureClasses() arcpy.Merge_management(Listing,"MergedFile.shp")
import arcpy, os arcpy.env.workspace = "D:/eCognition Results/Landcover/Buildings" for file in arcpy.ListFiles('*.shp'): os.rename(os.path.join(ws,file), os.path.join(ws,file.replace('.','_')[:-4] + '.shp')) Listing = arcpy.ListFeatureClasses() arcpy.Merge_management(Listing,"MergedFile.shp")
arcpy.Merge_management(Listing,"MergedFile.shp") Runtime error <class 'arcgisscripting.ExecuteError'>: Failed to execute. Parameters are not valid. ERROR 000732: Input Datasets: Dataset campus_ortho.tiles.tile00.v5.shp;campus_ortho.tiles.tile01.v8.shp;campus_ortho.tiles.tile02.v5.shp;campus_ortho.tiles.tile03.v6.shp;campus_ortho.tiles.tile04.v5.shp;campus_ortho.tiles.tile05.v9.shp;campus_ortho.tiles.tile06.v9.shp;campus_ortho.tiles.tile07.v9.shp;campus_ortho.tiles.tile08.v10.shp;campus_ortho.tiles.tile09.v8.shp;campus_ortho.tiles.tile10.v8.shp;campus_ortho.tiles.tile11.v8.shp;campus_ortho.tiles.tile12.v8.shp;campus_ortho.tiles.tile13.v9.shp;campus_ortho.tiles.tile14.v9.shp;campus_ortho.tiles.tile15.v8.shp;campus_ortho.tiles.tile17.v8.shp;campus_ortho.tiles.tile18.v9.shp does not exist or is not supported Failed to execute (Merge). >>>
import arcpy >>> arcpy.env.workspace = "D:eCognition Results/Landcover/Buildings" >>> Listing = arcpy.ListFeatureClasses() >>> arcpy.Merge_management(Listing,"MergedFile.shp") Runtime error <class 'arcgisscripting.ExecuteError'>: Failed to execute. Parameters are not valid. ERROR 000735: Input Datasets: Value is required Failed to execute (Merge).
import arcpy arcpy.env.workspace = "c:/junk/mergeMe" fcs = arcpy.ListFeatureClasses() arcpy.Merge_management(fcs, "Merged.shp")
import arcpy, os, sys, traceback arcpy.env.overwriteOutput = True # Workspace for interchange files ws = r'C:\IGIC\Beginner\Unit_1\DATA\EffigyMounds\InterchangeFiles' arcpy.env.workspace = ws # Local Variables out = r'C:\IGIC\Beginner\Unit_1\DATA\EffigyMounds\Fire' try: # Creates a folder if it doesn't already exist if not os.path.exists(out): os.makedirs(out) # List all ArcInfo Interchange files (.e00) for cov in arcpy.ListFiles('*.e00'): arcpy.ImportFromE00_conversion(cov, ws, cov.split('.')[0]) print 'Converted %s' %cov # Exclude Interchange files and info folder for cov in arcpy.ListFiles(): if not '.e00' in cov and cov != 'info': arcpy.env.workspace = os.path.join(ws,cov) for fc in arcpy.ListFeatureClasses('*polygon'): arcpy.FeatureClassToFeatureClass_conversion(fc, out, '%s.shp' %cov) shp = os.path.join(out, '%s.shp' %cov) print 'Converted Coverage to %s' %shp # List shapefiles in folder to create input list for merge arcpy.env.workspace = out shplist = arcpy.ListFeatureClasses() arcpy.Merge_management(shplist, os.path.join(out, 'All_Fires.shp')) print 'done' except: # Get the traceback object tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + \ "\nError Info:\n" + str(sys.exc_info()[1]) msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n" arcpy.AddError(pymsg) arcpy.AddError(msgs) # Print Python error messages for use in Python / Python Window print pymsg + "\n" print msgs
import arcpy, os out = r'Output\folder\location' # change this arcpy.env.workspace = r'Some\Path\Name' #change this shplist = arcpy.ListFeatureClasses('*.shp') arcpy.Merge_management(shplist, os.path.join(out, 'Merged_fc.shp')) print 'done'
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.