Exemplo n.º 1
0
    def processParameterLine(self, line):
        param = None
        out = 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().startswith('raster'):
            param = ParameterRaster(tokens[0], desc, False)
        elif tokens[1].lower().strip() == 'vector':
            param = ParameterVector(tokens[0], desc,
                                    [ParameterVector.VECTOR_TYPE_ANY])
        elif tokens[1].lower().strip() == 'vector point':
            param = ParameterVector(tokens[0], desc,
                                    [ParameterVector.VECTOR_TYPE_POINT])
        elif tokens[1].lower().strip() == 'vector line':
            param = ParameterVector(tokens[0], desc,
                                    [ParameterVector.VECTOR_TYPE_LINE])
        elif tokens[1].lower().strip() == 'vector polygon':
            param = ParameterVector(tokens[0], desc,
                                    [ParameterVector.VECTOR_TYPE_POLYGON])
        elif tokens[1].lower().strip() == 'table':
            param = ParameterTable(tokens[0], desc, False)
        elif tokens[1].lower().strip().startswith('multiple raster'):
            param = ParameterMultipleInput(tokens[0], desc,
                                           ParameterMultipleInput.TYPE_RASTER)
            param.optional = False
        elif tokens[1].lower().strip() == 'multiple vector':
            param = ParameterMultipleInput(
                tokens[0], desc, ParameterMultipleInput.TYPE_VECTOR_ANY)
            param.optional = False
        elif tokens[1].lower().strip().startswith('selection'):
            options = tokens[1].strip()[len('selection'):].split(';')
            param = ParameterSelection(tokens[0], desc, options)
        elif tokens[1].lower().strip().startswith('boolean'):
            default = tokens[1].strip()[len('boolean') + 1:]
            param = ParameterBoolean(tokens[0], desc, default)
        elif tokens[1].lower().strip().startswith('number'):
            try:
                default = float(tokens[1].strip()[len('number') + 1:])
                param = ParameterNumber(tokens[0], desc, default=default)
            except:
                raise WrongScriptException(
                    self.tr(
                        'Could not load R script: %s.\n Problem with line %s' %
                        (self.descriptionFile, line)))
        elif tokens[1].lower().strip().startswith('field'):
            field = tokens[1].strip()[len('field') + 1:]
            found = False
            for p in self.parameters:
                if p.name == field:
                    found = True
                    break
            if found:
                param = ParameterTableField(tokens[0], tokens[0], field)
        elif tokens[1].lower().strip() == 'extent':
            param = ParameterExtent(tokens[0], desc)
        elif tokens[1].lower().strip() == 'point':
            param = ParameterPoint(tokens[0], desc)
        elif tokens[1].lower().strip() == 'file':
            param = ParameterFile(tokens[0], desc, False)
        elif tokens[1].lower().strip() == 'folder':
            param = ParameterFile(tokens[0], desc, True)
        elif tokens[1].lower().strip().startswith('string'):
            default = tokens[1].strip()[len('string') + 1:]
            param = ParameterString(tokens[0], desc, default)
        elif tokens[1].lower().strip().startswith('longstring'):
            default = tokens[1].strip()[len('longstring') + 1:]
            param = ParameterString(tokens[0], desc, default, multiline=True)
        elif tokens[1].lower().strip().startswith('output raster'):
            out = OutputRaster()
        elif tokens[1].lower().strip().startswith('output vector'):
            out = OutputVector()
        elif tokens[1].lower().strip().startswith('output table'):
            out = OutputTable()
        elif tokens[1].lower().strip().startswith('output file'):
            out = OutputFile()

        if param is not None:
            self.addParameter(param)
        elif out is not None:
            out.name = tokens[0]
            out.description = tokens[0]
            self.addOutput(out)
        else:
            raise WrongScriptException(
                self.tr('Could not load R script: %s.\n Problem with line %s' %
                        (self.descriptionFile, line)))
