Exemplo n.º 1
0
	def execute(self, args):
		try:
			if len(args) != 4:
				pluginHost.showFeedback("Incorrect number of arguments given to tool.")
				return

			# read the input parameters
			inputfile = args[0]
			outputfile = args[1]
			filtersize = int(args[2])
			if filtersize < 3:
				filtersize = 3
			slopethreshold = float(args[3])
			
			exe_path = pluginHost.getResourcesDirectory() + "plugins" + os.path.sep
			os.chdir(exe_path)

			(release, vendor, vminfo, osinfo) = jav()
			if "win" in osinfo[0].lower():
				ext = '.exe'
			else:
				ext = ''

			cmd = "." + os.path.sep + "NativePlugins" + os.path.sep + "remove_off_terrain_objects{}".format(ext)
			cmd += ' -i=\"{}\"'.format(inputfile)
			cmd += ' -o=\"{}\"'.format(outputfile)
			cmd += ' -filter=\"{}\"'.format(filtersize)
			cmd += ' -slope=\"{}\"'.format(slopethreshold)
			cmd += ' -v'

			ps = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, universal_newlines=True)
			
			while True:
				line = ps.stdout.readline()
				if line != '':
					if "%" in line:
						str_array = line.split(" ")
						label = line.replace(str_array[len(str_array)-1], "")
						progress = int(str_array[len(str_array)-1].replace("%", "").strip())
						pluginHost.updateProgress(label, progress)
					else:
						if "error" in line.lower():
							pluginHost.showFeedback("Error: {}".format(line))
						else:
							if not line.startswith("*"):
								pluginHost.updateProgress(line, 0)
				else:
					break

			# 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
Exemplo n.º 2
0
    def execute(self, args):
        try:
            if len(args) != 6:
                pluginHost.showFeedback(
                    "Incorrect number of arguments given to tool.")
                return

            # read the input parameters
            inputfile = args[0]
            outputfile = args[1]
            min_z = float('-inf')
            if args[2].lower() != "not specified":
                min_z = float(args[2])
            max_z = float('inf')
            if args[3].lower() != "not specified":
                max_z = float(args[3])
            in_class = -1
            if args[4].lower() != "not specified":
                in_class = int(args[4])
            out_class = -1
            if args[5].lower() != "not specified":
                out_class = int(args[5])

            if min_z == float('-inf') and max_z == float('inf'):
                pluginHost.showFeedback(
                    "You must specify either a min. z, a max. z, or both.")
                return

            exe_path = pluginHost.getResourcesDirectory(
            ) + "plugins" + os.path.sep
            os.chdir(exe_path)

            (release, vendor, vminfo, osinfo) = jav()
            if "win" in osinfo[0].lower():
                ext = '.exe'
            else:
                ext = ''

            tool_name = "lidar_elevation_slice"
            cmd = "." + os.path.sep + "NativePlugins" + os.path.sep + "{}{}".format(
                tool_name, ext)
            cmd += ' -i=\"{}\"'.format(inputfile)
            cmd += ' -o=\"{}\"'.format(outputfile)
            cmd += ' -minz=\"{}\"'.format(min_z)
            cmd += ' -maxz=\"{}\"'.format(max_z)
            if in_class >= 0 and out_class >= 0:
                cmd += ' -class'
                cmd += ' -inclassval=\"{}\"'.format(in_class)
                cmd += ' -outclassval=\"{}\"'.format(out_class)
            cmd += ' -v'

            ps = subprocess.Popen(cmd,
                                  shell=True,
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.STDOUT,
                                  bufsize=1,
                                  universal_newlines=True)

            while True:
                line = ps.stdout.readline()
                if line != '':
                    if "%" in line:
                        str_array = line.split(" ")
                        label = line.replace(str_array[len(str_array) - 1], "")
                        progress = int(str_array[len(str_array) - 1].replace(
                            "%", "").strip())
                        pluginHost.updateProgress(label, progress)
                    else:
                        if "error" in line.lower():
                            pluginHost.showFeedback("Error: {}".format(line))
                        else:
                            if not line.startswith("*"):
                                pluginHost.updateProgress(line, 0)
                else:
                    break

            # 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
    def execute(self, args):
        try:
            if len(args) != 8:
                pluginHost.showFeedback(
                    "Incorrect number of arguments given to tool.")
                return

            # read the input parameters
            inputfile = args[0]
            outputfile = args[1]
            search_dist = float(args[2])
            slope = float(args[3])
            min_z_diff = float(args[4])
            max_z_above_ground = float(args[5])
            min_z_str = args[6]
            min_z = -999999.0
            if min_z_str.lower() != "not specified":
                min_z = float(min_z)
            classify = False
            if args[7].lower() == 'true':
                classify = True

            exe_path = pluginHost.getResourcesDirectory(
            ) + "plugins" + os.path.sep
            os.chdir(exe_path)

            (release, vendor, vminfo, osinfo) = jav()
            if "win" in osinfo[0].lower():
                ext = '.exe'
            else:
                ext = ''

            tool_name = "lidar_ground_point_separation"
            cmd = "." + os.path.sep + "NativePlugins" + os.path.sep + "{}{}".format(
                tool_name, ext)
            cmd += ' -i=\"{}\"'.format(inputfile)
            cmd += ' -o=\"{}\"'.format(outputfile)
            cmd += ' -dist=\"{}\"'.format(search_dist)
            cmd += ' -slope=\"{}\"'.format(slope)
            cmd += ' -minzdiff=\"{}\"'.format(min_z_diff)
            cmd += ' -maxzdiff=\"{}\"'.format(max_z_above_ground)
            if classify:
                cmd += ' -class'
            if min_z_str.lower() != "not specified":
                cmd += ' -minz=\"{}\"'.format(min_z)
            cmd += ' -v'

            ps = subprocess.Popen(cmd,
                                  shell=True,
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.STDOUT,
                                  bufsize=1,
                                  universal_newlines=True)

            while True:
                line = ps.stdout.readline()
                if line != '':
                    if "%" in line:
                        str_array = line.split(" ")
                        label = line.replace(str_array[len(str_array) - 1], "")
                        progress = int(str_array[len(str_array) - 1].replace(
                            "%", "").strip())
                        pluginHost.updateProgress(label, progress)
                    else:
                        if "error" in line.lower():
                            pluginHost.showFeedback("Error: {}".format(line))
                        else:
                            if not line.startswith("*"):
                                pluginHost.updateProgress(line, 0)
                else:
                    break

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

            # read the input parameters
            input_files = args[0][:-1]

            exe_path = pluginHost.getResourcesDirectory(
            ) + "plugins" + os.path.sep
            os.chdir(exe_path)

            (release, vendor, vminfo, osinfo) = jav()
            if "win" in osinfo[0].lower():
                ext = '.exe'
            else:
                ext = ''

            exe_name = "go-spatial"
            tool_name = "whitebox2geotiff"

            input_files_list = input_files.split(";")
            num_files = len(input_files_list)

            for input_file in input_files_list:
                cmd = "." + os.path.sep + "NativePlugins" + os.path.sep + "{0}{1}".format(
                    exe_name, ext)
                cmd += ' -run=\"{}\"'.format(tool_name)
                cmd += ' -args=\"{0};{1}\"'.format(
                    input_file, input_file.replace(".dep", ".tif"))

                ps = subprocess.Popen(cmd,
                                      shell=True,
                                      stdout=subprocess.PIPE,
                                      stderr=subprocess.STDOUT,
                                      bufsize=1,
                                      universal_newlines=True)

                while True:
                    line = ps.stdout.readline()
                    if line != '':
                        if "%" in line:
                            str_array = line.split(" ")
                            label = line.replace(str_array[len(str_array) - 1],
                                                 "")
                            progress = int(str_array[len(str_array) -
                                                     1].replace("%",
                                                                "").strip())
                            pluginHost.updateProgress(label, progress)
                        else:
                            if "error" in line.lower():
                                pluginHost.showFeedback(
                                    "Error: {}".format(line))
                            else:
                                if not line.startswith("*"):
                                    pluginHost.updateProgress(line, 0)
                    else:
                        break

            pluginHost.showFeedback("Complete!")

        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
