class ShowGeoTiffTags(ActionListener):
    def __init__(self, args):
        if len(args) != 0:
            self.execute(args)
        else:
            # Create a dialog for this tool to collect user-specified
            # tool parameters.
            self.sd = ScriptDialog(pluginHost, descriptiveName, self)

            # Specifying the help file will display the html help
            # file in the help pane. This file should be be located
            # in the help directory and have the same name as the
            # class, with an html extension.
            helpFile = self.__class__.__name__
            self.sd.setHelpFile(helpFile)

            # Specifying the source file allows the 'view code'
            # button on the tool dialog to be displayed.
            self.sd.setSourceFile(os.path.abspath(__file__))

            # add some components to the dialog
            self.sd.addDialogFile("Input file", "Input GeoTiff File:", "open",
                                  "GeoTiff Files (*.tif), TIF, TIFF", True,
                                  False)

            # resize the dialog to the standard size and display it
            self.sd.setSize(800, 400)
            self.sd.visible = True

    def execute(self, args):
        try:
            inputfile = args[0]

            if not os.path.exists(inputfile):
                pluginHost.showFeedback("File " + inputfile +
                                        " does not exist.")
                return

            gt = GeoTiff(inputfile)
            gt.read()
            tags = gt.showInfo()

            ret = ""
            for tag in tags:
                ret += tag + "\n"

            pluginHost.returnData(ret)

        except:
            pluginHost.showFeedback("Error during script execution.")
            return

    def actionPerformed(self, event):
        if event.getActionCommand() == "ok":
            args = self.sd.collectParameters()
            self.sd.dispose()
            t = Thread(target=lambda: self.execute(args))
            t.start()
class ShowGeoTiffTags(ActionListener):
	def __init__(self, args):
		if len(args) != 0:
			self.execute(args)
		else:
			# Create a dialog for this tool to collect user-specified
			# tool parameters.
			self.sd = ScriptDialog(pluginHost, descriptiveName, self)	
		
			# Specifying the help file will display the html help
			# file in the help pane. This file should be be located 
			# in the help directory and have the same name as the 
			# class, with an html extension.
			helpFile = self.__class__.__name__
			self.sd.setHelpFile(helpFile)
		
			# Specifying the source file allows the 'view code' 
			# button on the tool dialog to be displayed.
			self.sd.setSourceFile(os.path.abspath(__file__))

			# add some components to the dialog
			self.sd.addDialogFile("Input file", "Input GeoTiff File:", "open", "GeoTiff Files (*.tif), TIF, TIFF", True, False)
			
			# resize the dialog to the standard size and display it
			self.sd.setSize(800, 400)
			self.sd.visible = True
		
	def execute(self, args):
		try:
			inputfile = args[0]

			if not os.path.exists(inputfile):
				pluginHost.showFeedback("File " + inputfile + " does not exist.")
				return
					
			gt = GeoTiff(inputfile)
			gt.read()
			tags = gt.showInfo()
			
			ret = ""
			for tag in tags:
				ret += tag + "\n"
			
			pluginHost.returnData(ret)

		except:
			pluginHost.showFeedback("Error during script execution.")
			return

	def actionPerformed(self, event):
		if event.getActionCommand() == "ok":
			args = self.sd.collectParameters()
			self.sd.dispose()
			t = Thread(target=lambda: self.execute(args))
			t.start()
