Script to load multiple features into already existing feature class?

3255
4
08-06-2014 10:26 AM
SharonLitteral
New Contributor II

I have an existing feature class in a file gdb.  I am trying to write a python script to load data from a SQL2012 gdb.  I am new to this.  Normally, I would just drop a tool into modelbuilder and convert it to a python script.  However, I do not know how to do this with the Simple data loader that I use in ArcCatalog.  I would think that someone has already done this.  Any help is appreciated.

0 Kudos
4 Replies
SharonLitteral
New Contributor II

Okay, so I wrote the script to load or append data to an existing feature class.  First, I use arcpy.ListFeatureClasses and get a list of the feature classes from my source feature dataset.   I then loop through each one of the feature classes in the list above and:

     1.  Use arcpy.Describe and create a list containing all of the field names in the source

     2. Use arcpy.SearchCursor on my source feature dataset and for each row in this cursor I loop through and

     3. Use arcpy.InsertCursor.newRow and create a new row in my target dataset

     4. Then for each field name in the list of field names from 1. above I loop through and populate that field value in my  new row with the value from the source (I use getValue and setValue)

     5. Finally, I use the InsertCursor from 3. above and use the method insertRow to update the row in my target database.

     6. I clean up my cursors.

This all works, however it takes a long time to do this.

Does anyone have any experience with tuning the python performance or suggestions for how to modify my logic above to increase performance?

DarrenWiens2
MVP Honored Contributor

You can improve performance by using the cursors in the data access module‌. So, arcpy.da.SearchCursor rather than arcpy.SearchCursor, and arcpy.da.InsertCursor rather than arcpy.InsertCursor.

0 Kudos
IanMurray
Frequent Contributor

Note the parameter order changes slightly between da Cursors and standard Cursors

0 Kudos
DarrenWiens2
MVP Honored Contributor

^ their entire use is quite different.

0 Kudos