Exemplo n.º 5
0
    def execute(self, args):
        try:
            if len(args) != 3:
                pluginHost.showFeedback(
                    "Incorrect number of arguments given to tool.")
                return

            # read the input parameters
            inputfile = args[0]
            outputfile = args[1]
            grid_resolution = float(args[2])

            exe_path = pluginHost.getResourcesDirectory(
            ) + "plugins" + os.path.sep
            os.chdir(exe_path)

            (release, vendor, vminfo, osinfo) = jav()
            if "win" in osinfo[0].lower():
                ext = '.exe'
            else:
                ext = ''

            tool_name = "lidar_flightline_overlap"
            # Hard coded exe directory only for testing.
            cmd = "/Users/johnlindsay/Documents/programming/Whitebox/trunk/whitebox_tools/target/release/{0}{1}".format(
                tool_name, ext)
            #			cmd = "." + os.path.sep + "NativePlugins" + os.path.sep + "{0}{1}".format(tool_name, ext)
            cmd += ' -i=\"{}\"'.format(inputfile)
            cmd += ' -o=\"{}\"'.format(outputfile)
            cmd += ' -resolution=\"{}\"'.format(grid_resolution)
            cmd += ' -palette=\"light_quant.pal\"'
            cmd += ' -v'

            ps = subprocess.Popen(cmd,
                                  shell=True,
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.STDOUT,
                                  bufsize=1,
                                  universal_newlines=True)

            while True:
                line = ps.stdout.readline()
                if line != '':
                    if "%" in line:
                        str_array = line.split(" ")
                        label = line.replace(str_array[len(str_array) - 1], "")
                        progress = int(str_array[len(str_array) - 1].replace(
                            "%", "").strip())
                        pluginHost.updateProgress(label, progress)
                    else:
                        # print line
                        if "error" in line.lower():
                            pluginHost.showFeedback("Error: {}".format(line))
                        else:
                            if not line.startswith("*"):
                                pluginHost.updateProgress(line, 0)
                else:
                    break

            # 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