Ejemplo n.º 3
0
class RenameFile(ActionListener):
	def __init__(self, args):
		if len(args) != 0:
			self.execute(args)
		else:
			# Create a dialog for this tool to collect user-specified
			# tool parameters.
			self.sd = ScriptDialog(pluginHost, descriptiveName, self)	
		
			# Specifying the help file will display the html help
			# file in the help pane. This file should be be located 
			# in the help directory and have the same name as the 
			# class, with an html extension.
			helpFile = self.__class__.__name__
			self.sd.setHelpFile(helpFile)
		
			# Specifying the source file allows the 'view code' 
			# button on the tool dialog to be displayed.
			self.sd.setSourceFile(os.path.abspath(__file__))

			# add some components to the dialog
			self.sd.addDialogFile("Input file", "Input File:", "open", "Whitebox Files (*.shp; *.dep), DEP, SHP", True, False)
			self.sd.addDialogFile("Output file", "Output File:", "close", "Whitebox Files (*.shp; *.dep), DEP, SHP", True, False)

			# resize the dialog to the standard size and display it
			self.sd.setSize(800, 400)
			self.sd.visible = True
		
	def execute(self, args):
		try:
			inputfile = args[0]
			outputfile = args[1]

			# is the input file a WhiteboxRaster or a shapefile?
			if inputfile.endswith(".dep"):
				israster = True
			elif inputfile.endswith(".shp"):
				israster = False
			else:
				pluginHost.showFeedback("The input file must be a Whitebox raster or shapefile.")
				return
			
			if israster:
				# make sure that the output file is of the same 
				# file type
				if not outputfile.endswith(".dep"):
					fileName, fileExtension = os.path.splitext(outputfile)
					outputfile = fileName + ".dep"

				# rename the header file
				os.rename(inputfile, outputfile)

				# rename the data file
				oldfile = inputfile.replace(".dep", ".tas")
				newfile = outputfile.replace(".dep", ".tas")
				os.rename(oldfile, newfile)

				oldfile = inputfile.replace(".dep", ".wstat")
				newfile = outputfile.replace(".dep", ".wstat")
				if os.path.exists(oldfile):
					os.rename(oldfile, newfile)
				
			else:
				# make sure that the output file is of the same 
				# file type
				if not outputfile.endswith(".shp"):
					fileName, fileExtension = os.path.splitext(outputfile)
					outputfile = fileName + ".shp"
				
				# .shp file 
				os.rename(inputfile, outputfile)

				# .dbf file
				oldfile = inputfile.replace(".shp", ".dbf")
				newfile = outputfile.replace(".shp", ".dbf")
				if os.path.exists(oldfile):
					os.rename(oldfile, newfile)
					
				# .shx file
				oldfile = inputfile.replace(".shp", ".shx")
				newfile = outputfile.replace(".shp", ".shx")
				if os.path.exists(oldfile):
					os.rename(oldfile, newfile)

				# .prj file
				oldfile = inputfile.replace(".shp", ".prj")
				newfile = outputfile.replace(".shp", ".prj")
				if os.path.exists(oldfile):
					os.rename(oldfile, newfile)

				# .sbn file
				oldfile = inputfile.replace(".shp", ".sbn")
				newfile = outputfile.replace(".shp", ".sbn")
				if os.path.exists(oldfile):
					os.rename(oldfile, newfile)

				# .sbx file
				oldfile = inputfile.replace(".shp", ".sbx")
				newfile = outputfile.replace(".shp", ".sbx")
				if os.path.exists(oldfile):
					os.rename(oldfile, newfile)
					
			pluginHost.showFeedback("Operation complete")
			
		except:
			pluginHost.showFeedback("File not written properly.")
			return

	def actionPerformed(self, event):
		if event.getActionCommand() == "ok":
			args = self.sd.collectParameters()
			self.sd.dispose()
			t = Thread(target=lambda: self.execute(args))
			t.start()
Ejemplo n.º 4
0
class Sink(ActionListener):
	def __init__(self, args):
		if len(args) != 0:
			self.execute(args)
		else:
			# Create a dialog for this tool to collect user-specified
			# tool parameters.
			self.sd = ScriptDialog(pluginHost, descriptiveName, self)	
		
			# Specifying the help file will display the html help
			# file in the help pane. This file should be be located 
			# in the help directory and have the same name as the 
			# class, with an html extension.
			helpFile = self.__class__.__name__
			self.sd.setHelpFile(helpFile)
		
			# Specifying the source file allows the 'view code' 
			# button on the tool dialog to be displayed.
			self.sd.setSourceFile(os.path.abspath(__file__))

			# add some components to the dialog
			self.sd.addDialogFile("Input file", "Input DEM File:", "open", "Whitebox Raster Files (*.dep), DEP", True, False)
			self.sd.addDialogFile("Output file", "Output Raster File:", "close", "Whitebox Raster Files (*.dep), DEP", True, False)

			# resize the dialog to the standard size and display it
			self.sd.setSize(800, 400)
			self.sd.visible = True
		
	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 actionPerformed(self, event):
		if event.getActionCommand() == "ok":
			args = self.sd.collectParameters()
			self.sd.dispose()
			t = Thread(target=lambda: self.execute(args))
			t.start()