def execute(self, args): try: inputfile = args[0] outputfile = args[1] # fill the depressions in the DEM, being sure to # run on a dedicated thread and supressing # the return data (automatically displayed image) outputfile2 = outputfile.replace(".dep", "_temp.dep") args2 = [inputfile, outputfile2, "0.0"] pluginHost.runPlugin("FillDepressions", args2, False, True) # flag the cells that have been affected by the filling. inputraster = WhiteboxRaster(inputfile, 'r') tempraster = WhiteboxRaster(outputfile2, 'rw') rows = tempraster.getNumberRows() cols = tempraster.getNumberColumns() nodata = inputraster.getNoDataValue() oldprogress = -1 for row in xrange(0, rows): for col in xrange(0, cols): z1 = inputraster.getValue(row, col) z2 = tempraster.getValue(row, col) if z1 != nodata: if z1 < z2: tempraster.setValue(row, col, 1.0) else: tempraster.setValue(row, col, 0.0) else: tempraster.setValue(row, col, nodata) progress = (int)((100.0 * (row + 1.0)) / rows) if progress > oldprogress: oldprogress = progress pluginHost.updateProgress(progress) if pluginHost.isRequestForOperationCancelSet(): pluginHost.showFeedback("Operation cancelled") return tempraster.flush() # clump the filled cells, being sure to # run on a dedicated thread and supressing # the return data (automatically displayed image) args2 = [outputfile2, outputfile, 'true', 'true'] pluginHost.runPlugin("Clump", args2, False, True) inputraster.close() # delete the temporary file os.remove(outputfile2) os.remove(outputfile2.replace(".dep", ".tas")) # display the final output pluginHost.returnData(outputfile) except: pluginHost.showFeedback("Error during script execution.") return
def execute(self, args): try: if len(args) != 3: pluginHost.showFeedback( "Incorrect number of arguments given to tool.") return inputfile = args[0] outputfile = args[1] backgroundVal = 0.0 # fill the depressions in the DEM, being sure to # run on a dedicated thread and supressing # the return data (automatically displayed image) args2 = [inputfile, outputfile, "0.0"] pluginHost.runPlugin("FillDepressions", args2, False, True) # measure the depth in sink. inputraster = WhiteboxRaster(inputfile, 'r') outputraster = WhiteboxRaster(outputfile, 'rw') rows = outputraster.getNumberRows() cols = outputraster.getNumberColumns() nodata = inputraster.getNoDataValue() if args[2] == "true": backgroundVal = nodata outputraster.setPreferredPalette("spectrum.plt") else: outputraster.setPreferredPalette( "spectrum_black_background.plt") oldprogress = -1 for row in xrange(0, rows): for col in xrange(0, cols): z1 = inputraster.getValue(row, col) z2 = outputraster.getValue(row, col) if z1 != nodata: if z1 < z2: outputraster.setValue(row, col, z2 - z1) else: outputraster.setValue(row, col, backgroundVal) else: outputraster.setValue(row, col, nodata) progress = (int)(100.0 * row / (rows - 1)) if progress > oldprogress: oldprogress = progress pluginHost.updateProgress(progress) if pluginHost.isRequestForOperationCancelSet(): pluginHost.showFeedback("Operation cancelled") return inputraster.close() outputraster.flush() outputraster.findMinAndMaxVals() outputraster.setDisplayMinimum(outputraster.getMinimumValue()) outputraster.setDisplayMaximum(outputraster.getMaximumValue()) outputraster.close() # display the final output pluginHost.returnData(outputfile) pluginHost.updateProgress(0) except Exception, e: pluginHost.logException("Error in DepthInSink", e) pluginHost.showFeedback("Error during script execution.") return
def execute(self, args): try: if len(args) != 3: pluginHost.showFeedback("Incorrect number of arguments given to tool.") return inputfile = args[0] outputfile = args[1] backgroundVal = 0.0 # fill the depressions in the DEM, being sure to # run on a dedicated thread and supressing # the return data (automatically displayed image) args2 = [inputfile, outputfile, "0.0"] pluginHost.runPlugin("FillDepressions", args2, False, True) # measure the depth in sink. inputraster = WhiteboxRaster(inputfile, 'r') outputraster = WhiteboxRaster(outputfile, 'rw') rows = outputraster.getNumberRows() cols = outputraster.getNumberColumns() nodata = inputraster.getNoDataValue() if args[2] == "true": backgroundVal = nodata outputraster.setPreferredPalette("spectrum.plt") else: outputraster.setPreferredPalette("spectrum_black_background.plt") oldprogress = -1 for row in xrange(0, rows): for col in xrange(0, cols): z1 = inputraster.getValue(row, col) z2 = outputraster.getValue(row, col) if z1 != nodata: if z1 < z2: outputraster.setValue(row, col, z2 - z1) else: outputraster.setValue(row, col, backgroundVal) else: outputraster.setValue(row, col, nodata) progress = (int)(100.0 * row / (rows - 1)) if progress > oldprogress: oldprogress = progress pluginHost.updateProgress(progress) if pluginHost.isRequestForOperationCancelSet(): pluginHost.showFeedback("Operation cancelled") return inputraster.close() outputraster.flush() outputraster.findMinAndMaxVals() outputraster.setDisplayMinimum(outputraster.getMinimumValue()) outputraster.setDisplayMaximum(outputraster.getMaximumValue()) outputraster.close() # display the final output pluginHost.returnData(outputfile) pluginHost.updateProgress(0) except Exception, e: pluginHost.logException("Error in DepthInSink", e) pluginHost.showFeedback("Error during script execution.") return