Select to view content in your preferred language

Copy Feature Dataset from one FDGB to another -S imple?

6230
8
08-30-2012 10:06 AM
MikeBly
Regular Contributor
hope there is some who can help answer my seemingly simple question. All I want to do is have a script that copies select feature datasets from  a fgdb to another existing fgdb.

Any ideas as to which functions to use?

Be kind I am a newbie to Python.

Cheers,

Mike
Tags (2)
0 Kudos
8 Replies
by Anonymous User
Not applicable
Mike,

You can use the ListDatasets function.

arcpy.env.workspace = r"C;\\CountyData\\County.gdb'
outpath = r"C:\\Test\\test.gdb"
flist = arcpy.ListDatasets('*WildCard*', {feature_type})

for f in flist:
    output = outpath + os.sep + f
    arcpy.CopyFeatures_management(f, output)
    



http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v0000001m000000
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000035000000
0 Kudos
MikeBly
Regular Contributor
Thanks Caleb, this is exactly what I was looking for. I had tried something similar, but this worked and mine did not. Just a bit more to add to make it all work. I knew this part should be very simple.

Cheers.
0 Kudos
MikeBly
Regular Contributor
How would I enter into the code, only select certain datasets? Is this done through the wildcard. For example there are about 10 datasets, I only want to copy 4 of them.

THanks,

mike

Mike,

You can use the ListDatasets function.

arcpy.env.workspace = r"C;\\CountyData\\County.gdb'
outpath = r"C:\\Test\\test.gdb"
flist = arcpy.ListDatasets('*WildCard*', {feature_type})

for f in flist:
    output = outpath + os.sep + f
    arcpy.CopyFeatures_management(f, output)
    



http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v0000001m000000
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000035000000
0 Kudos
by Anonymous User
Not applicable
Yes you can do it through the wild card.  The way you set it up depends on how the feature data sets are named.  If the ones you are interested in have something common in the name you can use the wildcard operator for that.  For example if this is a list of feature datasets in a gdb: Cedar_addresses, Cedar_roads, Johnson_addresses, Johnson_roads, Cedar_ parcels, Scott_roads, Scott_parcels, Johnson_parcels you can use the following:

arcpy.env.workspace = r"C;\\CountyData\\County.gdb'
outpath = r"C:\\Test\\test.gdb"
flist = arcpy.ListDatasets('Cedar*')

for f in flist:
    output = outpath + os.sep + f
    arcpy.CopyFeatures_management(f, output)


This will return a list of Cedar_addresses, Cedar_roads, and Cedar_parcels and copy those into another gdb.  You can also use the feature type to return Feature Classes, Feature datasets, CAD data, tables, or coverages ect.  What are the names of the datasets you need to copy?
0 Kudos
MikeBly
Regular Contributor
There are 5 i need to copy out: Currently residing in an SDE with several more datasets, with no common naming:

Managed
Public
Reference
TCA
Anno

Through ArcCatalog each one of these has the SDE naming in front:

COL_LCT_SDE.Managed

If I could pull all 5 of these data sets out from the rest that would be the idea. The arcpy.ListDatasets only allows for two arguments to be passed in, wildcard and datatype. I tried entering in the multiple dtaset names, but of course it only pulls out the first in the list and then stops.

Mike
0 Kudos
by Anonymous User
Not applicable
This proved to be much trickier than I expected!  I'm still a novice python scripter (as you will see from my provided solution here).

Just to warn you, this IS ugly and probably not very practical.  Hopefully a better programmer will see this thread and give you a better solution.  This does work though.

import arcpy, os, sys, traceback
arcpy.env.workspace = r"G:\Testing\USA.gdb"
arcpy.env.overwriteOutput = True
outpath = r"G:\testing2\new.gdb"
pre = 'COL_LCT_SDE.'



try:
    fdlist = arcpy.ListDatasets('*', "Feature")
    tocopy1 = pre + 'Managed'
    tocopy2 = pre + 'Public'
    tocopy3 = pre + 'Reference'
    tocopy4 = pre + 'TCA'
    tocopy5 = pre + 'Anno'


    for fd in fdlist:
        pastefd = outpath + os.sep + str(fd)

        if fd == tocopy1:
            arcpy.Copy_management(fd, pastefd)

        if fd == tocopy2:
            arcpy.Copy_management(fd, pastefd)

        if fd == tocopy3:
            arcpy.Copy_management(fd, pastefd)

        if fd == tocopy4:
            arcpy.Copy_management(fd, pastefd)

        if fd == tocopy5:
            arcpy.Copy_management(fd, pastefd)

except:
    arcpy.AddError(arcpy.GetMessages(2))


If you don't want the 'COL_LCT_SDE.' in front of the name you can use the strip function in the "pastefd" variable.

Another thought though, if these files are not too large you could simply copy the gdb and use the arcpy.Delete_management to remove any unwanted datasets.
0 Kudos
MikeBly
Regular Contributor
Thanks for this. This is the thought process i was on, but could not wrap my head around how to execute it. I will implement this and see how it goes - may be ugly, but if it works, great.

I would copy the whole database, and remove the unwanted datasets, however the gdb is 90gb, so it would take a long time too run.

Thanks again, I will let you know how this goes or does not go.

Cheers,

Mike
0 Kudos
MikeBly
Regular Contributor
This worked well when going from FGDB to FGDB on same server, now I am attempting to use the same process to go from SDE to FGDB on a different server.

I have no syntax errors, no errors are returned, I run the script, it runs, but way too fast to have done anything, so I am curious if anyone can see where I may be going wrong.

I think it has to be a workspace issue, but cannot figure out. Here is the code: was not sure how to put code into its own window within this message

# Import system modules
import arcpy
from arcpy import env
import os, sys, traceback

# Set environment settings
arcpy.env.workspace = r"Database Connections\\COL_LCT_SDEOWNER.sde\\"
##arcpy.env.overwriteOutput = True

# Set local variables
outpath = r"I:\\ROBOTEST.gdb"
pre = 'COL_LCT_SDE.'

# Copy feature datasets to new FGDB
try:
    fdList = arcpy.ListDatasets("*","Feature")
    fdcopy1 = pre + 'ManagedData'
    fdcopy2 = pre + 'PublicWorks'
    fdcopy3 = pre + 'Annotation'
    fdcopy4 = pre + 'TCA'
    fdcopy5 = pre + 'ReferenceData'

    for fd in fdList:
        pastefd = outpath + os.sep + str(fd)

        if fd == fdcopy1:
            arcpy.Copy_management(fd, pastefd)

        if fd == fdcopy2:
            arcpy.Copy_management(fd, pastefd)

        if fd == fdcopy3:
            arcpy.Copy_management(fd, pastefd)

        if fd == fdcopy4:
            arcpy.Copy_management(fd, pastefd)

        if fd == fdcopy5:
            arcpy.Copy_management(fd, pastefd)

except:
    arcpy.AddError(arcpy.GetMessages(2))
                  
   
del fdList
0 Kudos