Hi so I am trying to do a least-cost-path analysis using Arcpy and I am trying to save the Cost Path raster
but I keep getting this error with the final line of the cost path tool. If I take out the save portion I am able to
convert it to a polyline, but I need data from the result. I used model builder to develop the script and only made
minor changes to some of the file paths. Any help would be greatly appreciated.
Error:
RuntimeError: ERROR 010240: Could not save raster dataset to C:\Users\doc34\Desktop\LCP_Project-20211206T164053Z-001\LCP_Project\CostPath_Raster with output format GRID.
Code:
# Process: Cost Path (Cost Path) (sa)
CostPath_Raster = "C:\\Users\\doc34\\Desktop\\LCP_Project-20211206T164053Z-001\\LCP_Project\\CostPath_Raster"
cost_path = CostPath_Raster
CostPath_Raster = arcpy.sa.CostPath(in_destination_data=Geological_Source, in_cost_distance_raster=CostDis_DEM,
in_cost_backlink_raster=BackLink_DEM, path_type="EACH_CELL",
destination_field="",
force_flow_direction_convention="INPUT_RANGE")
# the below code would save the cost-path raster, but throws an error that I have not been able to solve
CostPath_Raster.save(cost_path)
print("Cost Path Raster Complete")
Solved! Go to Solution.
If this is an esri raster, your output path shouldn't contain spaces or punctuation and the output name is too long (10 chars max I think).
You would be better off saving to a *.tif by adding the file extension to the file name. *.tif files are recommended by esri for most raster functions
If this is an esri raster, your output path shouldn't contain spaces or punctuation and the output name is too long (10 chars max I think).
You would be better off saving to a *.tif by adding the file extension to the file name. *.tif files are recommended by esri for most raster functions
Yep I changed:
CP = "C:\\Users\\doc34\\Desktop\\LCP_Project-20211206T164053Z-001\\LCP_Project\\CostPath_raster"
to
CP = "C:\\Users\\doc34\\Desktop\\LCP_Project-20211206T164053Z-001\\LCP_Project\\CPR"
and it worked!
Thank you