def defineCharacteristicsFromFile(self): lines = open(self.descriptionFile) line = lines.readline().strip('\n').strip() self.name = line self.i18n_name = QCoreApplication.translate("TAUDEMAlgorithm", line) line = lines.readline().strip('\n').strip() self.cmdName = line line = lines.readline().strip('\n').strip() self.group = line self.i18n_group = QCoreApplication.translate("TAUDEMAlgorithm", line) line = lines.readline().strip('\n').strip() while line != '': try: line = line.strip('\n').strip() if line.startswith('Parameter'): param = getParameterFromString(line) self.addParameter(param) else: self.addOutput(getOutputFromString(line)) line = lines.readline().strip('\n').strip() except Exception as e: ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, self.tr('Could not load TauDEM algorithm: %s\n%s' % (self.descriptionFile, line))) raise e lines.close()
def defineCharacteristicsFromFile(self): with codecs.open(self.descriptionFile, encoding='utf-8') as f: line = f.readline().strip('\n').strip() self.name = line self.i18n_name = self.tr(line) line = f.readline().strip('\n').strip() self.cmdName = line line = f.readline().strip('\n').strip() self.group = line self.i18n_group = self.tr(line) line = f.readline().strip('\n').strip() while line != '': try: line = line.strip('\n').strip() if line.startswith('Parameter'): param = getParameterFromString(line) self.addParameter(param) else: self.addOutput(getOutputFromString(line)) line = f.readline().strip('\n').strip() except Exception as e: ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, self.tr('Could not load TauDEM algorithm: {}\n{}'.format(self.descriptionFile, line))) raise e
def defineCharacteristicsFromFile(self): lines = open(self.descriptionFile) line = lines.readline().strip('\n').strip() self.name = line if '|' in self.name: tokens = self.name.split('|') self.name = tokens[0] self.i18n_name = QCoreApplication.translate("SAGAAlgorithm", unicode(self.name)) self.cmdname = tokens[1] else: self.cmdname = self.name self.i18n_name = QCoreApplication.translate("SAGAAlgorithm", unicode(self.name)) self.name = self.name[0].upper() + self.name[1:].lower() line = lines.readline().strip('\n').strip() self.undecoratedGroup = line self.group = SagaGroupNameDecorator.getDecoratedName(self.undecoratedGroup) self.i18n_group = QCoreApplication.translate("SAGAAlgorithm", self.group) line = lines.readline().strip('\n').strip() while line != '': if line.startswith('Hardcoded'): self.hardcodedStrings.append(line[len('Harcoded|') + 1:]) elif line.startswith('Parameter'): self.addParameter(getParameterFromString(line)) elif line.startswith('AllowUnmatching'): self.allowUnmatchingGridExtents = True elif line.startswith('Extent'): # An extent parameter that wraps 4 SAGA numerical parameters self.extentParamNames = line[6:].strip().split(' ') self.addParameter(ParameterExtent(self.OUTPUT_EXTENT, 'Output extent', '0,1,0,1')) else: self.addOutput(getOutputFromString(line)) line = lines.readline().strip('\n').strip() lines.close()
def processParameterLine(self, line): param = None line = line.replace('#', '') if line == "nomodeler": self._flags = self._flags | QgsProcessingAlgorithm.FlagHideFromModeler return if line == "nocrswarning": self.noCRSWarning = True return tokens = line.split('=', 1) desc = self.createDescriptiveName(tokens[0]) if tokens[1].lower().strip() == 'group': self._group = tokens[0] return if tokens[1].lower().strip() == 'name': self._name = self._display_name = tokens[0] return out = getOutputFromString(line) if out is None: param = getParameterFromString(line) if param is not None: self.addParameter(param) elif out is not None: out.setName(tokens[0]) out.setDescription(desc) self.addOutput(out) else: raise WrongScriptException( self.tr('Could not load script: {0}.\n' 'Problem with line "{1}"', 'ScriptAlgorithm').format(self.descriptionFile or '', line))
def defineCharacteristicsFromFile(self): lines = open(self.descriptionFile) line = lines.readline().strip("\n").strip() self.name = line if "|" in self.name: tokens = self.name.split("|") self.name = tokens[0] self.cmdname = tokens[1] else: self.cmdname = self.name self.name = self.name[0].upper() + self.name[1:].lower() line = lines.readline().strip("\n").strip() self.undecoratedGroup = line self.group = SagaGroupNameDecorator.getDecoratedName(self.undecoratedGroup) line = lines.readline().strip("\n").strip() while line != "": if line.startswith("Hardcoded"): self.hardcodedStrings.append(line[len("Harcoded|") + 1 :]) elif line.startswith("Parameter"): self.addParameter(getParameterFromString(line)) elif line.startswith("AllowUnmatching"): self.allowUnmatchingGridExtents = True elif line.startswith("Extent"): # An extent parameter that wraps 4 SAGA numerical parameters self.extentParamNames = line[6:].strip().split(" ") self.addParameter(ParameterExtent(self.OUTPUT_EXTENT, "Output extent", "0,1,0,1")) else: self.addOutput(getOutputFromString(line)) line = lines.readline().strip("\n").strip() lines.close()
def defineCharacteristicsFromFile(self): lines = open(self.descriptionFile) line = lines.readline().strip("\n").strip() self.name = line line = lines.readline().strip("\n").strip() self.cmdName = line line = lines.readline().strip("\n").strip() self.group = line line = lines.readline().strip("\n").strip() while line != "": try: line = line.strip("\n").strip() if line.startswith("Parameter"): param = getParameterFromString(line) self.addParameter(param) else: self.addOutput(getOutputFromString(line)) line = lines.readline().strip("\n").strip() except Exception as e: ProcessingLog.addToLog( ProcessingLog.LOG_ERROR, self.tr("Could not load TauDEM algorithm: %s\n%s" % (self.descriptionFile, line)), ) raise e lines.close()
def processParameterLine(self, line): param = None line = line.replace('#', '') if line == "nomodeler": self.showInModeler = False return if line == "nocrswarning": self.noCRSWarning = True return tokens = line.split('=', 1) desc = self.createDescriptiveName(tokens[0]) if tokens[1].lower().strip() == 'group': self.group = self.i18n_group = tokens[0] return if tokens[1].lower().strip() == 'name': self.name = self.i18n_name = tokens[0] return out = getOutputFromString(line) if out is None: param = getParameterFromString(line) if param is not None: self.addParameter(param) elif out is not None: out.name = tokens[0] out.description = desc self.addOutput(out) else: raise WrongScriptException( self.tr('Could not load script: %s.\n' 'Problem with line "%s"', 'ScriptAlgorithm') % (self.descriptionFile or '', line))
def defineCharacteristicsFromFile(self): with open(self.descriptionFile) as lines: line = lines.readline().strip('\n').strip() self.name = line if '|' in self.name: tokens = self.name.split('|') self.name = tokens[0] #cmdname is the name of the algorithm in SAGA, that is, the name to use to call it in the console self.cmdname = tokens[1] else: self.cmdname = self.name self.i18n_name = QCoreApplication.translate("SAGAAlgorithm", str(self.name)) #_commandLineName is the name used in processing to call the algorithm #Most of the time will be equal to the cmdname, but in same cases, several processing algorithms #call the same SAGA one self._commandLineName = self.createCommandLineName(self.name) self.name = decoratedAlgorithmName(self.name) self.i18n_name = QCoreApplication.translate("SAGAAlgorithm", str(self.name)) line = lines.readline().strip('\n').strip() self.undecoratedGroup = line self.group = decoratedGroupName(self.undecoratedGroup) self.i18n_group = QCoreApplication.translate("SAGAAlgorithm", self.group) line = lines.readline().strip('\n').strip() while line != '': if line.startswith('Hardcoded'): self.hardcodedStrings.append(line[len('Hardcoded|'):]) elif line.startswith('Parameter'): self.addParameter(getParameterFromString(line)) elif line.startswith('AllowUnmatching'): self.allowUnmatchingGridExtents = True elif line.startswith('NoResamplingChoice'): self.noResamplingChoice = True elif line.startswith('Extent'): # An extent parameter that wraps 4 SAGA numerical parameters self.extentParamNames = line[6:].strip().split(' ') self.addParameter(ParameterExtent(self.OUTPUT_EXTENT, 'Output extent')) else: self.addOutput(getOutputFromString(line)) line = lines.readline().strip('\n').strip() hasRaster = False for param in self.parameters: if (isinstance(param, ParameterRaster) or (isinstance(param, ParameterMultipleInput) and param.datatype == ParameterMultipleInput.TYPE_RASTER)): hasRaster = True break if (not self.noResamplingChoice and hasRaster): param = ParameterSelection(self.RESAMPLING, "Resampling method", ["Nearest Neighbour", "Bilinear Interpolation", "Bicubic Spline Interpolation", "B-Spline Interpolation"], 3) param.isAdvanced = True self.addParameter(param)
def processDescriptionParameterLine(self, line): try: if line.startswith('Parameter'): self.addParameter(getParameterFromString(line)) elif line.startswith('*Parameter'): param = getParameterFromString(line[1:]) param.isAdvanced = True self.addParameter(param) else: self.addOutput(getOutputFromString(line)) except Exception: raise WrongScriptException( self.tr('Could not load script: %s.\n' 'Problem with line %d', 'ScriptAlgorithm') % (self.descriptionFile or '', line))
def defineCharacteristicsFromFile(self): with open(self.descriptionFile) as content: dom_model = ET.fromstring(content.read()) self.appkey = dom_model.find("key").text self.cliName = dom_model.find("exec").text self.name = dom_model.find("longname").text self.i18n_name = QCoreApplication.translate("OTBAlgorithm", self.name) self.group = dom_model.find("group").text self.i18n_group = QCoreApplication.translate("OTBAlgorithm", self.group) rebu = None the_result = None try: rebu = self.get_list_from_node(dom_model) the_result = list(map(self.adapt_list_to_string, rebu)) except Exception as e: ProcessingLog.addToLog( ProcessingLog.LOG_ERROR, self.tr("Could not open OTB algorithm: %s\n%s" % (self.descriptionFile, traceback.format_exc())), ) raise e for line in the_result: try: if line.startswith("Parameter") or line.startswith("*Parameter"): if line.startswith("*Parameter"): param = getParameterFromString(line[1:]) param.isAdvanced = True else: param = getParameterFromString(line) # Hack for initializing the elevation parameters from Processing configuration if param.name == "-elev.dem.path" or param.name == "-elev.dem" or "elev.dem" in param.name: param.default = OTBUtils.otbSRTMPath() elif param.name == "-elev.dem.geoid" or param.name == "-elev.geoid" or "elev.geoid" in param.name: param.default = OTBUtils.otbGeoidPath() self.addParameter(param) elif line.startswith("Extent"): self.addParameter(ParameterExtent(self.REGION_OF_INTEREST, "Region of interest", "0,1,0,1")) self.hasROI = True else: self.addOutput(getOutputFromString(line)) except Exception as e: ProcessingLog.addToLog( ProcessingLog.LOG_ERROR, self.tr("Could not open OTB algorithm: %s\n%s" % (self.descriptionFile, line)), ) raise e
def processDescriptionParameterLine(self, line): try: if line.startswith('Parameter'): self.addParameter(getParameterFromString(line)) elif line.startswith('*Parameter'): param = getParameterFromString(line[1:]) param.isAdvanced = True self.addParameter(param) else: self.addOutput(getOutputFromString(line)) except Exception: raise WrongScriptException('Could not load script:' + self.descriptionFile or '' + '.\n Problem with line "' + line + '"' )
def defineCharacteristicsFromFile(self): lines = open(self.descriptionFile) line = lines.readline().strip('\n').strip() self.grassName = line line = lines.readline().strip('\n').strip() self.name = line self.i18n_name = QCoreApplication.translate("GrassAlgorithm", line) if " - " not in self.name: self.name = self.grassName + " - " + self.name self.i18n_name = self.grassName + " - " + self.i18n_name line = lines.readline().strip('\n').strip() self.group = line self.i18n_group = QCoreApplication.translate("GrassAlgorithm", line) hasRasterOutput = False hasVectorInput = False vectorOutputs = 0 line = lines.readline().strip('\n').strip() while line != '': try: line = line.strip('\n').strip() if line.startswith('Parameter'): parameter = getParameterFromString(line) self.addParameter(parameter) if isinstance(parameter, ParameterVector): hasVectorInput = True if isinstance(parameter, ParameterMultipleInput) \ and parameter.datatype < 3: hasVectorInput = True elif line.startswith('*Parameter'): param = getParameterFromString(line[1:]) param.isAdvanced = True self.addParameter(param) else: output = getOutputFromString(line) self.addOutput(output) if isinstance(output, OutputRaster): hasRasterOutput = True elif isinstance(output, OutputVector): vectorOutputs += 1 if isinstance(output, OutputHTML): self.addOutput(OutputFile("rawoutput", output.description + " (raw output)", "txt")) line = lines.readline().strip('\n').strip() except Exception, e: ProcessingLog.addToLog( ProcessingLog.LOG_ERROR, self.tr('Could not open GRASS algorithm: %s.\n%s' % (self.descriptionFile, line))) raise e
def processCommand(alg): # We need to remove all outputs basename = getOutputFromString('OutputRaster|output|Output basename') basename.value = 'output' alg.addOutput(basename) outputNames = ['output_{}'.format(f) for f in ['red', 'green', 'blue']] outputs = [alg.getOutputFromName(f) for f in outputNames] for output in outputNames: alg.exportedLayers[alg.getOutputValue(output)] = 'output' + alg.uniqueSufix alg.removeOutputFromName(output) alg.processCommand() # And to re-add them alg.removeOutputFromName('output') for output in outputs: alg.addOutput(output)
def processCommand(alg): # We need to remove all outputs basename = getOutputFromString("OutputRaster|output|Output basename") basename.value = "output" alg.addOutput(basename) outputNames = ["output_{}".format(f) for f in ["red", "green", "blue"]] outputs = [alg.getOutputFromName(f) for f in outputNames] for output in outputNames: alg.exportedLayers[alg.getOutputValue(output)] = "output" + alg.uniqueSufix alg.removeOutputFromName(output) alg.processCommand() # And to re-add them alg.removeOutputFromName("output") for output in outputs: alg.addOutput(output)
def defineCharacteristicsFromFile(self): lines = open(self.descriptionFile) line = lines.readline().strip('\n').strip() self.name = line if '|' in self.name: tokens = self.name.split('|') self.name = tokens[0] #cmdname is the name of the algorithm in SAGA, that is, the name to use to call it in the console self.cmdname = tokens[1] else: self.cmdname = self.name self.i18n_name = QCoreApplication.translate( "SAGAAlgorithm", str(self.name)) #_commandLineName is the name used in processing to call the algorithm #Most of the time will be equal to the cmdname, but in same cases, several processing algorithms #call the same SAGA one self._commandLineName = self.createCommandLineName(self.name) self.name = decoratedAlgorithmName(self.name) self.i18n_name = QCoreApplication.translate("SAGAAlgorithm", str(self.name)) line = lines.readline().strip('\n').strip() self.undecoratedGroup = line self.group = decoratedGroupName(self.undecoratedGroup) self.i18n_group = QCoreApplication.translate("SAGAAlgorithm", self.group) line = lines.readline().strip('\n').strip() while line != '': if line.startswith('Hardcoded'): self.hardcodedStrings.append(line[len('Hardcoded|'):]) elif line.startswith('Parameter'): self.addParameter(getParameterFromString(line)) elif line.startswith('AllowUnmatching'): self.allowUnmatchingGridExtents = True elif line.startswith('Extent'): # An extent parameter that wraps 4 SAGA numerical parameters self.extentParamNames = line[6:].strip().split(' ') self.addParameter( ParameterExtent(self.OUTPUT_EXTENT, 'Output extent')) else: self.addOutput(getOutputFromString(line)) line = lines.readline().strip('\n').strip() lines.close()
def defineCharacteristicsFromFile(self): with open(self.descriptionFile) as lines: line = lines.readline().strip('\n').strip() self._name = line if '|' in self._name: tokens = self._name.split('|') self._name = tokens[0] # cmdname is the name of the algorithm in SAGA, that is, the name to use to call it in the console self.cmdname = tokens[1] else: self.cmdname = self._name self._display_name = QCoreApplication.translate( "SAGAAlgorithm", str(self._name)) self._name = decoratedAlgorithmName(self._name) self._display_name = QCoreApplication.translate( "SAGAAlgorithm", str(self._name)) self._name = self._name.lower() validChars = \ 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:' self._name = ''.join(c for c in self._name if c in validChars) line = lines.readline().strip('\n').strip() self.undecoratedGroup = line self._group = QCoreApplication.translate( "SAGAAlgorithm", decoratedGroupName(self.undecoratedGroup)) line = lines.readline().strip('\n').strip() while line != '': if line.startswith('Hardcoded'): self.hardcodedStrings.append(line[len('Hardcoded|'):]) elif line.startswith('Parameter'): self.addParameter(getParameterFromString(line)) elif line.startswith('AllowUnmatching'): self.allowUnmatchingGridExtents = True elif line.startswith('Extent'): # An extent parameter that wraps 4 SAGA numerical parameters self.extentParamNames = line[6:].strip().split(' ') self.addParameter( ParameterExtent(self.OUTPUT_EXTENT, 'Output extent')) else: self.addOutput(getOutputFromString(line)) line = lines.readline().strip('\n').strip()
def processParameterLine(self, line): param = None line = line.replace('#', '') if line.lower().strip().startswith('showplots'): self.showPlots = True self.addOutput(OutputHTML(RAlgorithm.RPLOTS, 'R Plots')) return if line.lower().strip().startswith('dontuserasterpackage'): self.useRasterPackage = False return if line.lower().strip().startswith('passfilenames'): self.passFileNames = True return tokens = line.split('=') desc = self.createDescriptiveName(tokens[0]) if tokens[1].lower().strip() == 'group': self._group = tokens[0] return if tokens[1].lower().strip() == 'name': self._name = self._display_name = tokens[0] self._name = self._name.lower() validChars = \ 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:' self._name = ''.join(c for c in self._name if c in validChars) return out = getOutputFromString(line) if out is None: param = getParameterFromString(line) if param is not None: self.addParameter(param) elif out is not None: out.name = tokens[0] out.description = desc self.addOutput(out) else: raise WrongScriptException( self.tr('Could not load script: {0}.\n' 'Problem with line "{1}"', 'ScriptAlgorithm').format(self.descriptionFile or '', line)) raise WrongScriptException( self.tr('Could not load R script: {0}.\n Problem with line {1}').format(self.descriptionFile, line))
def processParameterLine(self, line): param = None line = line.replace('#', '') if line.lower().strip().startswith('showplots'): self.showPlots = True self.addOutput(OutputHTML(RAlgorithm.RPLOTS, 'R Plots')) return if line.lower().strip().startswith('dontuserasterpackage'): self.useRasterPackage = False return if line.lower().strip().startswith('passfilenames'): self.passFileNames = True return tokens = line.split('=') desc = self.createDescriptiveName(tokens[0]) if tokens[1].lower().strip() == 'group': self.group = self.i18n_group = tokens[0] return if tokens[1].lower().strip() == 'name': self.name = self.i18n_name = tokens[0] return out = getOutputFromString(line) if out is None: param = getParameterFromString(line) if param is not None: self.addParameter(param) elif out is not None: out.name = tokens[0] out.description = desc self.addOutput(out) else: raise WrongScriptException( self.tr( 'Could not load script: {0}.\n' 'Problem with line "{1}"', 'ScriptAlgorithm').format(self.descriptionFile or '', line)) raise WrongScriptException( self.tr('Could not load R script: {0}.\n Problem with line {1}' ).format(self.descriptionFile, line))
def defineCharacteristicsFromFile(self): lines = open(self.descriptionFile) line = lines.readline().strip('\n').strip() self.name = line line = lines.readline().strip('\n').strip() self.cmdName = line line = lines.readline().strip('\n').strip() self.group = line line = lines.readline().strip('\n').strip() while line != '': try: line = line.strip('\n').strip() if line.startswith('Parameter'): param = getParameterFromString(line) self.addParameter(param) else: self.addOutput(getOutputFromString(line)) line = lines.readline().strip('\n').strip()
def processParameterLine(self, line): param = None line = line.replace("#", "") if line.lower().strip().startswith("showplots"): self.showPlots = True self.addOutput(OutputHTML(RAlgorithm.RPLOTS, "R Plots")) return if line.lower().strip().startswith("dontuserasterpackage"): self.useRasterPackage = False return if line.lower().strip().startswith("passfilenames"): self.passFileNames = True return tokens = line.split("=") desc = self.createDescriptiveName(tokens[0]) if tokens[1].lower().strip() == "group": self.group = self.i18n_group = tokens[0] return if tokens[1].lower().strip() == "name": self.name = self.i18n_name = tokens[0] return out = getOutputFromString(line) if out is None: param = getParameterFromString(line) if param is not None: self.addParameter(param) elif out is not None: out.name = tokens[0] out.description = desc self.addOutput(out) else: raise WrongScriptException( self.tr("Could not load script: %s.\n" 'Problem with line "%s"', "ScriptAlgorithm") % (self.descriptionFile or "", line) ) raise WrongScriptException( self.tr("Could not load R script: %s.\n Problem with line %s" % (self.descriptionFile, line)) )
def defineCharacteristicsFromFile(self): lines = open(self.descriptionFile) line = lines.readline().strip('\n').strip() self.grassName = line line = lines.readline().strip('\n').strip() self.name = line line = lines.readline().strip('\n').strip() self.group = line hasRasterOutput = False hasVectorInput = False vectorOutputs = 0 line = lines.readline().strip('\n').strip() while line != '': try: line = line.strip('\n').strip() if line.startswith('Parameter'): parameter = getParameterFromString(line) self.addParameter(parameter) if isinstance(parameter, ParameterVector): hasVectorInput = True if isinstance(parameter, ParameterMultipleInput) \ and parameter.datatype < 3: hasVectorInput = True elif line.startswith('*Parameter'): param = getParameterFromString(line[1:]) param.isAdvanced = True self.addParameter(param) else: output = getOutputFromString(line) self.addOutput(output) if isinstance(output, OutputRaster): hasRasterOutput = True elif isinstance(output, OutputVector): vectorOutputs += 1 line = lines.readline().strip('\n').strip() except Exception, e: ProcessingLog.addToLog( ProcessingLog.LOG_ERROR, self.tr('Could not open GRASS algorithm: %s.\n%s' % (self.descriptionFile, line))) raise e
def defineCharacteristicsFromFile(self): lines = open(self.descriptionFile) line = lines.readline().strip('\n').strip() self.grassName = line line = lines.readline().strip('\n').strip() self.name = line line = lines.readline().strip('\n').strip() self.group = line hasRasterOutput = False hasVectorInput = False vectorOutputs = 0 line = lines.readline().strip('\n').strip() while line != '': try: line = line.strip('\n').strip() if line.startswith('Parameter'): parameter = getParameterFromString(line) self.addParameter(parameter) if isinstance(parameter, ParameterVector): hasVectorInput = True if isinstance(parameter, ParameterMultipleInput) \ and parameter.datatype < 3: hasVectorInput = True elif line.startswith('*Parameter'): param = getParameterFromString(line[1:]) param.isAdvanced = True self.addParameter(param) else: output = getOutputFromString(line) self.addOutput(output) if isinstance(output, OutputRaster): hasRasterOutput = True elif isinstance(output, OutputVector): vectorOutputs += 1 line = lines.readline().strip('\n').strip() except Exception, e: ProcessingLog.addToLog( ProcessingLog.LOG_ERROR, self.tr('Could not open GRASS GIS 7 algorithm: %s\n%s' % (self.descriptionFile, line))) raise e
def defineCharacteristicsFromFile(self): with open(self.descriptionFile) as lines: line = lines.readline().strip('\n').strip() self._name = line if '|' in self._name: tokens = self._name.split('|') self._name = tokens[0] # cmdname is the name of the algorithm in SAGA, that is, the name to use to call it in the console self.cmdname = tokens[1] else: self.cmdname = self._name self._display_name = QCoreApplication.translate("SAGAAlgorithm", str(self._name)) self._name = decoratedAlgorithmName(self._name) self._display_name = QCoreApplication.translate("SAGAAlgorithm", str(self._name)) self._name = self._name.lower() validChars = \ 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:' self._name = ''.join(c for c in self._name if c in validChars) line = lines.readline().strip('\n').strip() self.undecoratedGroup = line self._group = QCoreApplication.translate("SAGAAlgorithm", decoratedGroupName(self.undecoratedGroup)) line = lines.readline().strip('\n').strip() while line != '': if line.startswith('Hardcoded'): self.hardcodedStrings.append(line[len('Hardcoded|'):]) elif line.startswith('Parameter'): self.addParameter(getParameterFromString(line)) elif line.startswith('AllowUnmatching'): self.allowUnmatchingGridExtents = True elif line.startswith('Extent'): # An extent parameter that wraps 4 SAGA numerical parameters self.extentParamNames = line[6:].strip().split(' ') self.addParameter(ParameterExtent(self.OUTPUT_EXTENT, 'Output extent')) else: self.addOutput(getOutputFromString(line)) line = lines.readline().strip('\n').strip()
def defineCharacteristicsFromFile(self): lines = open(self.descriptionFile) line = lines.readline().strip('\n').strip() self.name = line if '|' in self.name: tokens = self.name.split('|') self.name = tokens[0] #cmdname is the name of the algorithm in SAGA, that is, the name to use to call it in the console self.cmdname = tokens[1] else: self.cmdname = self.name self.i18n_name = QCoreApplication.translate("SAGAAlgorithm", unicode(self.name)) #_commandLineName is the name used in processing to call the algorithm #Most of the time will be equal to the cmdname, but in same cases, several processing algorithms #call the same SAGA one self._commandLineName = self.createCommandLineName(self.name) self.name = decoratedAlgorithmName(self.name) self.i18n_name = QCoreApplication.translate("SAGAAlgorithm", unicode(self.name)) line = lines.readline().strip('\n').strip() self.undecoratedGroup = line self.group = decoratedGroupName(self.undecoratedGroup) self.i18n_group = QCoreApplication.translate("SAGAAlgorithm", self.group) line = lines.readline().strip('\n').strip() while line != '': if line.startswith('Hardcoded'): self.hardcodedStrings.append(line[len('Hardcoded|'):]) elif line.startswith('Parameter'): self.addParameter(getParameterFromString(line)) elif line.startswith('AllowUnmatching'): self.allowUnmatchingGridExtents = True elif line.startswith('Extent'): # An extent parameter that wraps 4 SAGA numerical parameters self.extentParamNames = line[6:].strip().split(' ') self.addParameter(ParameterExtent(self.OUTPUT_EXTENT, 'Output extent', '')) else: self.addOutput(getOutputFromString(line)) line = lines.readline().strip('\n').strip() lines.close()
def processParameterLine(self, line): param = None line = line.replace('#', '') if line.lower().strip().startswith('showplots'): self.showPlots = True self.addOutput(OutputHTML(RAlgorithm.RPLOTS, 'R Plots')) return if line.lower().strip().startswith('dontuserasterpackage'): self.useRasterPackage = False return if line.lower().strip().startswith('passfilenames'): self.passFileNames = True return tokens = line.split('=') desc = self.createDescriptiveName(tokens[0]) if tokens[1].lower().strip() == 'group': self.group = self.i18n_group = tokens[0] return if tokens[1].lower().strip() == 'name': self.name = self.i18n_name = tokens[0] return out = getOutputFromString(line) if out is None: param = getParameterFromString(line) if param is not None: self.addParameter(param) elif out is not None: out.name = tokens[0] out.description = desc self.addOutput(out) else: raise WrongScriptException( self.tr('Could not load script: %s.\n' 'Problem with line "%s"', 'ScriptAlgorithm') % (self.descriptionFile or '', line)) raise WrongScriptException( self.tr('Could not load R script: %s.\n Problem with line %s' % (self.descriptionFile, line)))
def defineCharacteristicsFromFile(self): lines = open(self.descriptionFile) line = lines.readline().strip('\n').strip() self.name = line if '|' in self.name: tokens = self.name.split('|') self.name = tokens[0] self.i18n_name = QCoreApplication.translate( "SAGAAlgorithm", unicode(self.name)) self.cmdname = tokens[1] else: self.cmdname = self.name self.i18n_name = QCoreApplication.translate( "SAGAAlgorithm", unicode(self.name)) self.name = self.name[0].upper() + self.name[1:].lower() line = lines.readline().strip('\n').strip() self.undecoratedGroup = line self.group = SagaGroupNameDecorator.getDecoratedName( self.undecoratedGroup) self.i18n_group = QCoreApplication.translate("SAGAAlgorithm", self.group) line = lines.readline().strip('\n').strip() while line != '': if line.startswith('Hardcoded'): self.hardcodedStrings.append(line[len('Hardcoded|'):]) elif line.startswith('Parameter'): self.addParameter(getParameterFromString(line)) elif line.startswith('AllowUnmatching'): self.allowUnmatchingGridExtents = True elif line.startswith('Extent'): # An extent parameter that wraps 4 SAGA numerical parameters self.extentParamNames = line[6:].strip().split(' ') self.addParameter( ParameterExtent(self.OUTPUT_EXTENT, 'Output extent', '0,1,0,1')) else: self.addOutput(getOutputFromString(line)) line = lines.readline().strip('\n').strip() lines.close()
def processParameterLine(self, line): param = None line = line.replace('#', '') if line == "nomodeler": self._flags = self._flags | QgsProcessingAlgorithm.FlagHideFromModeler return if line == "nocrswarning": self.noCRSWarning = True return tokens = line.split('=', 1) desc = self.createDescriptiveName(tokens[0]) if tokens[1].lower().strip() == 'group': self._group = tokens[0] validChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:' self._groupId = ''.join(c for c in tokens[0].lower() if c in validChars) return if tokens[1].lower().strip() == 'name': self._name = self._display_name = tokens[0] return out = getOutputFromString(line) if out is None: param = getParameterFromString(line) if param is not None: self.addParameter(param) elif out is not None: out.setName(tokens[0]) out.setDescription(desc) self.addOutput(out) else: raise WrongScriptException( self.tr( 'Could not load script: {0}.\n' 'Problem with line "{1}"', 'ScriptAlgorithm').format(self.descriptionFile or '', line))
def defineCharacteristicsFromFile(self): lines = open(self.descriptionFile) line = lines.readline().strip('\n').strip() self.name = line line = lines.readline().strip('\n').strip() self.cmdName = line line = lines.readline().strip('\n').strip() self.group = line while line != '': try: line = line.strip('\n').strip() if line.startswith('Parameter'): param = getParameterFromString(line) self.addParameter(param) else: self.addOutput(getOutputFromString(line)) line = lines.readline().strip('\n').strip() except Exception, e: ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, 'Could not load TauDEM algorithm: ' + self.descriptionFile + '\n' + line) raise e
def defineCharacteristicsFromFile(self): lines = open(self.descriptionFile) line = lines.readline().strip("\n").strip() self.operator = line line = lines.readline().strip("\n").strip() self.description = line line = lines.readline().strip("\n").strip() self.name = line line = lines.readline().strip("\n").strip() self.group = line line = lines.readline().strip("\n").strip() while line != "": try: if line.startswith("Parameter"): try: # Initialize GPF specific parameters ... param = GPFParameters.getParameterFromString(line) except AttributeError: # ... and generic Processing parameters param = getParameterFromString(line) self.addParameter(param) elif line.startswith("*Parameter"): try: param = GPFParameters.getParameterFromString(line[1:]) except AttributeError: param = getParameterFromString(line[1:]) param.isAdvanced = True self.addParameter(param) elif line.startswith("OutputRaster"): self.addOutput(GPFRasterOutput.getOutputFromString(line)) else: self.addOutput(getOutputFromString(line)) line = lines.readline().strip("\n").strip() except Exception, e: ProcessingLog.addToLog( ProcessingLog.LOG_ERROR, "Could not open GPF algorithm: " + self.descriptionFile + "\n" + line) raise e
def defineCharacteristicsFromFile(self): lines = open(self.descriptionFile) line = lines.readline().strip('\n').strip() self.name = line line = lines.readline().strip('\n').strip() self.cmdName = line line = lines.readline().strip('\n').strip() self.group = line line = lines.readline().strip('\n').strip() while line != '': try: line = line.strip('\n').strip() if line.startswith('Parameter'): param = getParameterFromString(line) self.addParameter(param) else: self.addOutput(getOutputFromString(line)) line = lines.readline().strip('\n').strip() except Exception, e: ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, self.tr('Could not load TauDEM algorithm: %s\n%s' % (self.descriptionFile, line))) raise e
def processParameterLine(self, line): param = None line = line.replace('#', '') if line == "nomodeler": self.showInModeler = False return if line == "nocrswarning": self.noCRSWarning = True return tokens = line.split('=', 1) desc = self.createDescriptiveName(tokens[0]) if tokens[1].lower().strip() == 'group': self.group = self.i18n_group = tokens[0] return if tokens[1].lower().strip() == 'name': self.name = self.i18n_name = tokens[0] return out = getOutputFromString(line) if out is None: param = getParameterFromString(line) if param is not None: self.addParameter(param) elif out is not None: out.name = tokens[0] out.description = desc self.addOutput(out) else: raise WrongScriptException( self.tr( 'Could not load script: {0}.\n' 'Problem with line "{1}"', 'ScriptAlgorithm').format(self.descriptionFile or '', line))
def defineCharacteristicsFromFile(self): lines = open(self.descriptionFile) line = lines.readline().strip('\n').strip() self.grass7Name = line line = lines.readline().strip('\n').strip() self.name = line self.i18n_name = QCoreApplication.translate("GrassAlgorithm", line) if " - " not in self.name: self.name = self.grass7Name + " - " + self.name self.i18n_name = self.grass7Name + " - " + self.i18n_name line = lines.readline().strip('\n').strip() self.group = line self.i18n_group = QCoreApplication.translate("GrassAlgorithm", line) hasRasterOutput = False hasVectorInput = False vectorOutputs = 0 line = lines.readline().strip('\n').strip() while line != '': try: line = line.strip('\n').strip() if line.startswith('Hardcoded'): self.hardcodedStrings.append(line[len('Hardcoded|'):]) elif line.startswith('Parameter'): parameter = getParameterFromString(line) self.addParameter(parameter) if isinstance(parameter, ParameterVector): hasVectorInput = True if isinstance(parameter, ParameterMultipleInput) \ and parameter.datatype < 3: hasVectorInput = True elif line.startswith('*Parameter'): param = getParameterFromString(line[1:]) param.isAdvanced = True self.addParameter(param) else: output = getOutputFromString(line) self.addOutput(output) if isinstance(output, OutputRaster): hasRasterOutput = True elif isinstance(output, OutputVector): vectorOutputs += 1 if isinstance(output, OutputHTML): self.addOutput( OutputFile("rawoutput", output.description + " (raw output)", "txt")) line = lines.readline().strip('\n').strip() except Exception as e: ProcessingLog.addToLog( ProcessingLog.LOG_ERROR, self.tr('Could not open GRASS GIS 7 algorithm: %s\n%s' % (self.descriptionFile, line))) raise e lines.close() self.addParameter( ParameterExtent(self.GRASS_REGION_EXTENT_PARAMETER, self.tr('GRASS GIS 7 region extent'))) if hasRasterOutput: self.addParameter( ParameterNumber( self.GRASS_REGION_CELLSIZE_PARAMETER, self.tr( 'GRASS GIS 7 region cellsize (leave 0 for default)'), 0, None, 0.0)) if hasVectorInput: param = ParameterNumber(self.GRASS_SNAP_TOLERANCE_PARAMETER, 'v.in.ogr snap tolerance (-1 = no snap)', -1, None, -1.0) param.isAdvanced = True self.addParameter(param) param = ParameterNumber(self.GRASS_MIN_AREA_PARAMETER, 'v.in.ogr min area', 0, None, 0.0001) param.isAdvanced = True self.addParameter(param) if vectorOutputs == 1: param = ParameterSelection(self.GRASS_OUTPUT_TYPE_PARAMETER, 'v.out.ogr output type', self.OUTPUT_TYPES) param.isAdvanced = True self.addParameter(param)
def defineCharacteristicsFromFile(self): with open(self.descriptionFile) as lines: line = lines.readline().strip('\n').strip() self.grass7Name = line line = lines.readline().strip('\n').strip() self._name = line self._display_name = QCoreApplication.translate("GrassAlgorithm", line) if " - " not in self._name: self._name = self.grass7Name + " - " + self._name self._display_name = self.grass7Name + " - " + self._display_name self._name = self._name[:self._name.find(' ')].lower() line = lines.readline().strip('\n').strip() self._group = QCoreApplication.translate("GrassAlgorithm", line) hasRasterOutput = False hasVectorInput = False vectorOutputs = 0 line = lines.readline().strip('\n').strip() while line != '': try: line = line.strip('\n').strip() if line.startswith('Hardcoded'): self.hardcodedStrings.append(line[len('Hardcoded|'):]) parameter = getParameterFromString(line) if parameter is not None: self.addParameter(parameter) if isinstance(parameter, ParameterVector): hasVectorInput = True if isinstance(parameter, ParameterMultipleInput) \ and parameter.datatype < 3: hasVectorInput = True else: output = getOutputFromString(line) self.addOutput(output) if isinstance(output, OutputRaster): hasRasterOutput = True elif isinstance(output, OutputVector): vectorOutputs += 1 if isinstance(output, OutputHTML): self.addOutput(OutputFile("rawoutput", self.tr("{0} (raw output)").format(output.description()), "txt")) line = lines.readline().strip('\n').strip() except Exception as e: QgsMessageLog.logMessage(self.tr('Could not open GRASS GIS 7 algorithm: {0}\n{1}').format(self.descriptionFile, line), self.tr('Processing'), QgsMessageLog.CRITICAL) raise e self.addParameter(ParameterExtent( self.GRASS_REGION_EXTENT_PARAMETER, self.tr('GRASS GIS 7 region extent')) ) if hasRasterOutput: self.addParameter(ParameterNumber( self.GRASS_REGION_CELLSIZE_PARAMETER, self.tr('GRASS GIS 7 region cellsize (leave 0 for default)'), 0, None, 0.0)) if hasVectorInput: param = ParameterNumber(self.GRASS_SNAP_TOLERANCE_PARAMETER, 'v.in.ogr snap tolerance (-1 = no snap)', -1, None, -1.0) param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced) self.addParameter(param) param = ParameterNumber(self.GRASS_MIN_AREA_PARAMETER, 'v.in.ogr min area', 0, None, 0.0001) param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced) self.addParameter(param) if vectorOutputs == 1: param = ParameterSelection(self.GRASS_OUTPUT_TYPE_PARAMETER, 'v.out.ogr output type', self.OUTPUT_TYPES) param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced) self.addParameter(param)
def defineCharacteristicsFromFile(self): lines = open(self.descriptionFile) line = lines.readline().strip('\n').strip() self.grass7Name = line line = lines.readline().strip('\n').strip() self.name = line self.i18n_name = QCoreApplication.translate("GrassAlgorithm", line) if " - " not in self.name: self.name = self.grass7Name + " - " + self.name self.i18n_name = self.grass7Name + " - " + self.i18n_name line = lines.readline().strip('\n').strip() self.group = line self.i18n_group = QCoreApplication.translate("GrassAlgorithm", line) hasRasterOutput = False hasVectorInput = False vectorOutputs = 0 line = lines.readline().strip('\n').strip() while line != '': try: line = line.strip('\n').strip() if line.startswith('Parameter'): parameter = getParameterFromString(line) self.addParameter(parameter) if isinstance(parameter, ParameterVector): hasVectorInput = True if isinstance(parameter, ParameterMultipleInput) \ and parameter.datatype < 3: hasVectorInput = True elif line.startswith('*Parameter'): param = getParameterFromString(line[1:]) param.isAdvanced = True self.addParameter(param) else: output = getOutputFromString(line) self.addOutput(output) if isinstance(output, OutputRaster): hasRasterOutput = True elif isinstance(output, OutputVector): vectorOutputs += 1 line = lines.readline().strip('\n').strip() except Exception as e: ProcessingLog.addToLog( ProcessingLog.LOG_ERROR, self.tr('Could not open GRASS GIS 7 algorithm: %s\n%s' % (self.descriptionFile, line))) raise e lines.close() self.addParameter(ParameterExtent( self.GRASS_REGION_EXTENT_PARAMETER, self.tr('GRASS GIS 7 region extent')) ) if hasRasterOutput: self.addParameter(ParameterNumber( self.GRASS_REGION_CELLSIZE_PARAMETER, self.tr('GRASS GIS 7 region cellsize (leave 0 for default)'), 0, None, 0.0)) if hasVectorInput: param = ParameterNumber(self.GRASS_SNAP_TOLERANCE_PARAMETER, 'v.in.ogr snap tolerance (-1 = no snap)', -1, None, -1.0) param.isAdvanced = True self.addParameter(param) param = ParameterNumber(self.GRASS_MIN_AREA_PARAMETER, 'v.in.ogr min area', 0, None, 0.0001) param.isAdvanced = True self.addParameter(param) if vectorOutputs == 1: param = ParameterSelection(self.GRASS_OUTPUT_TYPE_PARAMETER, 'v.out.ogr output type', self.OUTPUT_TYPES) param.isAdvanced = True self.addParameter(param)
class OTBAlgorithm(GeoAlgorithm): REGION_OF_INTEREST = "ROI" def __init__(self, descriptionfile): GeoAlgorithm.__init__(self) self.roiFile = None self.descriptionFile = descriptionfile self.defineCharacteristicsFromFile() self.numExportedLayers = 0 self.hasROI = None def __str__(self): return ("Algo : " + self.name + " from app : " + self.cliName + " in : " + self.group) def getCopy(self): newone = OTBAlgorithm(self.descriptionFile) newone.provider = self.provider return newone def getIcon(self): return PyQt4.QtGui.QIcon( os.path.dirname(__file__) + "/../../images/otb.png") def help(self): folder = os.path.join(OTBUtils.otbDescriptionPath(), 'doc') helpfile = os.path.join(str(folder), self.appkey + ".html") if os.path.exists(helpfile): return False, helpfile else: raise False, None def adapt_list_to_string(self, c_list): a_list = c_list[1:] if a_list[0] in ["ParameterVector", "ParameterMultipleInput"]: if c_list[0] == "ParameterType_InputImageList": a_list[3] = 3 elif c_list[0] == "ParameterType_InputFilenameList": a_list[3] = 4 else: a_list[3] = -1 a_list[1] = "-%s" % a_list[1] def mystr(par): if type(par) == type([]): return ";".join(par) return str(par) b_list = map(mystr, a_list) res = "|".join(b_list) return res def get_list_from_node(self, myet): all_params = [] for parameter in myet.iter('parameter'): rebuild = [] par_type = parameter.find('parameter_type').text key = parameter.find('key').text name = parameter.find('name').text source_par_type = parameter.find( 'parameter_type').attrib['source_parameter_type'] rebuild.append(source_par_type) rebuild.append(par_type) rebuild.append(key) rebuild.append(name) for each in parameter[4:]: if not each.tag in ["hidden"]: if len(list(each)) == 0: rebuild.append(each.text) else: rebuild.append( [item.text for item in each.iter('choice')]) all_params.append(rebuild) return all_params def defineCharacteristicsFromFile(self): content = open(self.descriptionFile).read() dom_model = ET.fromstring(content) self.appkey = dom_model.find('key').text self.cliName = dom_model.find('exec').text self.name = dom_model.find('longname').text self.group = dom_model.find('group').text #ProcessingLog.addToLog(ProcessingLog.LOG_INFO, "Reading parameters for %s" % self.appkey) rebu = None the_result = None try: rebu = self.get_list_from_node(dom_model) the_result = map(self.adapt_list_to_string, rebu) except Exception, e: ProcessingLog.addToLog( ProcessingLog.LOG_ERROR, "Could not open OTB algorithm: " + self.descriptionFile + "\n" + traceback.format_exc()) raise e for line in the_result: try: if line.startswith("Parameter") or line.startswith( "*Parameter"): if line.startswith("*Parameter"): param = getParameterFromString(line[1:]) param.isAdvanced = True else: param = getParameterFromString(line) # Hack for initializing the elevation parameters from Processing configuration if param.name == "-elev.dem.path" or param.name == "-elev.dem" or "elev.dem" in param.name: param.default = OTBUtils.otbSRTMPath() elif param.name == "-elev.dem.geoid" or param.name == "-elev.geoid" or "elev.geoid" in param.name: param.default = OTBUtils.otbGeoidPath() self.addParameter(param) elif line.startswith("Extent"): self.addParameter( ParameterExtent(self.REGION_OF_INTEREST, "Region of interest", "0,1,0,1")) self.hasROI = True else: self.addOutput(getOutputFromString(line)) except Exception, e: ProcessingLog.addToLog( ProcessingLog.LOG_ERROR, "Could not open OTB algorithm: " + self.descriptionFile + "\n" + line) raise e
def defineCharacteristicsFromFile(self): with open(self.descriptionFile) as lines: line = lines.readline().strip('\n').strip() self.grass7Name = line line = lines.readline().strip('\n').strip() self._name = line self._display_name = QCoreApplication.translate( "GrassAlgorithm", line) if " - " not in self._name: self._name = self.grass7Name + " - " + self._name self._display_name = self.grass7Name + " - " + self._display_name self._name = self._name[:self._name.find(' ')].lower() line = lines.readline().strip('\n').strip() self._group = QCoreApplication.translate("GrassAlgorithm", line) hasRasterOutput = False hasVectorInput = False vectorOutputs = 0 line = lines.readline().strip('\n').strip() while line != '': try: line = line.strip('\n').strip() if line.startswith('Hardcoded'): self.hardcodedStrings.append(line[len('Hardcoded|'):]) parameter = getParameterFromString(line) if parameter is not None: self.addParameter(parameter) if isinstance(parameter, ParameterVector): hasVectorInput = True if isinstance(parameter, ParameterMultipleInput) \ and parameter.datatype < 3: hasVectorInput = True else: output = getOutputFromString(line) self.addOutput(output) if isinstance(output, OutputRaster): hasRasterOutput = True elif isinstance(output, OutputVector): vectorOutputs += 1 if isinstance(output, OutputHTML): self.addOutput( OutputFile( "rawoutput", self.tr("{0} (raw output)").format( output.description), "txt")) line = lines.readline().strip('\n').strip() except Exception as e: QgsMessageLog.logMessage( self.tr( 'Could not open GRASS GIS 7 algorithm: {0}\n{1}'). format(self.descriptionFile, line), self.tr('Processing'), QgsMessageLog.CRITICAL) raise e self.addParameter( ParameterExtent(self.GRASS_REGION_EXTENT_PARAMETER, self.tr('GRASS GIS 7 region extent'))) if hasRasterOutput: self.addParameter( ParameterNumber( self.GRASS_REGION_CELLSIZE_PARAMETER, self.tr( 'GRASS GIS 7 region cellsize (leave 0 for default)'), 0, None, 0.0)) if hasVectorInput: param = ParameterNumber(self.GRASS_SNAP_TOLERANCE_PARAMETER, 'v.in.ogr snap tolerance (-1 = no snap)', -1, None, -1.0) param.isAdvanced = True self.addParameter(param) param = ParameterNumber(self.GRASS_MIN_AREA_PARAMETER, 'v.in.ogr min area', 0, None, 0.0001) param.isAdvanced = True self.addParameter(param) if vectorOutputs == 1: param = ParameterSelection(self.GRASS_OUTPUT_TYPE_PARAMETER, 'v.out.ogr output type', self.OUTPUT_TYPES) param.isAdvanced = True self.addParameter(param)
def defineCharacteristicsFromFile(self): with open(self.descriptionFile) as lines: line = lines.readline().strip("\n").strip() self.grass7Name = line line = lines.readline().strip("\n").strip() self.name = line self.i18n_name = QCoreApplication.translate("GrassAlgorithm", line) if " - " not in self.name: self.name = self.grass7Name + " - " + self.name self.i18n_name = self.grass7Name + " - " + self.i18n_name line = lines.readline().strip("\n").strip() self.group = line self.i18n_group = QCoreApplication.translate("GrassAlgorithm", line) hasRasterOutput = False hasVectorInput = False vectorOutputs = 0 line = lines.readline().strip("\n").strip() while line != "": try: line = line.strip("\n").strip() if line.startswith("Hardcoded"): self.hardcodedStrings.append(line[len("Hardcoded|") :]) parameter = getParameterFromString(line) if parameter is not None: self.addParameter(parameter) if isinstance(parameter, ParameterVector): hasVectorInput = True if isinstance(parameter, ParameterMultipleInput) and parameter.datatype < 3: hasVectorInput = True else: output = getOutputFromString(line) self.addOutput(output) if isinstance(output, OutputRaster): hasRasterOutput = True elif isinstance(output, OutputVector): vectorOutputs += 1 if isinstance(output, OutputHTML): self.addOutput(OutputFile("rawoutput", output.description + " (raw output)", "txt")) line = lines.readline().strip("\n").strip() except Exception as e: ProcessingLog.addToLog( ProcessingLog.LOG_ERROR, self.tr("Could not open GRASS GIS 7 algorithm: %s\n%s" % (self.descriptionFile, line)), ) raise e self.addParameter(ParameterExtent(self.GRASS_REGION_EXTENT_PARAMETER, self.tr("GRASS GIS 7 region extent"))) if hasRasterOutput: self.addParameter( ParameterNumber( self.GRASS_REGION_CELLSIZE_PARAMETER, self.tr("GRASS GIS 7 region cellsize (leave 0 for default)"), 0, None, 0.0, ) ) if hasVectorInput: param = ParameterNumber( self.GRASS_SNAP_TOLERANCE_PARAMETER, "v.in.ogr snap tolerance (-1 = no snap)", -1, None, -1.0 ) param.isAdvanced = True self.addParameter(param) param = ParameterNumber(self.GRASS_MIN_AREA_PARAMETER, "v.in.ogr min area", 0, None, 0.0001) param.isAdvanced = True self.addParameter(param) if vectorOutputs == 1: param = ParameterSelection(self.GRASS_OUTPUT_TYPE_PARAMETER, "v.out.ogr output type", self.OUTPUT_TYPES) param.isAdvanced = True self.addParameter(param)