Exemplo n.º 2
0
    def processParameterLine(self, line):
        param = None
        out = 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().startswith('raster'):
            param = ParameterRaster(tokens[0], desc, False)
        elif tokens[1].lower().strip() == 'vector':
            param = ParameterVector(tokens[0], desc,
                                    [ParameterVector.VECTOR_TYPE_ANY])
        elif tokens[1].lower().strip() == 'vector point':
            param = ParameterVector(tokens[0], desc,
                                    [ParameterVector.VECTOR_TYPE_POINT])
        elif tokens[1].lower().strip() == 'vector line':
            param = ParameterVector(tokens[0], desc,
                                    [ParameterVector.VECTOR_TYPE_LINE])
        elif tokens[1].lower().strip() == 'vector polygon':
            param = ParameterVector(tokens[0], desc,
                                    [ParameterVector.VECTOR_TYPE_POLYGON])
        elif tokens[1].lower().strip() == 'table':
            param = ParameterTable(tokens[0], desc, False)
        elif tokens[1].lower().strip().startswith('multiple raster'):
            param = ParameterMultipleInput(tokens[0], desc,
                                           ParameterMultipleInput.TYPE_RASTER)
            param.optional = False
        elif tokens[1].lower().strip() == 'multiple vector':
            param = ParameterMultipleInput(tokens[0], desc,
                                           ParameterMultipleInput.TYPE_VECTOR_ANY)
            param.optional = False
        elif tokens[1].lower().strip().startswith('selection'):
            options = tokens[1].strip()[len('selection'):].split(';')
            param = ParameterSelection(tokens[0], desc, options)
        elif tokens[1].lower().strip().startswith('boolean'):
            default = tokens[1].strip()[len('boolean') + 1:]
            param = ParameterBoolean(tokens[0], desc, default)
        elif tokens[1].lower().strip().startswith('number'):
            try:
                default = float(tokens[1].strip()[len('number') + 1:])
                param = ParameterNumber(tokens[0], desc, default=default)
            except:
                raise WrongScriptException(
                    self.tr('Could not load R script: %s.\n Problem with line %s' % (self.descriptionFile, line)))
        elif tokens[1].lower().strip().startswith('field'):
            field = tokens[1].strip()[len('field') + 1:]
            found = False
            for p in self.parameters:
                if p.name == field:
                    found = True
                    break
            if found:
                param = ParameterTableField(tokens[0], tokens[0], field)
        elif tokens[1].lower().strip() == 'extent':
            param = ParameterExtent(tokens[0], desc)
        elif tokens[1].lower().strip() == 'crs':
            param = ParameterCrs(tokens[0], desc)
        elif tokens[1].lower().strip() == 'point':
            param = ParameterPoint(tokens[0], desc)
        elif tokens[1].lower().strip() == 'file':
            param = ParameterFile(tokens[0], desc, False)
        elif tokens[1].lower().strip() == 'folder':
            param = ParameterFile(tokens[0], desc, True)
        elif tokens[1].lower().strip().startswith('string'):
            default = tokens[1].strip()[len('string') + 1:]
            param = ParameterString(tokens[0], desc, default)
        elif tokens[1].lower().strip().startswith('longstring'):
            default = tokens[1].strip()[len('longstring') + 1:]
            param = ParameterString(tokens[0], desc, default, multiline=True)
        elif tokens[1].lower().strip().startswith('output raster'):
            out = OutputRaster()
        elif tokens[1].lower().strip().startswith('output vector'):
            out = OutputVector()
        elif tokens[1].lower().strip().startswith('output table'):
            out = OutputTable()
        elif tokens[1].lower().strip().startswith('output file'):
            out = OutputFile()

        if param is not None:
            self.addParameter(param)
        elif out is not None:
            out.name = tokens[0]
            out.description = tokens[0]
            self.addOutput(out)
        else:
            raise WrongScriptException(
                self.tr('Could not load R script: %s.\n Problem with line %s' % (self.descriptionFile, line)))
