fun run() { amIActive = true var inputHeader: String? = null var outputHeader: String? = null var row: Int var col: Int var x: Int var y: Int var progress = 0 var z: Double var i: Int  var c: Int val dX = intArrayOf(1, 1, 1, 0, -1, -1, -1, 0) val dY = intArrayOf(-1, 0, 1, 1, 1, 0, -1, -1) var zFactor = 0.0 var slopeThreshold = 0.0 var profCurvThreshold = 0.0 var planCurvThreshold = 0.0 val radToDeg = 180 / Math.PI if (args.length <= 0) { showFeedback("Plugin parameters have not been set.") return } i = 0 while (i < args.length) { if (i == 0) { inputHeader = args.get(i) } else if (i == 1) { outputHeader = args.get(i) } else if (i == 2) { zFactor = args.get(i).toDouble() } else if (i == 3) { slopeThreshold =args.get(i).toDouble() } else if (i == 4) { profCurvThreshold = args.get(i).toDouble() } else if (i == 5) { planCurvThreshold = args.get(i).toDouble() ] } i++ } if (inputHeader == null || outputHeader == null) { showFeedback("One or more of the input parameters have not been set properly.") return } try { val DEM = WhiteboxRaster(inputHeader, "r")val rows: Int = DEM.getNumberRows() val cols: Int = DEM.getNumberColumns() val noData: Double = DEM.getNoDataValue() val gridResX: Double = DEM.getCellSizeX() val gridResY: Double = DEM.getCellSizeY() val diagGridRes = Math.sqrt(gridResX * gridResX + gridResY * gridResY) val gridLengths = doubleArrayOf( diagGridRes, gridResX, diagGridRes, gridResY, diagGridRes, gridResX, diagGridRes, gridResY ) var Zx: Double var Zy: Double var Zxx: Double var Zyy: Double var Zxy: Double var p: Double var Zx2: Double var q: Double var Zy2: Double var fx: Double var fy: Double val gridResTimes2 = gridResX * 2 val gridResSquared = gridResX * gridResX val fourTimesGridResSquared = gridResSquared * 4 var planCurv: Double var profCurv: Double var slope: Double val eightGridRes = 8 * gridResX val N = DoubleArray(8) val output = WhiteboxRaster(outputHeader, "rw", inputHeader, WhiteboxRaster.DataType.FLOAT, -999) output.setPreferredPalette("landclass.pal") output.setDataScale(WhiteboxRaster.DataScale.CONTINUOUS) row = 0 while (row < rows) { col = 0 while (col < cols) { z = DEM.getValue(row, col) if (z != noData) { z = z * zFactor c = 0 while (c < 8) { N[c] = DEM.getValue(row + dY[c], col + dX[c]) if (N[c] != noData) { N[c] = N[c] * zFactor } else { N[c] = z } c++ } Zx = (N[1] - N[5]) / gridResTimes2 Zy = (N[7] - N[3]) / gridResTimes2 Zxx = (N[1] - 2 * z + N[5]) / gridResSquared Zyy = (N[7] - 2 * z + N[3]) / gridResSquared Zxy = (-N[6] + N[0] + N[4] - N[2]) / fourTimesGridResSquared Zx2 = Zx * Zx Zy2 = Zy * Zy p = Zx2 + Zy2 q = p + 1 if (p > 0) { fy = (N[6] - N[4] + 2 * (N[7] - N[3]) + N[0] - N[2]) / eightGridRes fx = (N[2] - N[4] + 2 * (N[1] - N[5]) + N[0] - N[6]) / eightGridRes slope = Math.atan(Math.sqrt(fx * fx + fy * fy)) slope = slope * radToDeg planCurv = -1 * (Zxx * Zy2 - 2 * Zxy * Zx * Zy + Zyy * Zx2) / Math.pow(p, 1.5) planCurv = planCurv * radToDeg profCurv = -1 * (Zxx * Zx2 + 2 * Zxy * Zx * Zy + Zyy * Zy2) / Math.pow( p * q, 1.5 ) profCurv = profCurv * radToDeg if (profCurv < -profCurvThreshold && planCurv <= -planCurvThreshold and slope > slopeThreshold) { output.setValue(row, col, 1) } else if (profCurv < -profCurvThreshold && planCurv > planCurvThreshold && slope > slopeThreshold) { output.setValue(row, col, 2) } else if (profCurv > profCurvThreshold && planCurv <= planCurvThreshold && slope > slopeThreshold) { output.setValue(row, col, 3) } else if (profCurv > profCurvThreshold && planCurv > planCurvThreshold && slope > slopeThreshold) { output.setValue(row, col, 4) } else if (profCurv >= -profCurvThreshold && profCurv < profCurvThreshold && slope > slopeThreshold && planCurv <= -planCurvThreshold) { output.setValue(row, col, 5) } else if (profCurv >= -profCurvThreshold && profCurv < profCurvThreshold && slope > slopeThreshold && planCurv > planCurvThreshold) { output.setValue(row, col, 6) } else if (slope <= slopeThreshold) { output.setValue(row, col, 7) } else { output.setValue(row, col, noData) } } else { output.setValue(row, col, noData) } } col++ } if (cancelOp) { cancelOperation() return } progress = (100f * row / (rows - 1)).toInt() updateProgress(progress) row++ } output.addMetadataEntry("Created by the " + getDescriptiveName().toString() + " tool.") output.addMetadataEntry("Created on " + Date()) DEM.close() output.close() returnData(outputHeader) var retstr = "LANDFORM CLASSIFICATION KEY\n" retstr += "\nValue:\tClass" retstr += "\n1\tConvergent Footslope" retstr += "\n2\tDivergent Footslope" retstr += "\n3\tConvergent Shoulder" retstr += "\n4\tDivergent Shoulder" retstr += "\n5\tConvergent Backslope" retstr += "\n6\tDivergent Backslope" retstr += "\n7\tLevel" returnData(retstr) } catch (oe: OutOfMemoryError) { myHost.showFeedback("An out-of-memory error has occurred during operation.") } catch (e: Exception) { myHost.showFeedback("An error has occurred during operation. See log file for details.") myHost.logException("Error in " + getDescriptiveName(), e) } finally { updateProgress("Progress: ", 0) amIActive = false myHost.pluginComplete() } }
Used to execute this plugin tool .