2

I would like to implement a script that

  1. reads base file and appended file;
  2. calls the program tool 'Mosaic with feathering';
  3. creates a mosaic output file;
  4. uses the output file as new base file and so on in a loop.

For starting I'm currently try this python code in Whitebox GAT:

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

But when I execute the code I don't get any error and no output file is created. Do you know what I'm doing wrong?

  • What are you trying to achieve with this code you've posted? – Mattropolis Jun 19 '17 at 16:23
  • basically I would like to implement a script that 1. reads base file and appended file; 2. calls the program tool 'Mosaic with feathering'; 3. creates a mosaic output file; 4. uses the output file as new base file and so on in a loop. – head_lu Jun 19 '17 at 16:29
  • 1
    Can you edit your post and integrate your comment into the question. Most potential readers won't look at all the comments. Thanks. – Mattropolis Jun 19 '17 at 16:31
0

This worked perfectly for me, calculating slope from the example DEM in the Vermont folder in resources/samples:

    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!" 

First off, I noticed you have an error in the naming of your two input files, when you try and load them:

   base**F**ile = wd + "save1.dep"
   pluginHost.returnData(base**f**ile)
   append**F**ile = wd + "save2.dep"
   pluginHost.returnData(append**f**ile)
   outputFile = wd +"output.dep"

That will certainly cause an error. When that was fixed, it seemed to still give me an error, and this is what I found to work for the specific tool you asked about:

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!" 

With the key difference for me being in this line:

   args = [baseFile, appendFile, outputFile, resamplingmethod, matchHistograms, '4.0']

Where I added in the Distance Weight Parameter argument, which, when you dig into the function's code, it seems to be looking for on lines 225-227.

This caused it to work for me without having to change any of the file names from how you had them.

  • Thank you for your reply. I tried your solution and it also worked well. Indeed the key difference is in that line, in my original script was missing one argument. – head_lu Jun 21 '17 at 16:43
1

I've solved the issue using

inputFile = wd + file 

instead of base and append file and adding the missing power to the arguments

args = [inputFile1, inputFile2, outputFile, resamplingMethod, matchHistograms, power]

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.