Merge Fcs of Same name from multiple GDBs into new/Seprate GDB?

1279
4
Jump to solution
06-17-2019 04:00 AM
VaibhavSingh_ESRI_GIS
New Contributor III

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.

0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

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)

View solution in original post

4 Replies
JoshuaBixby
MVP Esteemed Contributor

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)
VaibhavSingh_ESRI_GIS
New Contributor III

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.:)

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

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.

DanielK2
New Contributor

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!

0 Kudos