Exemplo n.º 3
0
 def processInputParameterToken(self, token, name):
     param = None
     
     descName = self.createDescriptiveName(name)
     
     if token.lower().strip() == 'raster':
         param = ParameterRaster(name, descName, False)
     elif token.lower().strip() == 'vector':
         param = ParameterVector(name, descName,
                                 [ParameterVector.VECTOR_TYPE_ANY])
     elif token.lower().strip() == 'vector point':
         param = ParameterVector(name, descName,
                                 [ParameterVector.VECTOR_TYPE_POINT])
     elif token.lower().strip() == 'vector line':
         param = ParameterVector(name, descName,
                                 [ParameterVector.VECTOR_TYPE_LINE])
     elif token.lower().strip() == 'vector polygon':
         param = ParameterVector(name, descName,
                                 [ParameterVector.VECTOR_TYPE_POLYGON])
     elif token.lower().strip() == 'table':
         param = ParameterTable(name, descName, False)
     elif token.lower().strip() == 'multiple raster':
         param = ParameterMultipleInput(name, descName,
                                        ParameterMultipleInput.TYPE_RASTER)
         param.optional = False
     elif token.lower().strip() == 'multiple vector':
         param = ParameterMultipleInput(name, descName,
                                        ParameterMultipleInput.TYPE_VECTOR_ANY)
         param.optional = False
     elif token.lower().strip().startswith('selectionfromfile'):
         options = token.strip()[len('selectionfromfile '):].split(';')
         param = ParameterSelection(name, descName, options, isSource=True)
     elif token.lower().strip().startswith('selection'):
         options = tokens[1].strip()[len('selection '):].split(';')
         param = ParameterSelection(name, descName, options)
     elif token.lower().strip().startswith('boolean'):
         default = token.strip()[len('boolean') + 1:]
         param = ParameterBoolean(name, descName, default)
     elif token.lower().strip() == 'extent':
         param = ParameterExtent(name, descName)
     elif token.lower().strip() == 'file':
         param = ParameterFile(name, descName, False)
     elif token.lower().strip() == 'folder':
         param = ParameterFile(name, descName, True)
     elif token.lower().strip().startswith('number'):
         default = token.strip()[len('number') + 1:]
         param = ParameterNumber(name, descName, default=default)
     elif token.lower().strip().startswith('field'):
         field = token.strip()[len('field') + 1:]
         found = False
         for p in self.parameters:
             if p.name == field:
                 found = True
                 break
         if found:
             param = ParameterTableField(name, descName, field)
     elif token.lower().strip().startswith('string'):
         default = token.strip()[len('string') + 1:]
         param = ParameterString(name, descName, default)
     elif token.lower().strip().startswith('longstring'):
         default = token.strip()[len('longstring') + 1:]
         param = ParameterString(name, descName, default, multiline=True)
     elif token.lower().strip().startswith('crs'):
         default = token.strip()[len('crs') + 1:]
         if not default:
             default = 'EPSG:4326'
         param = ParameterCrs(name, descName, default)
         
     return param
Exemplo n.º 4
0
    def processParameterLine(self, line):
        param = None
        out = None
        line = line.replace('#', '')

        # If the line is in the format of the text description files for
        # normal algorithms, then process it using parameter and output
        # factories
        if '|' in line:
            self.processDescriptionParameterLine(line)
            return
        if line == "nomodeler":
            self.showInModeler = False
            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
        if tokens[1].lower().strip() == 'raster':
            param = ParameterRaster(tokens[0], desc, False)
        elif tokens[1].lower().strip() == 'vector':
            param = ParameterVector(tokens[0], desc,
                                    [ParameterVector.VECTOR_TYPE_ANY])
        elif tokens[1].lower().strip() == 'vector point':
            param = ParameterVector(tokens[0], desc,
                                    [ParameterVector.VECTOR_TYPE_POINT])
        elif tokens[1].lower().strip() == 'vector line':
            param = ParameterVector(tokens[0], desc,
                                    [ParameterVector.VECTOR_TYPE_LINE])
        elif tokens[1].lower().strip() == 'vector polygon':
            param = ParameterVector(tokens[0], desc,
                                    [ParameterVector.VECTOR_TYPE_POLYGON])
        elif tokens[1].lower().strip() == 'table':
            param = ParameterTable(tokens[0], desc, False)
        elif tokens[1].lower().strip() == 'multiple raster':
            param = ParameterMultipleInput(tokens[0], desc,
                    ParameterMultipleInput.TYPE_RASTER)
            param.optional = False
        elif tokens[1].lower().strip() == 'multiple vector':
            param = ParameterMultipleInput(tokens[0], desc,
                    ParameterMultipleInput.TYPE_VECTOR_ANY)
            param.optional = False
        elif tokens[1].lower().strip().startswith('selectionfromfile'):
            options = tokens[1].strip()[len('selectionfromfile '):].split(';')
            param = ParameterSelection(tokens[0], desc, options, isSource=True)
        elif tokens[1].lower().strip().startswith('selection'):
            options = tokens[1].strip()[len('selection '):].split(';')
            param = ParameterSelection(tokens[0], desc, options)
        elif tokens[1].lower().strip().startswith('boolean'):
            default = tokens[1].strip()[len('boolean') + 1:]
            param = ParameterBoolean(tokens[0], desc, default)
        elif tokens[1].lower().strip() == 'extent':
            param = ParameterExtent(tokens[0], desc)
        elif tokens[1].lower().strip() == 'file':
            param = ParameterFile(tokens[0], desc, False)
        elif tokens[1].lower().strip() == 'folder':
            param = ParameterFile(tokens[0], desc, True)
        elif tokens[1].lower().strip().startswith('number'):
            default = tokens[1].strip()[len('number') + 1:]
            param = ParameterNumber(tokens[0], desc, default=default)
        elif tokens[1].lower().strip().startswith('field'):
            field = tokens[1].strip()[len('field') + 1:]
            found = False
            for p in self.parameters:
                if p.name == field:
                    found = True
                    break
            if found:
                param = ParameterTableField(tokens[0], desc, field)
        elif tokens[1].lower().strip().startswith('string'):
            default = tokens[1].strip()[len('string') + 1:]
            param = ParameterString(tokens[0], desc, default)
        elif tokens[1].lower().strip().startswith('longstring'):
            default = tokens[1].strip()[len('longstring') + 1:]
            param = ParameterString(tokens[0], desc, default, multiline=True)
        elif tokens[1].lower().strip().startswith('crs'):
            default = tokens[1].strip()[len('crs') + 1:]
            if not default:
                default = 'EPSG:4326'
            param = ParameterCrs(tokens[0], desc, default)
        elif tokens[1].lower().strip().startswith('output raster'):
            out = OutputRaster()
        elif tokens[1].lower().strip().startswith('output vector'):
            out = OutputVector()
        elif tokens[1].lower().strip().startswith('output table'):
            out = OutputTable()
        elif tokens[1].lower().strip().startswith('output html'):
            out = OutputHTML()
        elif tokens[1].lower().strip().startswith('output file'):
            out = OutputFile()
            subtokens = tokens[1].split(' ')
            if len(subtokens) > 2:
                out.ext = subtokens[2]
        elif tokens[1].lower().strip().startswith('output directory'):
            out = OutputDirectory()
        elif tokens[1].lower().strip().startswith('output number'):
            out = OutputNumber()
        elif tokens[1].lower().strip().startswith('output string'):
            out = OutputString()

        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))
