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
	def execute(self, args):
		try:
			dX = [ 1, 1, 1, 0, -1, -1, -1, 0 ]
			dY = [ -1, 0, 1, 1, 1, 0, -1, -1 ]
			
			if len(args) != 2:
				pluginHost.showFeedback("Incorrect number of arguments given to tool.")
				return

			# read the input parameters
			inputfile = args[0]
			outputfile = args[1]
			
			# read the input image 
			inputraster = WhiteboxRaster(inputfile, 'r')
			nodata = inputraster.getNoDataValue()
			rows = inputraster.getNumberRows()
			cols = inputraster.getNumberColumns()
			
			# initialize the output image
			outputraster = WhiteboxRaster(outputfile, "rw", inputfile, DataType.FLOAT, nodata)
			outputraster.setPreferredPalette(inputraster.getPreferredPalette())

			'''perform the analysis
			   This code loops through a raster and performs a 
		 	   3 x 3 mean filter.'''
			oldprogress = -1
			for row in xrange(0, rows):
				for col in xrange(0, cols):
					z = inputraster.getValue(row, col)
					if z != nodata:
						mean = z
						numneighbours = 1
						for n in xrange(0, 8):
							zn = inputraster.getValue(row + dY[n], col + dX[n])
							if zn != nodata:
								mean += zn
								numneighbours += 1
								
						outputraster.setValue(row, col, mean / numneighbours)
				
				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.addMetadataEntry("Created by the " + descriptiveName + " tool.")
			outputraster.addMetadataEntry("Created on " + time.asctime())
			outputraster.close()

			# display the output image
			pluginHost.returnData(outputfile)
			
		except Exception, e:
			print e
			pluginHost.showFeedback("An error has occurred during operation. See log file for details.")
			pluginHost.logException("Error in " + descriptiveName, e)
			return
示例#4
0
    def execute(self, args):
        try:
            dX = [1, 1, 1, 0, -1, -1, -1, 0]
            dY = [-1, 0, 1, 1, 1, 0, -1, -1]

            if len(args) != 2:
                pluginHost.showFeedback(
                    "Incorrect number of arguments given to tool.")
                return

            # read the input parameters
            inputfile = args[0]
            outputfile = args[1]

            # read the input image
            inputraster = WhiteboxRaster(inputfile, 'r')
            nodata = inputraster.getNoDataValue()
            rows = inputraster.getNumberRows()
            cols = inputraster.getNumberColumns()

            # initialize the output image
            outputraster = WhiteboxRaster(outputfile, "rw", inputfile,
                                          DataType.FLOAT, nodata)
            outputraster.setPreferredPalette(inputraster.getPreferredPalette())
            '''perform the analysis
			   This code loops through a raster and performs a 
		 	   3 x 3 mean filter.'''
            oldprogress = -1
            for row in xrange(0, rows):
                for col in xrange(0, cols):
                    z = inputraster.getValue(row, col)
                    if z != nodata:
                        mean = z
                        numneighbours = 1
                        for n in xrange(0, 8):
                            zn = inputraster.getValue(row + dY[n], col + dX[n])
                            if zn != nodata:
                                mean += zn
                                numneighbours += 1

                        outputraster.setValue(row, col, mean / numneighbours)

                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.addMetadataEntry("Created by the " + descriptiveName +
                                          " tool.")
            outputraster.addMetadataEntry("Created on " + time.asctime())
            outputraster.close()

            # display the output image
            pluginHost.returnData(outputfile)

        except Exception, e:
            print e
            pluginHost.showFeedback(
                "An error has occurred during operation. See log file for details."
            )
            pluginHost.logException("Error in " + descriptiveName, e)
            return