copy features - works only for Points?

325
2
11-18-2013 11:04 AM
MartinHvidberg
Occasional Contributor
Hi All

I'm writing a arcpy script to copy many feature classes from one workspace (file geo database) to another. It's important for me that the script works between existing feature classes, i.e. Not try to create new feature classes, but appends the copied features as new features to the existing feature classes.

If you know Batch-Copy-Paste, this is the same, only without messing up the PLTS_Compilation info.

Due to the above requirements it seemed out of the question to use either of:
arcpy.CopyFeatures_management()
arcpy.FeatureClassToGeodatabase_conversion()
arcpy.FeatureClassToFeatureClass_conversion()
arcpy.Copy_management()
even with the 'overwrite output' turned on, as they all aim at creating a new output feature class.

I therefore decided to go row-by-row with a Search-cursor and an Insert-cursor.
The two .gdb already exist, and have identical structure (schema) but the output.gdb holds no features in the feature classes

The script looks like this:

import os, arcpy
 
def inventory_data(workspace, datatypes):
    for path, path_names, data_names in arcpy.da.Walk(workspace, datatype=datatypes):
        for data_name in data_names:
            yield os.path.join(path, data_name)

def match_feature_names(FA,lstFB):
    FAName = FA[FA.rfind("\\")+1:]
    for FB in lstFB:
        if FAName in FB:
            return FB
    return False

#Main
genWSA = inventory_data(r"C:\data\input.gdb", "FeatureClass")
lstWSA = list(genWSA)
genWSB = inventory_data(r"C:\data\output.gdb", "FeatureClass")
lstWSB = list(genWSB)

for FCA in lstWSA:
    print "Copying:"+FCA
    lst_field_names = [fldX.name for fldX in arcpy.ListFields(FCA)]
    curWrite = arcpy.da.InsertCursor(match_feature_names(FCA,lstWSB),lst_field_names)
    with arcpy.da.SearchCursor(FCA,"*") as curRead:
        for row in curRead:
            curWrite.insertRow(row)
    del curRead,curWrite        
       
  
For some reason it only works well for Point feature classes. Any Line or Polygon feature class have the attributes copied correctely, but the 'shape' is empty. Also the length- and area-field holds only 0 (zero) in all output rows
Any suggestion are appreciated.

Best regards
Martin
Tags (2)
0 Kudos
2 Replies
RobertBorchert
Frequent Contributor III
Is there a reason why you are not simply copying them from one filegeodatabase to the other in Catalog?
0 Kudos
MartinHvidberg
Occasional Contributor
Is there a reason why you are not simply copying them from one filegeodatabase to the other in Catalog?


Yes - Two reasons.
1) Copying like that would not append features to an existing feature class, it would create a new feature classe with a '_1' name.
2) It would be time consuming. The data bases have 20-30 Feature classes, with potentially hundreds of subtypes (though they are not all populated). I need to do it often, so I would like it to be automatic.

I have used the Batch-Copy-Paste tool. But the data base is multi-scale, and batch-copy-paste don't honour that, it puts the default Production Compilation Scale on all output features.

/M
0 Kudos