Exemplo n.º 5
0
    def processInputParameterToken(self, token, name):
        param = None

        descName = self.createDescriptiveName(name)

        if token.lower().strip() == 'raster':
            param = ParameterRaster(name, descName, False)
        elif token.lower().strip() == 'vector':
            param = ParameterVector(name, descName,
                                    [dataobjects.TYPE_VECTOR_ANY])
        elif token.lower().strip() == 'vector point':
            param = ParameterVector(name, descName,
                                    [dataobjects.TYPE_VECTOR_POINT])
        elif token.lower().strip() == 'vector line':
            param = ParameterVector(name, descName,
                                    [dataobjects.TYPE_VECTOR_LINE])
        elif token.lower().strip() == 'vector polygon':
            param = ParameterVector(name, descName,
                                    [dataobjects.TYPE_VECTOR_POLYGON])
        elif token.lower().strip() == 'table':
            param = ParameterTable(name, descName, False)
        elif token.lower().strip() == 'multiple raster':
            param = ParameterMultipleInput(name, descName,
                                           dataobjects.TYPE_RASTER)
            param.optional = False
        elif token.lower().strip() == 'multiple vector':
            param = ParameterMultipleInput(name, descName,
                                           dataobjects.TYPE_VECTOR_ANY)
            param.optional = False
        elif token.lower().strip().startswith('selectionfromfile'):
            options = token.strip()[len('selectionfromfile '):].split(';')
            param = ParameterSelection(name, descName, options, isSource=True)
        elif token.lower().strip().startswith('selection'):
            options = token.strip()[len('selection '):].split(';')
            param = ParameterSelection(name, descName, options)
        elif token.lower().strip().startswith('boolean'):
            default = token.strip()[len('boolean') + 1:]
            if default:
                param = ParameterBoolean(name, descName, default)
            else:
                param = ParameterBoolean(name, descName)
        elif token.lower().strip() == 'extent':
            param = ParameterExtent(name, descName)
        elif token.lower().strip() == 'point':
            param = ParameterPoint(name, descName)
        elif token.lower().strip() == 'file':
            param = ParameterFile(name, descName, False)
        elif token.lower().strip() == 'folder':
            param = ParameterFile(name, descName, True)
        elif token.lower().strip().startswith('number'):
            default = token.strip()[len('number') + 1:]
            if default:
                param = ParameterNumber(name, descName, default=default)
            else:
                param = ParameterNumber(name, descName)
        elif token.lower().strip().startswith('field'):
            if token.lower().strip().startswith('field number'):
                field = token.strip()[len('field number') + 1:]
                datatype = ParameterTableField.DATA_TYPE_NUMBER
            elif token.lower().strip().startswith('field string'):
                field = token.strip()[len('field string') + 1:]
                datatype = ParameterTableField.DATA_TYPE_STRING
            else:
                field = token.strip()[len('field') + 1:]
                datatype = ParameterTableField.DATA_TYPE_ANY
            found = False
            for p in self.parameters:
                if p.name == field:
                    found = True
                    break
            if found:
                param = ParameterTableField(
                    name=name,
                    description=descName,
                    parent=field,
                    datatype=datatype
                )
        elif token.lower().strip().startswith('multiple field'):
            if token.lower().strip().startswith('multiple field number'):
                field = token.strip()[len('multiple field number') + 1:]
                datatype = ParameterTableMultipleField.DATA_TYPE_NUMBER
            elif token.lower().strip().startswith('multiple field string'):
                field = token.strip()[len('multiple field string') + 1:]
                datatype = ParameterTableMultipleField.DATA_TYPE_STRING
            else:
                field = token.strip()[len('multiple field') + 1:]
                datatype = ParameterTableMultipleField.DATA_TYPE_ANY
            found = False
            for p in self.parameters:
                if p.name == field:
                    found = True
                    break
            if found:
                param = ParameterTableMultipleField(
                    name=name,
                    description=descName,
                    parent=field,
                    datatype=datatype
                )
        elif token.lower().strip().startswith('string'):
            default = token.strip()[len('string') + 1:]
            if default:
                param = ParameterString(name, descName, default)
            else:
                param = ParameterString(name, descName)
        elif token.lower().strip().startswith('longstring'):
            default = token.strip()[len('longstring') + 1:]
            if default:
                param = ParameterString(name, descName, default, multiline=True)
            else:
                param = ParameterString(name, descName, multiline=True)
        elif token.lower().strip().startswith('crs'):
            default = token.strip()[len('crs') + 1:]
            if default:
                param = ParameterCrs(name, descName, default)
            else:
                param = ParameterCrs(name, descName)

        return param
