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)