2

My goal is to copy all the feature classes in a file geodatabase into an sde geodatabase, skipping those elements which already exist in the output sde gdb. Both geodatabases have the same feature dataset structure and the sde geodatabase may have empty feature datasets.

To copy feature classes into feature datasets I need the full path of the output feature dataset where I want to copy each. For example, for UrbanData feature dataset it would be sqldb.DBO.UrbanData. To get that information I use this piece of code:

#input parameters
from_bd = r"C:\GISData\Buildings.gdb" #file gdb
to_bd =r"Database Connections\city_dat.sde" #sde connection file

arcpy.env.workspace = from_bd
sdebd = to_bd
datasetList = arcpy.ListDatasets()
desc = arcpy.Describe(sdebd)

for dataset in datasetList:
    for child in desc.children:
        if child.dataType == "FeatureDataset" and child.name == dataset:
            fdset =child.name #the feature dataset full path

And I use it to copy each feature class to the output sde gdb:

    for fc in arcpy.ListFeatureClasses('','',dataset):
        if arcpy.Exists(sdebd + os.sep + fc)==False:
            arcpy.Copy_management(fc, sdebd + os.sep + fdset + os.sep + new_fc)

To my surprise the Children property from arcpy.Describe object won't return empty feature datasets. There's no mention of this behaviour in the Describe Object documentation.
So I need a workaround and I'm a bit stuck. Any ideas?

  • It's not possible to discover an empty feature dataset by listing feature classes (you're querying for a NOT NULL field where all values are NULL). Also, thère is no such thing as an "sde geodatabase" - the term of art is "enterprise geodatabase". – Vince Apr 7 '16 at 11:04
  • 1
    The part of the code that lists feature datasets is right before listing feature classes, so it should return empty feature datasets. Call it enterprise geodatabase, enterprise sde geodatabase, sde geodatabase or ArcSDE geodatabase. You can find any of this trems in Esri documentation. – DMS02 Apr 7 '16 at 11:17
  • arcpy.da.Walk function may do the trick. I'm checking it out. Anyway any ideas are welcome. – DMS02 Apr 7 '16 at 11:44
2

An alternative option to get your fc and fd paths is to use arcpy.da.walk. This code snippet will provide the path of empty fd:

walk = arcpy.da.Walk(workspace, datatype="FeatureDataset")
  for dirpath, dirnames, filenames in walk:
    print dirpath
  • 1
    Yeah, that's what I was checking out and it's my best solution so far. And it's faster than the arcpy.Describe object. – DMS02 Apr 7 '16 at 12:18
1

Using arcy.da.Walk it works and even faster than using the Describe object. So in case it is useful to anyone, this is how my code is now:

import arcpy, os

def ListFeatureDatasets(geodb):
    arcpy.env.workspace = geodb
    for dirpath, dirnames, filenames in arcpy.da.Walk(workspace,datatype="FeatureDataset"):
        return dirnames

def CopyFeatureClasses(from_bd,to_bd):   
    sde_datasetList = []
    sdebd = to_bd
    sde_datasetList = ListFeatureDatasets(sdebd)
    arcpy.env.workspace = from_bd
    datasetList = arcpy.ListDatasets()
    for dataset in datasetList:
        for sde_dataset in sde_datasetList:
            if sde_dataset.split('.')[-1]==dataset:
                sdefd = sde_dataset
        for fc in arcpy.ListFeatureClasses('','',dataset):
            if arcpy.Exists(sdebd + os.sep + fc)==False:
                arcpy.Copy_management(fc, sdebd + os.sep + sdefd + os.sep + fc)

#input parameters
from_bd = r"C:\GISData\Buildings.gdb" #file gdb
to_bd =r"Database Connections\city_dat.sde" #sde connection file

CopyClasesEntidad(from_bd,to_bd)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.