Exemplo n.º 6
0
    def processInputParameterToken(self, token, name):
        param = None

        descName = self.createDescriptiveName(name)

        if token.lower().strip() == 'raster':
            param = ParameterRaster(name, descName, False)
        elif token.lower().strip() == 'vector':
            param = ParameterVector(name, descName,
                                    [ParameterVector.VECTOR_TYPE_ANY])
        elif token.lower().strip() == 'vector point':
            param = ParameterVector(name, descName,
                                    [ParameterVector.VECTOR_TYPE_POINT])
        elif token.lower().strip() == 'vector line':
            param = ParameterVector(name, descName,
                                    [ParameterVector.VECTOR_TYPE_LINE])
        elif token.lower().strip() == 'vector polygon':
            param = ParameterVector(name, descName,
                                    [ParameterVector.VECTOR_TYPE_POLYGON])
        elif token.lower().strip() == 'table':
            param = ParameterTable(name, descName, False)
        elif token.lower().strip() == 'multiple raster':
            param = ParameterMultipleInput(name, descName,
                                           ParameterMultipleInput.TYPE_RASTER)
            param.optional = False
        elif token.lower().strip() == 'multiple vector':
            param = ParameterMultipleInput(
                name, descName, ParameterMultipleInput.TYPE_VECTOR_ANY)
            param.optional = False
        elif token.lower().strip().startswith('selectionfromfile'):
            options = token.strip()[len('selectionfromfile '):].split(';')
            param = ParameterSelection(name, descName, options, isSource=True)
        elif token.lower().strip().startswith('selection'):
            options = token.strip()[len('selection '):].split(';')
            param = ParameterSelection(name, descName, options)
        elif token.lower().strip().startswith('boolean'):
            default = token.strip()[len('boolean') + 1:]
            if default:
                param = ParameterBoolean(name, descName, default)
            else:
                param = ParameterBoolean(name, descName)
        elif token.lower().strip() == 'extent':
            param = ParameterExtent(name, descName)
        elif token.lower().strip() == 'point':
            param = ParameterPoint(name, descName)
        elif token.lower().strip() == 'file':
            param = ParameterFile(name, descName, False)
        elif token.lower().strip() == 'folder':
            param = ParameterFile(name, descName, True)
        elif token.lower().strip().startswith('number'):
            default = token.strip()[len('number') + 1:]
            if default:
                param = ParameterNumber(name, descName, default=default)
            else:
                param = ParameterNumber(name, descName)
        elif token.lower().strip().startswith('field'):
            field = token.strip()[len('field') + 1:]
            found = False
            for p in self.parameters:
                if p.name == field:
                    found = True
                    break
            if found:
                param = ParameterTableField(name, descName, field)
        elif token.lower().strip().startswith('string'):
            default = token.strip()[len('string') + 1:]
            if default:
                param = ParameterString(name, descName, default)
            else:
                param = ParameterString(name, descName)
        elif token.lower().strip().startswith('longstring'):
            default = token.strip()[len('longstring') + 1:]
            if default:
                param = ParameterString(name,
                                        descName,
                                        default,
                                        multiline=True)
            else:
                param = ParameterString(name, descName, multiline=True)
        elif token.lower().strip().startswith('crs'):
            default = token.strip()[len('crs') + 1:]
            if default:
                param = ParameterCrs(name, descName, default)
            else:
                param = ParameterCrs(name, descName)

        return param
