I am attempting to create a least cost path using ArcPy for automation. I have the starting/end points and cost surface raster already assembled, so I am just using ArcPy to automate through my dataset. Upon running the script, though, I receive an error at line 24: "CostDist = arcpy.sa.CostDistance(...".
Here is the code block:
import os
import arcpy
from arcpy.sa import *
arcpy.env.overwriteOutput= True
arcpy.env.extent = ('H:\\IAS GIS Information\\Geodatabase\\Island_Isolation\\Tidal_Stream\\Tide_LCP\\Extent_3\\Tide_Extent3.shp')
arcpy.CheckOutExtension("spatial")
arcpy.env.workspace = ('H:\\IAS GIS Information\\Geodatabase\\Island_Isolation\\Tidal_Stream\\Tide_LCP\\Extent_3')
TargetWorkspace = ('H:\\IAS GIS Information\\Geodatabase\\Island_Isolation\\Tidal_Stream\\Tide_LCP\\Extent_3')
SourcePoints = ("H:\\IAS GIS Information\\Geodatabase\\Island_Isolation\\Tidal_Stream\\Tide_LCP\\Extent_3\\Tide_Extent3_Source_Points.shp")
DestinationPoints = ("H:\\IAS GIS Information\\Geodatabase\\Island_Isolation\\Tidal_Stream\\Tide_LCP\\Extent_3\\Tide_Extent3_Destination_Points.shp")
CostSurface = ("H:\\IAS GIS Information\\Geodatabase\\Island_Isolation\\Tidal_Stream\\Tide_LCP\\Extent_3\\Tide_Extent_3_CostSurface.tif")
CostDist = ('H:\\IAS GIS Information\\Geodatabase\\Island_Isolation\\Tidal_Stream\\Tide_LCP\\Extent_3')
Backlink = ('H:\\IAS GIS Information\\Geodatabase\\Island_Isolation\\Tidal_Stream\\Tide_LCP\\Extent_3')
CostPath = ('H:\\IAS GIS Information\\Geodatabase\\Island_Isolation\\Tidal_Stream\\Tide_LCP\\Extent_3')
for i in range (int(arcpy.GetCount_management(DestinationPoints).getOutput(0))): #Use the "getOutput() to start the FID count"
if os.path.exists(Backlink + str(i)):
os.remove(Backlink + str(i))
arcpy.MakeFeatureLayer_management(DestinationPoints, "endpointA" + str(i), ' "IN_FID_A" = ' + str(i))
arcpy.MakeFeatureLayer_management(SourcePoints, "sourcepointA" + str(i), ' "IN_FID_A" = ' + str(i))
CostDist = arcpy.sa.CostDistance("endpointA" + str(i), CostSurface, out_backlink_raster = "BackLinkA"+str(i))
CostDist.save("CostDistA" + str(i))
CostPath = arcpy.sa.CostPath("sourcepointA" + str(i), "CostDistA" + str(i), "BackLinkA" + str(i))
CostPath.save("CostPathA" + str(i))
The execution error reads: "ExecuteError: ERROR 999999: Error executing function. Failed to create raster dataset Failed to execute (CostDistance)."
I have used this code previously with no issues so I am not sure about what is making the script fail.