I'm having a bit of a strange issue; the code below worked just fine yesterday but when I re-ran it and added a backlink raster to the output of the CostDistance tool on line 71 it caused ArcGIS Pro to crash (there was no open instance of ArcGIS Pro at the time, I can only assume it was opened for background processing or something). I don't really need the backlink so no problem I thought, so I just restarted my IDE (Spyder) and when I tried to run it again it gave me an
ExecuteError: ERROR 999999: Something unexpected caused the tool to fail. Contact Esri Technical Support (http://esriurl.com/support) to Report a Bug, and refer to the error help for potential solutions or workarounds.
Failed to create raster dataset
Failed to execute (Fill).
on line 28
elev_filled = Fill(inSurfaceRaster)
There have been a few previous cases where anaconda or python froze during some operation and it resulted an Error 999999 when I restarted, but it was always easily fixed by deleting the contents of C:\users\{myname}\AppData\local\Temp; this time however the problem has persisted. I've tried running the code on the python window of ArcGIS Pro, in an ArcMap 10.6 arcpy environment, and in Jupyter Notebooks and each one gives the Error 999999; however, it works fine when I use the Fill tool in ArcGIS Pro Desktop.
Anyone have any idea what's up? I'm guessing the unexpected exit of ArcGIS Pro left some debris on my system that would normally have been cleaned up in a normal exit but outside of the temp folder I'm not sure where to look. I've also tried rebooting the system (after deleting the temp folders) and running both spyder and ArcGIS Pro as an administrator.
Update: I tested it in the python window in ArcMap 10.6 on my computer and still got the Error 999999; I tried it out in the python window of ArcMap 10.6 on a different computer and it *did* work.
It strikes me that I don't know how to add line numbers to this code block and the spaces between lines have disappeared, so hopefully it's not too much trouble for you all.
Thanks!
# -*- coding: utf-8 -*-
#Import packages, check out extensions
import arcpy
from arcpy import env
arcpy.CheckOutExtension("Spatial")
from arcpy.sa import *
import geomorph_routines_module
# Set environment settings
env.workspace = r'D:\hydro_RI\data'
env.overwriteOutput = 1
# Set local variables
#inSurfaceRaster = env.workspace + '\\' + 'grdn42w072_13'
inSurfaceRaster = env.workspace + '\\' + 'rhodeIslandDEM.tif'
#outDropRaster = "D:\\hydro_RI\\data\\dropraster"
outBacklinkRaster = "D:\\hydro_RI\\data\\backlink"
#sample_points =
stream_threshold = 50000
#declares units of the map; need to add some code to figure this out
inZUnits = 'Meters'
#Set raster calculation details
env.extent = inSurfaceRaster
env.cellSize = 10
# Fill sinks in the raster
elev_filled = Fill(inSurfaceRaster)
#elev_filled = Fill(r"D:\hydro_RI\data\rhodeIslandDEM.tif")
#Calculate flow direction
outFlowDirection = FlowDirection(elev_filled, "FORCE", outDropRaster, 'D8')
#Calculate flow accumulation
flow_accum = FlowAccumulation(outFlowDirection)
#Calculate watershed areas feeding into locations of sample points;
streamThreshold = SetNull(flow_accum <= stream_threshold,flow_accum)
strahler_threshold = StreamOrder(streamThreshold, outFlowDirection, 'STRAHLER')
strahler_link = StreamLink(strahler_threshold, outFlowDirection)
#Clip relevent watersheds to reduce processing time of indices
#clip_feature = arcpy.RasterToPolygon_conversion (polluted, env.workspace + '\\' + 'clipFeat.shp' , "NO_SIMPLIFY")
#wshd_clip = arcpy.Clip_management(elev_filled, '#', env.workspace + '\\' + 'wshd_clip.tif',clip_feature, "0", "ClippingGeometry")
#Basis for CTI
clippedFootprint = geomorph_routines_module.checkExt(elev_filled)
zFactor = geomorph_routines_module.getZFactor(clippedFootprint,inZUnits)
slope = Slope(clippedFootprint,"DEGREE",zFactor)
radSlope = Divide(Times(slope,1.570796),90)
tan_slp = Con(radSlope > 0, Tan(radSlope), 0.001)
# Getting info on raster
dscRaster = arcpy.Describe(clippedFootprint)
inSpRef = dscRaster.spatialReference
spRefType = inSpRef.type
cellSize = dscRaster.meanCellHeight
if spRefType == "Geographic":
cellSize = cellSize/zFactor
#Calculate flow direction and flow accumulation of filled rastter
clippedFlowDirection = FlowDirection(clippedFootprint)
clippedFlowAcc = FlowAccumulation(clippedFlowDirection)
#CTI
corr_flowAcc = Times(Plus(clippedFlowAcc,1),cellSize)
twiRaster = Ln(Divide(corr_flowAcc,tan_slp))
twiRaster.save(env.workspace + '\\' + 'twiRI')
#Cartographic depth to water index (DTW)
dtwRaster = CostDistance (strahler_threshold, tan_slp, '', '')
dtwRaster.save(env.workspace + '\\' + 'dtwRI')
Give the Syntax Highlighter a try to format your code:
Done, thanks!