Exemplo n.º 7
0
    def processParameterLine(self, line):
        param = None
        out = None
        line = line.replace('#', '')

        # If the line is in the format of the text description files for
        # normal algorithms, then process it using parameter and output
        # factories
        if '|' in line:
            self.processDescriptionParameterLine(line)
            return
        if line == "nomodeler":
            self.showInModeler = False
            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 = tokens[0]
            return
        if tokens[1].lower().strip() == 'raster':
            param = ParameterRaster(tokens[0], desc, False)
        elif tokens[1].lower().strip() == 'vector':
            param = ParameterVector(tokens[0], desc,
                                    [ParameterVector.VECTOR_TYPE_ANY])
        elif tokens[1].lower().strip() == 'vector point':
            param = ParameterVector(tokens[0], desc,
                                    [ParameterVector.VECTOR_TYPE_POINT])
        elif tokens[1].lower().strip() == 'vector line':
            param = ParameterVector(tokens[0], desc,
                                    [ParameterVector.VECTOR_TYPE_LINE])
        elif tokens[1].lower().strip() == 'vector polygon':
            param = ParameterVector(tokens[0], desc,
                                    [ParameterVector.VECTOR_TYPE_POLYGON])
        elif tokens[1].lower().strip() == 'table':
            param = ParameterTable(tokens[0], desc, False)
        elif tokens[1].lower().strip() == 'multiple raster':
            param = ParameterMultipleInput(tokens[0], desc,
                                           ParameterMultipleInput.TYPE_RASTER)
            param.optional = False
        elif tokens[1].lower().strip() == 'multiple vector':
            param = ParameterMultipleInput(
                tokens[0], desc, ParameterMultipleInput.TYPE_VECTOR_ANY)
            param.optional = False
        elif tokens[1].lower().strip().startswith('selection'):
            options = tokens[1].strip()[len('selection '):].split(';')
            param = ParameterSelection(tokens[0], desc, options)
        elif tokens[1].lower().strip().startswith('boolean'):
            default = tokens[1].strip()[len('boolean') + 1:]
            param = ParameterBoolean(tokens[0], desc, default)
        elif tokens[1].lower().strip() == 'extent':
            param = ParameterExtent(tokens[0], desc)
        elif tokens[1].lower().strip() == 'file':
            param = ParameterFile(tokens[0], desc, False)
        elif tokens[1].lower().strip() == 'folder':
            param = ParameterFile(tokens[0], desc, True)
        elif tokens[1].lower().strip().startswith('number'):
            default = tokens[1].strip()[len('number') + 1:]
            param = ParameterNumber(tokens[0], desc, default=default)
        elif tokens[1].lower().strip().startswith('field'):
            field = tokens[1].strip()[len('field') + 1:]
            found = False
            for p in self.parameters:
                if p.name == field:
                    found = True
                    break
            if found:
                param = ParameterTableField(tokens[0], desc, field)
        elif tokens[1].lower().strip().startswith('string'):
            default = tokens[1].strip()[len('string') + 1:]
            param = ParameterString(tokens[0], desc, default)
        elif tokens[1].lower().strip().startswith('longstring'):
            default = tokens[1].strip()[len('longstring') + 1:]
            param = ParameterString(tokens[0], desc, default, multiline=True)
        elif tokens[1].lower().strip().startswith('crs'):
            default = tokens[1].strip()[len('crs') + 1:]
            if not default:
                default = 'EPSG:4326'
            param = ParameterCrs(tokens[0], desc, default)
        elif tokens[1].lower().strip().startswith('output raster'):
            out = OutputRaster()
        elif tokens[1].lower().strip().startswith('output vector'):
            out = OutputVector()
        elif tokens[1].lower().strip().startswith('output table'):
            out = OutputTable()
        elif tokens[1].lower().strip().startswith('output html'):
            out = OutputHTML()
        elif tokens[1].lower().strip().startswith('output file'):
            out = OutputFile()
            subtokens = tokens[1].split(' ')
            if len(subtokens) > 2:
                out.ext = subtokens[2]
        elif tokens[1].lower().strip().startswith('output directory'):
            out = OutputDirectory()
        elif tokens[1].lower().strip().startswith('output number'):
            out = OutputNumber()
        elif tokens[1].lower().strip().startswith('output string'):
            out = OutputString()

        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 %d', 'ScriptAlgorithm') %
                (self.descriptionFile or '', line))
