Merge Feature Classes within a GDB into one Feature Dataset?

2795
6
08-02-2016 03:09 PM
HollyBiery
New Contributor II

I need to pull multiple feature classes within a GDB into one Feature Dataset. I am still new at Python and  am unsure of the correct structure needed to merge all of the FC into one FD. Sorry for the limited Python knowledge, I am trying to grasp the basic structure to run this simple code.

Would it look something close to this? I don't know if I did the input parameter correctly.

0 Kudos
6 Replies
DanPatterson_Retired
MVP Esteemed Contributor

line 8 is not needed, you could simply exit or print an error message

add

import sys

to the top of the script, then test to see if datasets is empty and if it is

print("exiting, nothing to work on")

sys.exit()

line 18 is indented improperly

Now did you get error messages? cause it is hard to comment further without testing

HollyBiery
New Contributor II

why is import sys needed?

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

in order to use sys.exit() should you wish to bail when a condition isn't meet... sometimes it is better to bail than fail

0 Kudos
RebeccaStrauch__GISP
MVP Esteemed Contributor

If this is a one type thing, you may just want to use on of the tools already available.  Of course it will depend on what the data is you are trying to combine....same type? same data structure?  same coordinate system?  If any thing is different, it could complicate things, andcdepending on the input, it may be easier to massage the data before combining.

Merge—Help | ArcGIS for Desktop

Merge....Combines multiple input datasets of the same data type into a single, new output dataset. This tool can combine point, line, or polygon feature classes or tables.

Use the Append tool to combine input datasets with an existing dataset.

edit...my guess is you are using this as an exercise to learn python.....I'll bow out to Dan, since it looks like he is on the task to help.... 

HollyBiery
New Contributor II

I will need to do this on multiple GDB's so I think that a python code would be the fastest way to manage it. All of the data is in the same Coordinate system and has the same structure, so I don't believe that should be an issue.

0 Kudos
DarrenWiens2
MVP Honored Contributor

You need to add all of the feature class paths to be merged into a list, which will be the first parameter in the Merge tool.

So, something along the lines of (obviously, pseudocode):

for ds... # loop datasets
    mylist = [] # empty list for each dataset
    for fc... # loop feature classes
        mylist.append(os.path.join(...)) # add path to list
    Merge(mylist,...) # merge list for each dataset