1

Objective - I have a target GDB "schema" with set feature dataset names and feature classes (no features) within them. I want to copy submittal geodatabase feature classes into that target. I first reproject the target to match the submittal coordinate system.

What I want to do with python is copy all feature classes from the submittal over to the target, where if a submittal feature class name matches one in the target GDB, I want to replace it in the target GDB in the feature dataset location where the empty feature class was in the target. If submittal feature class has no name match in target GDB, I want to copy it over to the target GDB outside any feature dataset.

I am a python novice. I used http://support.esri.com/en/knowledgebase/techarticles/detail/40831 as a start and now got code (below) to work to copy all feature classes from the source GDB to the target GDB, deleting out feature classes within feature datasets with matching names between the source and target GDBs, but I can't get it to put the source feature classes in the feature datasets where the matched name feature classes are in the target, it just puts them in no feature dataset in the GDB.

UPDATE: Code does work when I make a copy of my submittal database. This revealed that code didn't work as intended because the reproject I do on my target database feature datasets initially isn't truly bringing in all the spatial reference information. In order to get this to work the way I want, I believe I have to add code to create new feature datasets in the target GDB with same names as the target feature datasets with spatial reference information from the submittal feature datasets, then copy over feature classes where names submittal names match target names, then delete the original target feature datasets (or overwrite when creating).

Code snippet below updated per comment instruction:

import arcpy, os, string

arcpy.env.overwriteOutput = True

def FeatureClassToFeatureClass_conversion(start_db,end_db):

#Set workspaces
arcpy.env.workspace = start_db
wk2 = end_db
datasetList = arcpy.ListDatasets()

#for feature classes within datasets
for dataset in datasetList:
    fclist = arcpy.ListFeatureClasses("*","",dataset)
    for fc in fclist:
        print "Reading: {0}".format(fc)
        name = arcpy.Describe(fc)
        new_data=name.name
        if arcpy.Exists(wk2 + os.sep + new_data)==True: 
            arcpy.Delete_management(wk2 + os.sep + new_data)
            arcpy.Copy_management(fc, wk2 + os.sep + new_data)
            print "Completed copy on {0}".format(new_data)          
        else:
            arcpy.Copy_management(fc, wk2 + os.sep + new_data)
            print "Completed copy on {0}".format(new_data)
#Clear memory
del fc

if __name__== "__main__":
    start_db = arcpy.GetParameterAsText(0)
    end_db = arcpy.GetParameterAsText(1)
    FeatureClassToFeatureClass_conversion(start_db,end_db)
  • I am a bit unclear about what your ultimate objective is. It would be helpful to create a step-wise outline of what you hope to accomplish. Also, what would your final product look like? Why not simply make a copy of the whole FGDB at another location? – Aaron Aug 1 '15 at 20:59
  • Thanks Aaron, I edited post to try to explain better. I don't want an exact copy, because I'm trying to move the feature classes with specific names to a set of standard feature datasets where those feature classes "belong" based on name matches. If no name match, I just want them outside feature datasets in the target GDB. – augni Aug 1 '15 at 21:12
  • 2
    The indentation of your Python functions seems astray and I think defining one function to have the same name as an ArcPy function, let alone two, is likely to cause unpredictability. I think you should set this code aside and start a new test script into which you copy a line or two at a time. As soon as you see it do something unexpected is the time to research/ask about it here. – PolyGeo Aug 1 '15 at 23:58
  • I simplified it to just the part I'm having trouble with, I'm just not sure what line it is exactly that I need to alter to get it to execute, something in the arcpy.Copy_management to get it to the correct target feature dataset I believe. – augni Aug 2 '15 at 0:52
  • Updating post - code does work, just not with the feature datasets in my target GDB due to something still off with the spatial references. – augni Aug 2 '15 at 4:59
1

if there is a name match in your target database, it migt be easier & perform faster to

  • purge the target feature class (delete the objects, not the class itself)

  • define its projection to match that of the submittal feature class. Two big assumptions here: the target featue class is NOT in a feature dataset AND the attribute table structure is identical. So this depends on your workflow.

  • append the records from the submittal feature class.

Otherwise, for your projection issues, you can try setting the environmental variables

    arcpy.env.outputCoordinateSystem

and, if necessary:

    arcpy.env.geographicTransformations 

Last, it seems to me that your statement

    wk2 + os.sep + new_data

references the target database and the feature class name, this is why you are creating standalone feature classes. You should explicitly include the target dataset name in there, something along the lines of:

    wk2 + os.sep + dataset + os.sep + new_data

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.