Exemplo n.º 8
0
    def processParameterLine(self, line):
        param = None
        out = None
        line = line.replace("#", "")

        # If the line is in the format of the text description files for
        # normal algorithms, then process it using parameter and output
        # factories
        if "|" in line:
            self.processDescriptionParameterLine(line)
            return
        if line == "nomodeler":
            self.showInModeler = False
            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 = tokens[0]
            return
        if tokens[1].lower().strip() == "raster":
            param = ParameterRaster(tokens[0], desc, False)
        elif tokens[1].lower().strip() == "vector":
            param = ParameterVector(tokens[0], desc, [ParameterVector.VECTOR_TYPE_ANY])
        elif tokens[1].lower().strip() == "vector point":
            param = ParameterVector(tokens[0], desc, [ParameterVector.VECTOR_TYPE_POINT])
        elif tokens[1].lower().strip() == "vector line":
            param = ParameterVector(tokens[0], desc, [ParameterVector.VECTOR_TYPE_LINE])
        elif tokens[1].lower().strip() == "vector polygon":
            param = ParameterVector(tokens[0], desc, [ParameterVector.VECTOR_TYPE_POLYGON])
        elif tokens[1].lower().strip() == "table":
            param = ParameterTable(tokens[0], desc, False)
        elif tokens[1].lower().strip() == "multiple raster":
            param = ParameterMultipleInput(tokens[0], desc, ParameterMultipleInput.TYPE_RASTER)
            param.optional = False
        elif tokens[1].lower().strip() == "multiple vector":
            param = ParameterMultipleInput(tokens[0], desc, ParameterMultipleInput.TYPE_VECTOR_ANY)
            param.optional = False
        elif tokens[1].lower().strip().startswith("selection"):
            options = tokens[1].strip()[len("selection ") :].split(";")
            param = ParameterSelection(tokens[0], desc, options)
        elif tokens[1].lower().strip().startswith("boolean"):
            default = tokens[1].strip()[len("boolean") + 1 :]
            param = ParameterBoolean(tokens[0], desc, default)
        elif tokens[1].lower().strip() == "extent":
            param = ParameterExtent(tokens[0], desc)
        elif tokens[1].lower().strip() == "file":
            param = ParameterFile(tokens[0], desc, False)
        elif tokens[1].lower().strip() == "folder":
            param = ParameterFile(tokens[0], desc, True)
        elif tokens[1].lower().strip().startswith("number"):
            default = tokens[1].strip()[len("number") + 1 :]
            param = ParameterNumber(tokens[0], desc, default=default)
        elif tokens[1].lower().strip().startswith("field"):
            field = tokens[1].strip()[len("field") + 1 :]
            found = False
            for p in self.parameters:
                if p.name == field:
                    found = True
                    break
            if found:
                param = ParameterTableField(tokens[0], desc, field)
        elif tokens[1].lower().strip().startswith("string"):
            default = tokens[1].strip()[len("string") + 1 :]
            param = ParameterString(tokens[0], desc, default)
        elif tokens[1].lower().strip().startswith("longstring"):
            default = tokens[1].strip()[len("longstring") + 1 :]
            param = ParameterString(tokens[0], desc, default, multiline=True)
        elif tokens[1].lower().strip().startswith("crs"):
            default = tokens[1].strip()[len("crs") + 1 :]
            if not default:
                default = "EPSG:4326"
            param = ParameterCrs(tokens[0], desc, default)
        elif tokens[1].lower().strip().startswith("output raster"):
            out = OutputRaster()
        elif tokens[1].lower().strip().startswith("output vector"):
            out = OutputVector()
        elif tokens[1].lower().strip().startswith("output table"):
            out = OutputTable()
        elif tokens[1].lower().strip().startswith("output html"):
            out = OutputHTML()
        elif tokens[1].lower().strip().startswith("output file"):
            out = OutputFile()
            subtokens = tokens[1].split(" ")
            if len(subtokens) > 2:
                out.ext = subtokens[2]
        elif tokens[1].lower().strip().startswith("output directory"):
            out = OutputDirectory()
        elif tokens[1].lower().strip().startswith("output number"):
            out = OutputNumber()
        elif tokens[1].lower().strip().startswith("output string"):
            out = OutputString()

        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 %d", "ScriptAlgorithm")
                % (self.descriptionFile or "", line)
            )
