Hi, I create a model that use 15 tools. I export this model in python. The model takes 35 secondes to run and the python script takes 13 minutes to run. they do the same thing and use the same tools(same geoprocessing tools) and the result is the same! I tried to modify the script to increase performance but no gains.
Somebody can explane that?
It is possible to increase performance of the script?
I use ArcGis 9.3
Thanks,
SCRIPT:
# ---------------------------------------------------------------------------
# delete_duplicates.py
# Created on: Wed Feb 02 2011 11:21:49 AM
# (generated by ArcGIS/ModelBuilder)
# Usage: delete_duplicates <block9>
# ---------------------------------------------------------------------------
# Import system modules
import sys, string, os, arcgisscripting
# Create the Geoprocessor object
gp = arcgisscripting.create()
gp.overwriteoutput = 1
# Load required toolboxes...
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Analysis Tools.tbx")
try:
# Script arguments...
fc = string.replace(gp.getparameterastext(0),"\\","/")
block9 = fc
if block9 == '#':
block9 = "block9" # provide a default value if unspecified
# describe...
descfc = gp.describe(fc)
sr = descfc.spatialreference
dt = descfc.datatype
cp = descfc.catalogpath
gp.addmessage("datatype :" + dt)
#Process the feature class attributes (worckspace)
lstfc = string.split(cp,"\\")
#gp.addmessage("split_fc :" + lstfc)
for fl in lstfc:
gp.addmessage("split_cp_fl :" + fl)
fn = fl
gp.addmessage("fn :" + fn)
strWorkspace = string.replace(cp,fn,"")
gp.addmessage("ws :" + strWorkspace)
gp.workspace = strWorkspace
# Local variables...
Layer = "Layer"
doublon_stat_dbf = "C:\\Temp\\doublon_stat.dbf"
def clearall():
all = [var for var in globals() if var[0] != " _ "]
for var in all:
del globals()[var]
if dt in "ShapeFile, FeatureLayer" :
gp.addmessage("Traitement des shapes")
# Process: Add Field...
gp.addmessage("Add field...")
gp.AddField_management(fc, "dd", "SHORT", "", "", "", "", "NON_NULLABLE", "NON_REQUIRED", "")
# Process: Add Field (2)...
gp.AddField_management(fc, "iddd", "LONG", "", "", "", "", "NON_NULLABLE", "NON_REQUIRED", "")
# Process: Make Feature Layer...
gp.addmessage("Make...")
gp.MakeFeatureLayer_management(fc, Layer)
#,"", "", "FID_block9 FID_block9 VISIBLE NONE;AREA AREA VISIBLE NONE;PERIMETER PERIMETER VISIBLE NONE;FMFOBJID FMFOBJID VISIBLE NONE;POLYID POLYID VISIBLE NONE;POLYTYPE POLYTYPE VISIBLE NONE;YRSOURCE YRSOURCE VISIBLE NONE;SOURCE SOURCE VISIBLE NONE;FORMOD FORMOD VISIBLE NONE;DEVSTAGE DEVSTAGE VISIBLE NONE;YRDEP YRDEP VISIBLE NONE;OYRORG OYRORG VISIBLE NONE;OSPCOMP OSPCOMP VISIBLE NONE;OLEADSPC OLEADSPC VISIBLE NONE;OAGE OAGE VISIBLE NONE;OHT OHT VISIBLE NONE;OCCLO OCCLO VISIBLE NONE;OSI OSI VISIBLE NONE;OSC OSC VISIBLE NONE;UYRORG UYRORG VISIBLE NONE;USPCOMP USPCOMP VISIBLE NONE;ULEADSPC ULEADSPC VISIBLE NONE;UAGE UAGE VISIBLE NONE;UHT UHT VISIBLE NONE;UCCLO UCCLO VISIBLE NONE;USI USI VISIBLE NONE;USC USC VISIBLE NONE;INCIDSPC INCIDSPC VISIBLE NONE;VERT VERT VISIBLE NONE;HORIZ HORIZ VISIBLE NONE;PRI_ECO PRI_ECO VISIBLE NONE;SEC_ECO SEC_ECO VISIBLE NONE;ACCESS1 ACCESS1 VISIBLE NONE;ACCESS2 ACCESS2 VISIBLE NONE;MGMTCON1 MGMTCON1 VISIBLE NONE;MGMTCON2 MGMTCON2 VISIBLE NONE;MGMTCON3 MGMTCON3 VISIBLE NONE;VERDATE VERDATE VISIBLE NONE;SENSITIV SENSITIV VISIBLE NONE;BED BED VISIBLE NONE;STKG STKG VISIBLE NONE;FID_index_ FID_index_ VISIBLE NONE;OBJECT_ID OBJECT_ID VISIBLE NONE;nom nom VISIBLE NONE;BUFF_DIST BUFF_DIST VISIBLE NONE;dd dd VISIBLE NONE;racc racc VISIBLE NONE;iddd iddd VISIBLE NONE")
# Process: Calculate Field (5)...
gp.addmessage("Calculates...")
gp.CalculateField_management(Layer, "dd", "0", "PYTHON", "")
# Process: Calculate Field (4)...
gp.CalculateField_management(Layer, "iddd", "!FID!", "PYTHON", "")
# Process: Calculate Field...
expression = "!shape.area@SQUAREMETERS!"
gp.CalculateField_management(Layer, "AREA", expression, "PYTHON", "")
# Process: Summary Statistics...
gp.addmessage("Satistiques...")
gp.Statistics_analysis(Layer, doublon_stat_dbf, "AREA COUNT;iddd MAX", "AREA")
# Process: Add Join...
gp.addmessage("Join...")
gp.AddJoin_management(Layer, "AREA", doublon_stat_dbf, "AREA", "KEEP_ALL")
# Process: Select Layer By Attribute...
gp.addmessage("Select1...")
gp.SelectLayerByAttribute_management(Layer, "NEW_SELECTION", "\"FREQUENCY\" > 1")
# Process: Calculate Field (2)...
gp.CalculateField_management(Layer, "dd", "3", "PYTHON", "")
# Process: Select Layer By Attribute (2)...
gp.addmessage("Select2...")
gp.SelectLayerByAttribute_management(Layer, "NEW_SELECTION", "\"iddd\" = \"MAX_iddd\"")
# Process: Calculate Field (3)...
gp.CalculateField_management(Layer, "dd", "4", "PYTHON", "")
# Process: Select Layer By Attribute (3)...
gp.addmessage("Select3...")
gp.SelectLayerByAttribute_management(Layer, "NEW_SELECTION", "\"dd\" =3")
# Process: Delete Features...
gp.addmessage("Delete...")
gp.DeleteFeatures_management(Layer)
# Process: Delete...
gp.Delete_management(Layer, "")
else:
gp.addmessage("Traitement des autres type non développé")
#Summary message
gp.addmessage( "features processed")
clearall()
except:
gp.addmessage("Error encountered\n")
gp.getmessage(2)