Increasing speed of Python scripts using arcpy

المشرف العام

Administrator
طاقم الإدارة
Update 4/11/2014

It looks like the script was getting hung up on the Delete Features tool, so I switched to Truncate Table, as suggested in the answer below. I also removed the unused variables from the append tool.

Update 4/10/2014

I ran this script on my co-worker's computer (his machine has more memory AND contains ArcGIS 10.0/Python26) and it ran quickly. Hooray! Once my tech support finds the ArcGIS 10.0 CD, I will install and test to see if that improves the speed on my machine. To be clear, we are running the same script, our network drive and database connection are mapped identically, and the print statements are the same. I'll post an update here once that happens.

End updates

I need to increase the speed of some Python scripts that perform updates on an Oracle database. I had these Python scripts running well for a year+, via scheduled tasks and batch files to initiate the scripts. Last week I moved from an XP to a Windows 7 machine and ArcGIS 10.0 --> 10.1. Since then the scripts have become terribly slow. If I run this script using a small feature class (containing ~20 features) it runs in 30 seconds. If I use a medium feature class (~80,000 records) it runs in 15 minutes. The feature class I really need to be able to transfer quickly contains about 1,000,000 records - the script only goes as far as the print statement to check if the files exist (if statement in code below). This process would take only 35 minutes to complete on my XP/ArcGIS 10.0 machine.

Below is the simplified code I have been testing with. Does anyone have suggestions on what I can do to increase the speed? Thanks, Patty

import arcpy, os, sys from arcpy import env arcpy.env.overwriteOutput = True from datetime import datetime import smtplib import string import urllib #Define variables inWorkspace = "O:/LANDING_PAD/BOE/example.gdb" lpFeatures = inWorkspace + os.sep + "fc1" outWorkspace = "Database Connections\\THIS.sde" arcpy.env.workspace = outWorkspace workspace = "" copyFC = outWorkspace + os.sep + "SDE.fc1_1" #The feature class the script will update via delete and append schema_type = "NO_TEST" fieldMappings = "" subtype = "" t = datetime.now() print "This script began at: " + str(t) if arcpy.Exists(lpFeatures) is True and arcpy.Exists(copyFC) is True: print "Both files exist. Beginning delete..." arcpy.DeleteFeatures_management(copyFC) #(copyFC) print "ALL DONE DELETING!" arcpy.Append_management(lpFeatures, copyFC, schema_type, fieldMappings, subtype) #Append data from landing pad to db print "ALL DONE APPENDING!" record_count = arcpy.GetCount_management(lpFeatures) print record_count r = datetime.now() print "This script ended at: " + str(r)

أكثر...
 
أعلى