DMS2

Making my script run faster

Discussion created by DMS2 on Nov 8, 2011
Latest reply on Nov 9, 2011 by kimo
Hello,
I'm trying to get the fastest and most efficient script to take each feature in a shapefile (it's a 60x60m grid with 10 million features) as a mask to cut a DTM and apply the surface volume tool to each resulting raster.
This script needs 3 seconds per feature but bearing in mind that I have 10 million features this is too slow.
Any idea on how to improve it?
Thanks!

import arcpy

arcpy.CheckOutExtension("3D")
arcpy.CheckOutExtension("spatial")

Fishnet60x60 = arcpy.GetParameterAsText(0)
MDT15 = arcpy.GetParameterAsText(1)
Area2D3D_txt = arcpy.GetParameterAsText(2)

try:

    rows = arcpy.SearchCursor(Fishnet60x60)
    for row in rows:
        idvalue = row.getValue("ID_GRID")
        arcpy.MakeFeatureLayer_management(Fishnet60x60, Fishnet60x60 + "_layer", "\"ID_GRID\" = '" + idvalue + "'", "", "")
        arcpy.gp.ExtractByMask_sa(MDT15, Fishnet60x60 + "_layer", idvalue)
        arcpy.SurfaceVolume_3d(idvalue, Area2D3D_txt, "ABOVE", "0", "1", "0")

except:

    arcpy.AddMessage(arcpy.GetMessages(2))

Outcomes