1

I'm trying to get a small script to run using Whitebox's Scripter:

print("Running script")

# data path
whiteboxdp = "/Users/analytics/dem_catchment/sites/Southwold/whitebox_files/"

# set local working directory
pluginHost.setWorkingDirectory(whiteboxdp)

# Calculate dem fill
base_dem = whiteboxdp + "Southwold_lidar_dem_2m_full.dep"
filled_dem = whiteboxdp + "SW_filled.dep"
flatIncrement = "0.0001"
args = [base_dem, filled_dem, flatIncrement]

# does nothing that I can see, no processing or output
pluginHost.runPlugin("FillDepression", args, False, False)

print("Script finished")

When I execute/run the script I just instantly get:

Running script
Script finished

No errors or other warnings. No content generated. I looked at the example by John Lindsay but I feel that I'm not using this correctly as it's not implementing any of the toolbox calls.

What am I doing wrong?

  • 1
    Maybe the Whiteboxdb path needs a Drive designation such as C: – klewis Jan 25 '17 at 15:38
  • Agree with ^ klewis. I'm actually surprised this isn't throwing some variety of file not found error. Is there a "debug mode" or "debug option" for the scripter where you can watch for errors or warnings? Optionally, you could try wrapping in a try catch and do a print("error caught..") instruction in the catch block. – elrobis Jan 25 '17 at 15:56
  • This is running on a Mac so the pathnames are correct. I can get the script to list files fine using os.listdir(whiteboxdp). The 'try - catch' suggestion won't work as no errors are thrown. – Cyrille Jan 25 '17 at 22:02
1

Try either of these, pasting them right into the scripting window:

Mosiac with Feather

import os
try:
   separator = os.sep
   wd = pluginHost.getApplicationDirectory() + separator + "resources" + separator + "samples" + separator + "Vermont DEM" + separator
   pluginHost.setWorkingDirectory(wd)
   baseFile = wd + "Vermont DEM.dep"
   pluginHost.returnData(baseFile)
   appendFile = wd + "hillshade.dep"
   pluginHost.returnData(appendFile)
   outputFile = wd + "output.dep"
   resamplingmethod = "nearest neighbour"
   matchHistograms = "true"
   args = [baseFile, appendFile, outputFile, resamplingmethod, matchHistograms, '4.0']
   pluginHost.runPlugin("MosaicWithFeathering", args, False)
except Exception, e:
   print e
   pluginHost.showFeedback("Error during script execution.")
finally:
    print "I'm done!" 

Slope calc:

import os
try:
   separator = os.sep
   wd = pluginHost.getApplicationDirectory() + separator + "resources" + separator + "samples" + separator + "Vermont DEM" + separator
   pluginHost.setWorkingDirectory(wd)
   print(wd)
   basefile = wd + 'Vermont DEM.dep'
   pluginHost.returnData(basefile)
   outputFile = wd + "slope.dep"
   zFactor = "1.0"
   args = [basefile, outputFile, zFactor]
   pluginHost.runPlugin("Slope", args, False)
except Exception, e:
   print e
   pluginHost.showFeedback("Error during script execution.")
finally:
    print "I'm done!" 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.