Merging all feature classes with the same name nested in multiple geodatabases using ArcPy?
Here is the code:
Anyone kindly, assist me in resolving/modifying this code!
I am getting the result (merge feature) but only one feature class (probably last FC of the iteration), how can I make it work for all the iterating FCs.
Don't hesitate to ask for more clarity.
Solved! Go to Solution.
Does this work for you:
import arcpy
import os
input_ws = # path to workspace to search for feature classes
output_ws = # path to workspace for merged feature classes
walk = arcpy.da.Walk(input_ws, datatype="FeatureClass")
di = {}
for root, dirs, files in walk:
for name in files:
di.setdefault(os.path.splitext(name)[0], []).append(os.path.join(root, name))
for name in di:
arcpy.Merge_management(di[name], os.path.join(output_ws, name)
Does this work for you:
import arcpy
import os
input_ws = # path to workspace to search for feature classes
output_ws = # path to workspace for merged feature classes
walk = arcpy.da.Walk(input_ws, datatype="FeatureClass")
di = {}
for root, dirs, files in walk:
for name in files:
di.setdefault(os.path.splitext(name)[0], []).append(os.path.join(root, name))
for name in di:
arcpy.Merge_management(di[name], os.path.join(output_ws, name)
Thanks, it worked!!!
So nice of you, now i am wondering how i can make the destination structure is same as Source, please refer following:
Thanks to your code, it worked and gives me merge feature in the destination gdb but merge fcs inside GDB not like in source GDB structure ie Six FCS in feature dataset and one in GDB (outside dataset).Can you help me in doing that also,
Thanks in advance.:)
This new requirement will involve changing part of the code. I don't have time right now to look into it, but I may revisit it sometime this week. In the meantime, moving 6 feature classes into a feature dataset in the final GDB isn't time consuming by hand.
Hi,
I know it has been while since this was posted, but I am trying to do a similar thing for work. All of the features get put into their own feature classes, which is great, but a lot of the attribute data gets lost in this process. Should I be using a different method to combine data if I am worried about maintaining attribute integrity as well as spatial integrity? I am still learning python/arcpy and everything, so any help is greatly appreciated.
Thanks!