4

By using the code below that creates least-cost paths between several polygons, I obtain this error message:

ExecuteError: ERROR 010067: Error in executing grid expression. Initalization failed

when I execute this code line:

outCostPath = CostPath("Selected_patch_end", "outCostDist.tif", "outCostLink.tif", "EACH_ZONE","FID")

Sometimes, when I re-execute my script, it works.

However, when the code works, I always obtain strange files and folders every time that I execute the same code line above:

enter image description here

Here is an insight of my dataset:

enter image description here

Here is my code:

 import arcpy
 from arcpy import env
 from arcpy.sa import *
 arcpy.CheckOutExtension("Spatial")
 arcpy.env.overwriteOutput = True
 arcpy.env.workspace = r"C:\Users\LCP"
 arcpy.env.extent = "costsn.tif"

with arcpy.da.SearchCursor("selected_polygons.shp",("*")) as rowsInPatches_start: 

   for rowStart in rowsInPatches_start:

      ID_patch_start = int(rowStart[3])

      ## Define SQL expression for the fonction Select Layer By Attribute
      expressionForSelectInPatches_start = "GRIDCODE=%s" % (ID_patch_start) 

      ## Process: Select Layer By Attribute
      arcpy.MakeFeatureLayer_management("selected_polygons.shp", "Selected_patch_start", expressionForSelectInPatches_start)

      ## Process: Cost Distance
      outCostDist=CostDistance("Selected_patch_start", "costsn.tif", "", "outCostLink.tif")

      ## Save the output
      outCostDist.save("outCostDist.tif")

      with arcpy.da.SearchCursor("selected_polygons.shp",("*")) as rowsInSelectedPatches_end: 

         for rowEnd in rowsInSelectedPatches_end:

            ID_patch_end = int(rowEnd[3]) 

            ## Define SQL expression for the fonction Select Layer By Attribute
            expressionForSelectInPatches_end = "GRIDCODE=%s" % (ID_patch_end) 

            ## Process: Select Layer By Attribute in Patches_end
            arcpy.MakeFeatureLayer_management("selected_polygons.shp", "Selected_patch_end", expressionForSelectInPatches_end)

            ## Process: Cost Path
            outCostPath = CostPath("Selected_patch_end", "outCostDist.tif", "outCostLink.tif", "EACH_ZONE","FID")

            ## Save the output
            outCostPath.save('P_' +  str(int(ID_patch_start)) + '_' + str(int(ID_patch_end)) + ".tif")

            ## Write in a file .txt
            outfile=open('P_' +  str(int(ID_patch_start)) + '_' + str(int(ID_patch_end)) + ".txt", "w")
            rowsTxt = arcpy.SearchCursor('P_' +  str(int(ID_patch_start)) + '_' + str(int(ID_patch_end)) + ".tif")
            for rowTxt in rowsTxt:
               value = rowTxt.getValue("Value")
               count = rowTxt.getValue("Count")
               pathcost = rowTxt.getValue("PATHCOST")
               startrow = rowTxt.getValue("STARTROW")
               startcol = rowTxt.getValue("STARTCOL")
               print value, count, pathcost, startrow, startcol
               outfile.write(str(value) + " " + str(count) + " " + str(pathcost) + " " + str(startrow) + " " + str(startcol) + "\n")
            outfile.close()

closed as off-topic by PolyGeo Oct 31 '16 at 4:09

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    You may want to review the previous questions that refer to this error number - a few of them have answers that may or may not help you debug your script. If you are able to extract a code snippet from your script that can be used to reproduce the error that would be very useful. – PolyGeo Aug 15 '14 at 22:42