Edited to Add: 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.
Am a python novice. I used http://support.esri.com/en/knowledgebase/techarticles/detail/40831 as a start and was able to copy FC outside feature datasets in source GDB to a target GDB outside feature datasets, but cannot get it to copy those FC in feature datasets to overwrite FC matches in target feature datasets and when no match found just copy outside feature datasets in target. Any help? Code below.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.
# Name: Merge_Geodatabases_Tool.py# Description: Copy feature classes from one geodatabase to another - # If feature class already exists in target geodatabase,# script will overwrite it into that same location in target, within# feature dataset. If feature class does not exist in# target geodatabase, script will copy it over, but not in a feature# dataset, even if it was in a feature dataset in origin geodatabse.import arcpy, os, stringarcpy.env.overwriteOutput = Truedef FeatureClassToFeatureClass_conversion(start_db,end_db):#Set workspacesarcpy.env.workspace = start_dbwk2 = end_dbdatasetList = arcpy.ListDatasets()#for feature classes within datasetsfor dataset in datasetList: fclist = arcpy.ListFeatureClasses() for fc in fclist: print "Reading: {0}".format(fc) name = arcpy.Describe(fc) new_data=name.name 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)#Clear memorydel fcdef FeatureClassToFeatureClass_conversion(start_db,end_db):#Set workspacesarcpy.env.workspace = start_dbwk2 = end_db#for feature classes not within datasetsfor fc in arcpy.ListFeatureClasses(): print "Reading: {0}".format(fc) name = arcpy.Describe(fc) new_data=name.name 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)if __name__== "__main__": start_db = arcpy.GetParameterAsText(0) end_db = arcpy.GetParameterAsText(1) FeatureClassToFeatureClass_conversion(start_db,end_db)
أكثر...