Select to view content in your preferred language

Copying features with InserCursor

208
0
07-17-2019 02:35 PM
TonyAlmeida
Frequent Contributor

I have a feature class that i need to update weekly and i can't just delete the feature class because it's tied to programs and applications. So what I have done is use arcpy.DeleteFeatures_management to delete the rows. I have been using Append_Management to update the layer but it takes about 7 mins, there is roughly about 90K features. So i wanted to see i can us InsertCurors and i come up with two different timing. From my understanding is that arcpy.da was suppose to be faster? I am running this in 2.7 python. So which way is right? can this be done with dictionaries and if so how?

First example takes about 3 mins and 29 secs.

arcpy.env.workspace = "Database Connections\***.sde"
for FC2 in arcpy.ListFeatureClasses():
    if FC2.startswith('***.***.TEST_ALL_'): 
        pass
FC3 = "Database Connections\***.sde\****\***.TEST\***.***.PT_Test"  

searchCur = arcpy.SearchCursor(FC2)
inCur = arcpy.InsertCursor(FC3)

for Row in searchCur:
    inCur.insertRow(Row)
del inCur   

The second one takes 5 mins and 45 secs.

arcpy.env.workspace = "Database Connections\***.sde"
for FC2 in arcpy.ListFeatureClasses():
    if FC2.startswith('***.***.TEST_ALL_'): 
        pass
FC3 = "Database Connections\***.sde\****\***.TEST\***.***.PT_Test"  

with arcpy.da.InsertCursor(FC3, ["SHAPE@", "*"]) as iCursor:
    with arcpy.da.SearchCursor(FC2, ["SHAPE@", "*"]) as sCursor:
        for row in sCursor:
            iCursor.insertRow(row)
0 Kudos
0 Replies