Exemplo n.º 9
0
    def processInputParameterToken(self, token, name):
        param = None
        optional = False
        isAdvanced = False

        desc = self.createDescriptiveName(name)

        tokens = token.lower().strip().split(' ')
        if "optional" in tokens[0]:
            optional = True
        if "advanced" in tokens[0]:
            isAdvanced = True
        if optional or isAdvanced:
            token = (' ').join(tokens[1:])

        if token.lower().strip().startswith('raster'):
            param = ParameterRaster(name, desc, False)
        elif token.lower().strip() == 'vector':
            param = ParameterVector(name, desc,
                                    [ParameterVector.VECTOR_TYPE_ANY])
        elif token.lower().strip() == 'vector point':
            param = ParameterVector(name, desc,
                                    [ParameterVector.VECTOR_TYPE_POINT])
        elif token.lower().strip() == 'vector line':
            param = ParameterVector(name, desc,
                                    [ParameterVector.VECTOR_TYPE_LINE])
        elif token.lower().strip() == 'vector polygon':
            param = ParameterVector(name, desc,
                                    [ParameterVector.VECTOR_TYPE_POLYGON])
        elif token.lower().strip() == 'table':
            param = ParameterTable(name, desc, False)
        elif token.lower().strip().startswith('multiple raster'):
            param = ParameterMultipleInput(name, desc,
                                           ParameterMultipleInput.TYPE_RASTER)
            param.optional = False
        elif token.lower().strip() == 'multiple vector':
            param = ParameterMultipleInput(name, desc,
                                           ParameterMultipleInput.TYPE_VECTOR_ANY)
            param.optional = False
        elif token.lower().strip().startswith('selection'):
            options = token.strip()[len('selection'):].split(';')
            param = ParameterSelection(name, desc, options)
        elif token.lower().strip().startswith('boolean'):
            default = token.strip()[len('boolean') + 1:]
            if default:
                param = ParameterBoolean(name, desc, default)
            else:
                param = ParameterBoolean(name, desc)
        elif token.lower().strip().startswith('number'):
            default = token.strip()[len('number') + 1:]
            if default:
                param = ParameterNumber(name, desc, default=default)
            else:
                param = ParameterNumber(name, desc)
        elif token.lower().strip().startswith('field'):
            field = token.strip()[len('field') + 1:]
            found = False
            for p in self.parameters:
                if p.name == field:
                    found = True
                    break
            if found:
                param = ParameterTableField(name, desc, field)
        elif token.lower().strip().startswith('multiple field'):
            field = token.strip()[len('multiple field') + 1:]
            found = False
            for p in self.parameters:
                if p.name == field:
                    found = True
                    break
            if found:
                param = ParameterTableMultipleField(name, desc, field)
        elif token.lower().strip() == 'extent':
            param = ParameterExtent(name, desc)
        elif token.lower().strip() == 'point':
            param = ParameterPoint(name, desc)
        elif token.lower().strip().startswith('file'):
            param = ParameterFile(name, desc, False)
            ext = token.strip()[len('file') + 1:]
            if ext:
                param.ext = ext
        elif token.lower().strip().startswith('folder'):
            param = ParameterFile(name, desc, True)
        elif token.lower().strip().startswith('string'):
            default = token.strip()[len('string') + 1:]
            if default:
                param = ParameterString(name, desc, default)
            else:
                param = ParameterString(name, desc)
        elif token.lower().strip().startswith('longstring'):
            default = token.strip()[len('longstring') + 1:]
            if default:
                param = ParameterString(name, desc, default, multiline=True)
            else:
                param = ParameterString(name, desc, multiline=True)
        elif token.lower().strip().startswith('crs'):
            default = token.strip()[len('crs') + 1:]
            if default:
                param = ParameterCrs(name, desc, default)
            else:
                param = ParameterCrs(name, desc)

        if param is not None:
            param.optional = optional
            param.isAdvanced = isAdvanced

        return param