mykonosman

Spatial Join script takes hours in Python, 7 minutes in ArcMap

Discussion created by mykonosman on Mar 27, 2012
Latest reply on Mar 29, 2012 by mykonosman
My spatial join python script used for two polygon features takes over an hour to complete, yet when I run the same spatial join in ArcMap takes about 7 minutes.

Any idea how I could modify the script to speed it up ?

import arcgisscripting

# Create the geoprocessor object
gp = arcgisscripting.create(9.3)
gp.OverWriteOutput = True

# Set the workspace. List all of the folders within
gp.Workspace = "C:\ZP4"
fcs = gp.ListWorkspaces("*","Folder")

#run spatial join on parcel.shp in each folder, then delete original and replace with "parceljoined"
for fc in fcs:
    print fc
    try:
     gp.SpatialJoin_analysis(fc + "\\Parcels.shp", "C:\ESRI\ESRIDATA\USA\usa_zipcodes.shp", fc + "\\Parcelsjoined.shp",)
     gp.CalculateField_management(fc + "\\Parcelsjoined.shp", "SIT_ZIP", "[POSTAL]", "VB", "")
     gp.CalculateField_management(fc + "\\Parcelsjoined.shp", "SIT_CITY", "[CITYNAME]", "VB", "")
     gp.DeleteField_management(fc + "\\Parcelsjoined.shp", "Join_Count;Join_Cou_1;Join_Cou_2;POSTAL")
     gp.Delete_management(fc + "\\Parcels.shp")
     gp.Rename_management(fc + "\\Parcelsjoined.shp", "Parcels.shp")
    except Exception:
     print 'AddZip Error'

Outcomes