Ejemplo n.º 1
0
    def testScriptCode(self):
        parent_name = "test_parent_layer"
        test_data = points()
        test_layer = QgsVectorLayer(test_data, parent_name, "ogr")
        parameter = ParameterTableField("myName", "myDesc", parent_name)
        code = parameter.getAsScriptCode()
        result = getParameterFromString(code)
        self.assertIsInstance(result, ParameterTableField)

        parameter.optional = True
        code = parameter.getAsScriptCode()
        result = getParameterFromString(code)
        self.assertIsInstance(result, ParameterTableField)
        self.assertTrue(result.optional)
Ejemplo n.º 2
0
    def defineCharacteristics(self):
        self.name, self.i18n_name = self.trAlgorithm('Heatmap (Kernel Density Estimation)')
        self.group, self.i18n_group = self.trAlgorithm('Interpolation')
        self.tags = self.tr('heatmap,kde,hotspot')

        self.addParameter(ParameterVector(self.INPUT_LAYER,
                                          self.tr('Point layer'), [dataobjects.TYPE_VECTOR_POINT]))
        self.addParameter(ParameterNumber(self.RADIUS,
                                          self.tr('Radius (layer units)'),
                                          0.0, 9999999999, 100.0))

        radius_field_param = ParameterTableField(self.RADIUS_FIELD,
                                                 self.tr('Radius from field'), self.INPUT_LAYER, optional=True, datatype=ParameterTableField.DATA_TYPE_NUMBER)
        radius_field_param.isAdvanced = True
        self.addParameter(radius_field_param)

        class ParameterHeatmapPixelSize(ParameterNumber):

            def __init__(self, name='', description='', parent_layer=None, radius_param=None, radius_field_param=None, minValue=None, maxValue=None,
                         default=None, optional=False, metadata={}):
                ParameterNumber.__init__(self, name, description, minValue, maxValue, default, optional, metadata)
                self.parent_layer = parent_layer
                self.radius_param = radius_param
                self.radius_field_param = radius_field_param

        self.addParameter(ParameterHeatmapPixelSize(self.PIXEL_SIZE,
                                                    self.tr('Output raster size'), parent_layer=self.INPUT_LAYER, radius_param=self.RADIUS,
                                                    radius_field_param=self.RADIUS_FIELD,
                                                    minValue=0.0, maxValue=9999999999, default=0.1,
                                                    metadata={'widget_wrapper': HeatmapPixelSizeWidgetWrapper}))

        weight_field_param = ParameterTableField(self.WEIGHT_FIELD,
                                                 self.tr('Weight from field'), self.INPUT_LAYER, optional=True, datatype=ParameterTableField.DATA_TYPE_NUMBER)
        weight_field_param.isAdvanced = True
        self.addParameter(weight_field_param)
        kernel_shape_param = ParameterSelection(self.KERNEL,
                                                self.tr('Kernel shape'), self.KERNELS)
        kernel_shape_param.isAdvanced = True
        self.addParameter(kernel_shape_param)
        decay_ratio = ParameterNumber(self.DECAY,
                                      self.tr('Decay ratio (Triangular kernels only)'),
                                      -100.0, 100.0, 0.0)
        decay_ratio.isAdvanced = True
        self.addParameter(decay_ratio)
        output_scaling = ParameterSelection(self.OUTPUT_VALUE,
                                            self.tr('Output value scaling'), self.OUTPUT_VALUES)
        output_scaling.isAdvanced = True
        self.addParameter(output_scaling)
        self.addOutput(OutputRaster(self.OUTPUT_LAYER,
                                    self.tr('Heatmap')))
Ejemplo n.º 3
0
    def testScriptCode(self):
        parent_name = 'test_parent_layer'
        test_data = points()
        test_layer = QgsVectorLayer(test_data, parent_name, 'ogr')
        parameter = ParameterTableField(
            'myName', 'myDesc', parent_name)
        code = parameter.getAsScriptCode()
        result = getParameterFromString(code)
        self.assertTrue(isinstance(result, ParameterTableField))

        parameter.optional = True
        code = parameter.getAsScriptCode()
        result = getParameterFromString(code)
        self.assertTrue(isinstance(result, ParameterTableField))
        self.assertTrue(result.optional)
Ejemplo n.º 4
0
    def __init__(self):
        super().__init__()
        self.addParameter(ParameterVector(self.INPUT_LAYER,
                                          self.tr('Point layer'), [dataobjects.TYPE_VECTOR_POINT]))
        self.addParameter(ParameterNumber(self.RADIUS,
                                          self.tr('Radius (layer units)'),
                                          0.0, 9999999999, 100.0))

        radius_field_param = ParameterTableField(self.RADIUS_FIELD,
                                                 self.tr('Radius from field'), self.INPUT_LAYER, optional=True, datatype=ParameterTableField.DATA_TYPE_NUMBER)
        radius_field_param.setFlags(radius_field_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(radius_field_param)

        class ParameterHeatmapPixelSize(ParameterNumber):

            def __init__(self, name='', description='', parent_layer=None, radius_param=None, radius_field_param=None, minValue=None, maxValue=None,
                         default=None, optional=False, metadata={}):
                ParameterNumber.__init__(self, name, description, minValue, maxValue, default, optional, metadata)
                self.parent_layer = parent_layer
                self.radius_param = radius_param
                self.radius_field_param = radius_field_param

        self.addParameter(ParameterHeatmapPixelSize(self.PIXEL_SIZE,
                                                    self.tr('Output raster size'), parent_layer=self.INPUT_LAYER, radius_param=self.RADIUS,
                                                    radius_field_param=self.RADIUS_FIELD,
                                                    minValue=0.0, maxValue=9999999999, default=0.1,
                                                    metadata={'widget_wrapper': HeatmapPixelSizeWidgetWrapper}))

        weight_field_param = ParameterTableField(self.WEIGHT_FIELD,
                                                 self.tr('Weight from field'), self.INPUT_LAYER, optional=True, datatype=ParameterTableField.DATA_TYPE_NUMBER)
        weight_field_param.setFlags(weight_field_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(weight_field_param)
        kernel_shape_param = ParameterSelection(self.KERNEL,
                                                self.tr('Kernel shape'), self.KERNELS)
        kernel_shape_param.setFlags(kernel_shape_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(kernel_shape_param)
        decay_ratio = ParameterNumber(self.DECAY,
                                      self.tr('Decay ratio (Triangular kernels only)'),
                                      -100.0, 100.0, 0.0)
        decay_ratio.setFlags(decay_ratio.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(decay_ratio)
        output_scaling = ParameterSelection(self.OUTPUT_VALUE,
                                            self.tr('Output value scaling'), self.OUTPUT_VALUES)
        output_scaling.setFlags(output_scaling.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(output_scaling)
        self.addOutput(OutputRaster(self.OUTPUT_LAYER,
                                    self.tr('Heatmap')))
Ejemplo n.º 5
0
    def defineCharacteristics(self):
        self.DIRECTIONS = OrderedDict([
            (self.tr('Forward direction'), QgsVectorLayerDirector.DirectionForward),
            (self.tr('Backward direction'), QgsVectorLayerDirector.DirectionForward),
            (self.tr('Both directions'), QgsVectorLayerDirector.DirectionForward)])

        self.STRATEGIES = [self.tr('Shortest'),
                           self.tr('Fastest')
                           ]

        self.addParameter(ParameterVector(self.INPUT_VECTOR,
                                          self.tr('Vector layer representing network'),
                                          [dataobjects.TYPE_VECTOR_LINE]))
        self.addParameter(ParameterPoint(self.START_POINT,
                                         self.tr('Start point')))
        self.addParameter(ParameterPoint(self.END_POINT,
                                         self.tr('End point')))
        self.addParameter(ParameterSelection(self.STRATEGY,
                                             self.tr('Path type to calculate'),
                                             self.STRATEGIES,
                                             default=0))

        params = []
        params.append(ParameterTableField(self.DIRECTION_FIELD,
                                          self.tr('Direction field'),
                                          self.INPUT_VECTOR,
                                          optional=True))
        params.append(ParameterString(self.VALUE_FORWARD,
                                      self.tr('Value for forward direction'),
                                      '',
                                      optional=True))
        params.append(ParameterString(self.VALUE_BACKWARD,
                                      self.tr('Value for backward direction'),
                                      '',
                                      optional=True))
        params.append(ParameterString(self.VALUE_BOTH,
                                      self.tr('Value for both directions'),
                                      '',
                                      optional=True))
        params.append(ParameterSelection(self.DEFAULT_DIRECTION,
                                         self.tr('Default direction'),
                                         list(self.DIRECTIONS.keys()),
                                         default=2))
        params.append(ParameterTableField(self.SPEED_FIELD,
                                          self.tr('Speed field'),
                                          self.INPUT_VECTOR,
                                          optional=True))
        params.append(ParameterNumber(self.DEFAULT_SPEED,
                                      self.tr('Default speed (km/h)'),
                                      0.0, 99999999.999999, 5.0))
        params.append(ParameterNumber(self.TOLERANCE,
                                      self.tr('Topology tolerance'),
                                      0.0, 99999999.999999, 0.0))

        for p in params:
            p.isAdvanced = True
            self.addParameter(p)

        self.addOutput(OutputNumber(self.TRAVEL_COST,
                                    self.tr('Travel cost')))
        self.addOutput(OutputVector(self.OUTPUT_LAYER,
                                    self.tr('Shortest path'),
                                    datatype=[dataobjects.TYPE_VECTOR_LINE]))
Ejemplo n.º 6
0
    def defineCharacteristics(self):
        self.name, self.i18n_name = self.trAlgorithm(
            'Rasterize (vector to raster)')
        self.group, self.i18n_group = self.trAlgorithm('[GDAL] Conversion')
        self.addParameter(ParameterVector(self.INPUT, self.tr('Input layer')))
        self.addParameter(
            ParameterTableField(self.FIELD, self.tr('Attribute field'),
                                self.INPUT))
        self.addParameter(
            ParameterSelection(
                self.DIMENSIONS,
                self.
                tr('Set output raster size (ignored if above option is checked)'
                   ), [
                       'Output size in pixels',
                       'Output resolution in map units per pixel'
                   ], 1))
        self.addParameter(
            ParameterNumber(self.WIDTH, self.tr('Horizontal'), 0.0,
                            99999999.999999, 100.0))
        self.addParameter(
            ParameterNumber(self.HEIGHT, self.tr('Vertical'), 0.0,
                            99999999.999999, 100.0))
        self.addParameter(
            ParameterExtent(self.RAST_EXT, self.tr('Raster extent')))

        params = []
        params.append(
            ParameterSelection(self.RTYPE, self.tr('Raster type'), self.TYPE,
                               5))
        params.append(
            ParameterString(self.NO_DATA,
                            self.tr("Nodata value"),
                            '',
                            optional=True))
        params.append(
            ParameterSelection(self.COMPRESS,
                               self.tr('GeoTIFF options. Compression type:'),
                               self.COMPRESSTYPE, 4))
        params.append(
            ParameterNumber(self.JPEGCOMPRESSION,
                            self.tr('Set the JPEG compression level'), 1, 100,
                            75))
        params.append(
            ParameterNumber(self.ZLEVEL,
                            self.tr('Set the DEFLATE compression level'), 1, 9,
                            6))
        params.append(
            ParameterNumber(
                self.PREDICTOR,
                self.tr('Set the predictor for LZW or DEFLATE compression'), 1,
                3, 1))
        params.append(
            ParameterBoolean(
                self.TILED,
                self.tr(
                    'Create tiled output (only used for the GTiff format)'),
                False))
        params.append(
            ParameterSelection(
                self.BIGTIFF,
                self.
                tr('Control whether the created file is a BigTIFF or a classic TIFF'
                   ), self.BIGTIFFTYPE, 0))
        self.addParameter(
            ParameterBoolean(
                self.TFW,
                self.
                tr('Force the generation of an associated ESRI world file (.tfw)'
                   ), False))
        params.append(
            ParameterString(self.EXTRA,
                            self.tr('Additional creation parameters'),
                            '',
                            optional=True))

        for param in params:
            param.isAdvanced = True
            self.addParameter(param)

        self.addOutput(OutputRaster(self.OUTPUT, self.tr('Rasterized')))
Ejemplo n.º 7
0
 def initAlgorithm(self, config=None):
     self.DB_CONNECTIONS = self.dbConnectionNames()
     self.addParameter(
         ParameterSelection(self.DATABASE,
                            self.tr('Database (connection name)'),
                            self.DB_CONNECTIONS))
     self.addParameter(
         ParameterTable(self.INPUT_LAYER, self.tr('Input layer')))
     self.addParameter(
         ParameterString(self.SHAPE_ENCODING,
                         self.tr('Shape encoding'),
                         "",
                         optional=True))
     self.addParameter(
         ParameterString(self.SCHEMA,
                         self.tr('Schema name'),
                         'public',
                         optional=True))
     self.addParameter(
         ParameterString(
             self.TABLE,
             self.tr('Table name, leave blank to use input name'),
             '',
             optional=True))
     self.addParameter(
         ParameterString(self.PK,
                         self.tr('Primary key'),
                         'id',
                         optional=True))
     self.addParameter(
         ParameterTableField(
             self.PRIMARY_KEY,
             self.
             tr('Primary key (existing field, used if the above option is left empty)'
                ),
             self.INPUT_LAYER,
             optional=True))
     self.addParameter(
         ParameterString(
             self.WHERE,
             self.
             tr('Select features using a SQL "WHERE" statement (Ex: column=\'value\')'
                ),
             '',
             optional=True))
     self.addParameter(
         ParameterString(
             self.GT,
             self.tr('Group N features per transaction (Default: 20000)'),
             '',
             optional=True))
     self.addParameter(
         ParameterBoolean(self.OVERWRITE,
                          self.tr('Overwrite existing table'), True))
     self.addParameter(
         ParameterBoolean(self.APPEND, self.tr('Append to existing table'),
                          False))
     self.addParameter(
         ParameterBoolean(
             self.ADDFIELDS,
             self.tr('Append and add new fields to existing table'), False))
     self.addParameter(
         ParameterBoolean(self.LAUNDER,
                          self.tr('Do not launder columns/table names'),
                          False))
     self.addParameter(
         ParameterBoolean(
             self.SKIPFAILURES,
             self.tr(
                 'Continue after a failure, skipping the failed record'),
             False))
     self.addParameter(
         ParameterBoolean(
             self.PRECISION,
             self.tr('Keep width and precision of input attributes'), True))
     self.addParameter(
         ParameterString(self.OPTIONS,
                         self.tr('Additional creation options'),
                         '',
                         optional=True))
Ejemplo n.º 8
0
 def okPressed(self):
     description = unicode(self.nameTextBox.text())
     if description.strip() == '':
         QMessageBox.warning(self, self.tr('Unable to define parameter'),
                             self.tr('Invalid parameter name'))
         return
     if self.param is None:
         validChars = \
             'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
         safeName = ''.join(c for c in description if c in validChars)
         name = self.paramType.upper().replace(' ', '') + '_' \
             + safeName.upper()
     else:
         name = self.param.name
     if self.paramType \
             == ModelerParameterDefinitionDialog.PARAMETER_BOOLEAN \
             or isinstance(self.param, ParameterBoolean):
         self.param = ParameterBoolean(name, description,
                                       self.state.isChecked())
     elif self.paramType \
             == ModelerParameterDefinitionDialog.PARAMETER_TABLE_FIELD \
             or isinstance(self.param, ParameterTableField):
         if self.parentCombo.currentIndex() < 0:
             QMessageBox.warning(
                 self, self.tr('Unable to define parameter'),
                 self.tr('Wrong or missing parameter values'))
             return
         parent = self.parentCombo.itemData(self.parentCombo.currentIndex())
         self.param = ParameterTableField(name, description, parent)
     elif self.paramType \
             == ModelerParameterDefinitionDialog.PARAMETER_RASTER \
             or isinstance(self.param, ParameterRaster):
         self.param = ParameterRaster(name, description,
                                      self.yesNoCombo.currentIndex() == 1)
     elif self.paramType \
             == ModelerParameterDefinitionDialog.PARAMETER_TABLE \
             or isinstance(self.param, ParameterTable):
         self.param = ParameterTable(name, description,
                                     self.yesNoCombo.currentIndex() == 1)
     elif self.paramType \
             == ModelerParameterDefinitionDialog.PARAMETER_VECTOR \
             or isinstance(self.param, ParameterVector):
         self.param = ParameterVector(
             name, description, [self.shapetypeCombo.currentIndex() - 1],
             self.yesNoCombo.currentIndex() == 1)
     elif self.paramType \
             == ModelerParameterDefinitionDialog.PARAMETER_MULTIPLE \
             or isinstance(self.param, ParameterMultipleInput):
         self.param = ParameterMultipleInput(
             name, description,
             self.datatypeCombo.currentIndex() - 1,
             self.yesNoCombo.currentIndex() == 1)
     elif self.paramType \
             == ModelerParameterDefinitionDialog.PARAMETER_NUMBER \
             or isinstance(self.param, ParameterNumber):
         try:
             vmin = str(self.minTextBox.text()).strip()
             if vmin == '':
                 vmin = None
             else:
                 vmin = float(vmin)
             vmax = str(self.maxTextBox.text()).strip()
             if vmax == '':
                 vmax = None
             else:
                 vmax = float(vmax)
             self.param = ParameterNumber(name, description, vmin, vmax,
                                          str(self.defaultTextBox.text()))
         except:
             QMessageBox.warning(
                 self, self.tr('Unable to define parameter'),
                 self.tr('Wrong or missing parameter values'))
             return
     elif self.paramType \
             == ModelerParameterDefinitionDialog.PARAMETER_STRING \
             or isinstance(self.param, ParameterString):
         self.param = ParameterString(name, description,
                                      unicode(self.defaultTextBox.text()))
     elif self.paramType \
             == ModelerParameterDefinitionDialog.PARAMETER_EXTENT \
             or isinstance(self.param, ParameterExtent):
         self.param = ParameterExtent(name, description)
     elif self.paramType == \
             ModelerParameterDefinitionDialog.PARAMETER_FILE \
             or isinstance(self.param, ParameterFile):
         isFolder = self.fileFolderCombo.currentIndex() == 1
         self.param = ParameterFile(name, description, isFolder=isFolder)
     self.close()
Ejemplo n.º 9
0
 def defineCharacteristics(self):
     self.addParameter(ParameterVector(self.INPUT,
                                       self.tr('Input layer')))
     self.addParameter(ParameterTableField(self.FIELD,
                                           self.tr('Class field'), self.INPUT))
     self.addOutput(OutputVector(self.OUTPUT, self.tr('Layer with index field')))
Ejemplo n.º 10
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('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))
Ejemplo n.º 11
0
 def initAlgorithm(self, config=None):
     self.addParameter(ParameterVector(self.INPUT, self.tr('Input layer')))
     self.addParameter(ParameterTableField(self.FIELD,
                                           self.tr('Attribute field'), self.INPUT))
     self.addParameter(ParameterRaster(self.INPUT_RASTER,
                                       self.tr('Existing raster layer'), False))
Ejemplo n.º 12
0
    def defineCharacteristics(self):
        self.DIRECTIONS = OrderedDict([
            (self.tr('Forward direction'),
             QgsVectorLayerDirector.DirectionForward),
            (self.tr('Backward direction'),
             QgsVectorLayerDirector.DirectionForward),
            (self.tr('Both directions'),
             QgsVectorLayerDirector.DirectionForward)
        ])

        self.STRATEGIES = [self.tr('Shortest'), self.tr('Fastest')]

        self.name, self.i18n_name = self.trAlgorithm(
            'Service area (from layer)')
        self.group, self.i18n_group = self.trAlgorithm('Network analysis')

        self.addParameter(
            ParameterVector(self.INPUT_VECTOR,
                            self.tr('Vector layer representing network'),
                            [dataobjects.TYPE_VECTOR_LINE]))
        self.addParameter(
            ParameterVector(self.START_POINTS,
                            self.tr('Vector layer with start points'),
                            [dataobjects.TYPE_VECTOR_POINT]))
        self.addParameter(
            ParameterSelection(self.STRATEGY,
                               self.tr('Path type to calculate'),
                               self.STRATEGIES,
                               default=0))
        self.addParameter(
            ParameterNumber(
                self.TRAVEL_COST,
                self.tr(
                    'Travel cost (distance for "Shortest", time for "Fastest")'
                ), 0.0, 99999999.999999, 0.0))

        params = []
        params.append(
            ParameterTableField(self.DIRECTION_FIELD,
                                self.tr('Direction field'),
                                self.INPUT_VECTOR,
                                optional=True))
        params.append(
            ParameterString(self.VALUE_FORWARD,
                            self.tr('Value for forward direction'),
                            '',
                            optional=True))
        params.append(
            ParameterString(self.VALUE_BACKWARD,
                            self.tr('Value for backward direction'),
                            '',
                            optional=True))
        params.append(
            ParameterString(self.VALUE_BOTH,
                            self.tr('Value for both directions'),
                            '',
                            optional=True))
        params.append(
            ParameterSelection(self.DEFAULT_DIRECTION,
                               self.tr('Default direction'),
                               list(self.DIRECTIONS.keys()),
                               default=2))
        params.append(
            ParameterTableField(self.SPEED_FIELD,
                                self.tr('Speed field'),
                                self.INPUT_VECTOR,
                                optional=True))
        params.append(
            ParameterNumber(self.DEFAULT_SPEED,
                            self.tr('Default speed (km/h)'), 0.0,
                            99999999.999999, 5.0))
        params.append(
            ParameterNumber(self.TOLERANCE, self.tr('Topology tolerance'), 0.0,
                            99999999.999999, 0.0))

        for p in params:
            p.isAdvanced = True
            self.addParameter(p)

        self.addOutput(
            OutputVector(self.OUTPUT_POINTS,
                         self.tr('Service area (boundary nodes)'),
                         datatype=[dataobjects.TYPE_VECTOR_POINT]))
        self.addOutput(
            OutputVector(self.OUTPUT_POLYGON,
                         self.tr('Service area (convex hull)'),
                         datatype=[dataobjects.TYPE_VECTOR_POLYGON]))
Ejemplo n.º 13
0
 def defineCharacteristics(self):
     self.addParameter(
         ParameterVector(self.INPUT, self.tr('Layer to import')))
     self.addParameter(
         ParameterString(
             self.DATABASE,
             self.tr('Database (connection name)'),
             metadata={
                 'widget_wrapper': {
                     'class':
                     'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'
                 }
             }))
     self.addParameter(
         ParameterString(
             self.SCHEMA,
             self.tr('Schema (schema name)'),
             'public',
             optional=True,
             metadata={
                 'widget_wrapper': {
                     'class':
                     'processing.gui.wrappers_postgis.SchemaWidgetWrapper',
                     'connection_param': self.DATABASE
                 }
             }))
     self.addParameter(
         ParameterString(
             self.TABLENAME,
             self.tr('Table to import to (leave blank to use layer name)'),
             '',
             optional=True,
             metadata={
                 'widget_wrapper': {
                     'class':
                     'processing.gui.wrappers_postgis.TableWidgetWrapper',
                     'schema_param': self.SCHEMA
                 }
             }))
     self.addParameter(
         ParameterTableField(self.PRIMARY_KEY,
                             self.tr('Primary key field'),
                             self.INPUT,
                             optional=True))
     self.addParameter(
         ParameterString(self.GEOMETRY_COLUMN, self.tr('Geometry column'),
                         'geom'))
     self.addParameter(
         ParameterString(self.ENCODING,
                         self.tr('Encoding'),
                         'UTF-8',
                         optional=True))
     self.addParameter(
         ParameterBoolean(self.OVERWRITE, self.tr('Overwrite'), True))
     self.addParameter(
         ParameterBoolean(self.CREATEINDEX, self.tr('Create spatial index'),
                          True))
     self.addParameter(
         ParameterBoolean(self.LOWERCASE_NAMES,
                          self.tr('Convert field names to lowercase'),
                          True))
     self.addParameter(
         ParameterBoolean(
             self.DROP_STRING_LENGTH,
             self.tr('Drop length constraints on character fields'), False))
     self.addParameter(
         ParameterBoolean(
             self.FORCE_SINGLEPART,
             self.tr('Create single-part geometries instead of multi-part'),
             False))
Ejemplo n.º 14
0
 def __init__(self):
     super().__init__()
     self.addParameter(
         ParameterVector(self.INPUT_LAYER, self.tr('Input layer')))
     self.addParameter(
         ParameterString(self.SHAPE_ENCODING,
                         self.tr('Shape encoding'),
                         "",
                         optional=True))
     self.addParameter(
         ParameterSelection(self.GTYPE, self.tr('Output geometry type'),
                            self.GEOMTYPE, 0))
     self.addParameter(
         ParameterCrs(self.A_SRS,
                      self.tr('Assign an output CRS'),
                      '',
                      optional=False))
     self.addParameter(
         ParameterCrs(self.T_SRS,
                      self.tr('Reproject to this CRS on output '),
                      '',
                      optional=True))
     self.addParameter(
         ParameterCrs(self.S_SRS,
                      self.tr('Override source CRS'),
                      '',
                      optional=True))
     self.addParameter(
         ParameterString(self.HOST,
                         self.tr('Host'),
                         'localhost',
                         optional=True))
     self.addParameter(
         ParameterString(self.PORT, self.tr('Port'), '5432', optional=True))
     self.addParameter(
         ParameterString(self.USER, self.tr('Username'), '', optional=True))
     self.addParameter(
         ParameterString(self.DBNAME,
                         self.tr('Database name'),
                         '',
                         optional=True))
     self.addParameter(
         ParameterString(self.PASSWORD,
                         self.tr('Password'),
                         '',
                         optional=True))
     self.addParameter(
         ParameterString(self.SCHEMA,
                         self.tr('Schema name'),
                         'public',
                         optional=True))
     self.addParameter(
         ParameterString(
             self.TABLE,
             self.tr('Table name, leave blank to use input name'),
             '',
             optional=True))
     self.addParameter(
         ParameterString(self.PK,
                         self.tr('Primary key (new field)'),
                         'id',
                         optional=True))
     self.addParameter(
         ParameterTableField(
             self.PRIMARY_KEY,
             self.
             tr('Primary key (existing field, used if the above option is left empty)'
                ),
             self.INPUT_LAYER,
             optional=True))
     self.addParameter(
         ParameterString(self.GEOCOLUMN,
                         self.tr('Geometry column name'),
                         'geom',
                         optional=True))
     self.addParameter(
         ParameterSelection(self.DIM, self.tr('Vector dimensions'),
                            self.DIMLIST, 0))
     self.addParameter(
         ParameterString(self.SIMPLIFY,
                         self.tr('Distance tolerance for simplification'),
                         '',
                         optional=True))
     self.addParameter(
         ParameterString(
             self.SEGMENTIZE,
             self.tr('Maximum distance between 2 nodes (densification)'),
             '',
             optional=True))
     self.addParameter(
         ParameterExtent(
             self.SPAT,
             self.tr(
                 'Select features by extent (defined in input layer CRS)')))
     self.addParameter(
         ParameterBoolean(
             self.CLIP,
             self.tr(
                 'Clip the input layer using the above (rectangle) extent'),
             False))
     self.addParameter(
         ParameterString(
             self.WHERE,
             self.
             tr('Select features using a SQL "WHERE" statement (Ex: column=\'value\')'
                ),
             '',
             optional=True))
     self.addParameter(
         ParameterString(
             self.GT,
             self.tr('Group N features per transaction (Default: 20000)'),
             '',
             optional=True))
     self.addParameter(
         ParameterBoolean(self.OVERWRITE,
                          self.tr('Overwrite existing table'), True))
     self.addParameter(
         ParameterBoolean(self.APPEND, self.tr('Append to existing table'),
                          False))
     self.addParameter(
         ParameterBoolean(
             self.ADDFIELDS,
             self.tr('Append and add new fields to existing table'), False))
     self.addParameter(
         ParameterBoolean(self.LAUNDER,
                          self.tr('Do not launder columns/table names'),
                          False))
     self.addParameter(
         ParameterBoolean(self.INDEX,
                          self.tr('Do not create spatial index'), False))
     self.addParameter(
         ParameterBoolean(
             self.SKIPFAILURES,
             self.tr(
                 'Continue after a failure, skipping the failed feature'),
             False))
     self.addParameter(
         ParameterBoolean(self.PROMOTETOMULTI,
                          self.tr('Promote to Multipart'), True))
     self.addParameter(
         ParameterBoolean(
             self.PRECISION,
             self.tr('Keep width and precision of input attributes'), True))
     self.addParameter(
         ParameterString(self.OPTIONS,
                         self.tr('Additional creation options'),
                         '',
                         optional=True))
Ejemplo n.º 15
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
Ejemplo n.º 16
0
        self.group = '[OGR] Geoprocessing'

        self.addParameter(ParameterVector(self.INPUT_LAYER,
            self.tr('Input layer'), [ParameterVector.VECTOR_TYPE_LINE], False))
        self.addParameter(ParameterSelection(self.OPERATION,
            self.tr('Operation'),self.OPERATIONLIST, 0))
        self.addParameter(ParameterString(self.GEOMETRY,
            self.tr('Geometry column name ("geometry" for Shapefiles, may be different for other formats)'),
            'geometry', optional=False))
        self.addParameter(ParameterString(self.RADIUS,
            self.tr('Buffer distance'), '1000', optional=False))
        self.addParameter(ParameterSelection(self.LEFTRIGHT,
            self.tr('Buffer side'),self.LEFTRIGHTLIST, 0))
        self.addParameter(ParameterBoolean(self.DISSOLVEALL,
            self.tr('Dissolve all results'), False))
        self.addParameter(ParameterTableField(self.FIELD,
            self.tr('Dissolve by attribute'), self.INPUT_LAYER, optional=True))
        self.addParameter(ParameterBoolean(self.MULTI,
            self.tr('Output as singlepart geometries (only used when dissolving by attribute)'), False))
        self.addParameter(ParameterString(self.OPTIONS,
            self.tr('Additional creation options (see ogr2ogr manual)'),
            '', optional=True))

        self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Output layer')))

    def processAlgorithm(self, progress):
=======
        self.name, self.i18n_name = self.trAlgorithm('Single sided buffers (and offset lines) for lines')
        self.group, self.i18n_group = self.trAlgorithm('[OGR] Geoprocessing')

        self.addParameter(ParameterVector(self.INPUT_LAYER,
                                          self.tr('Input layer'), [ParameterVector.VECTOR_TYPE_LINE], False))
Ejemplo n.º 17
0
    def processInputParameterToken(self, token, name):
        param = None

        desc = self.createDescriptiveName(name)

        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() == 'file':
            param = ParameterFile(name, desc, False)
        elif token.lower().strip() == '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() == 'crs':
            default = token.strip()[len('crs') + 1:]
            if default:
                param = ParameterCrs(name, desc, default)
            else:
                param = ParameterCrs(name, desc)

        return param
Ejemplo n.º 18
0
    def defineCharacteristics(self):
        self.addParameter(
            ParameterVector(self.INPUT_LAYER, self.tr('Point layer'),
                            [dataobjects.TYPE_VECTOR_POINT]))
        self.addParameter(
            ParameterNumber(self.RADIUS, self.tr('Radius (layer units)'), 0.0,
                            9999999999, 100.0))

        radius_field_param = ParameterTableField(
            self.RADIUS_FIELD,
            self.tr('Radius from field'),
            self.INPUT_LAYER,
            optional=True,
            datatype=ParameterTableField.DATA_TYPE_NUMBER)
        radius_field_param.isAdvanced = True
        self.addParameter(radius_field_param)

        class ParameterHeatmapPixelSize(ParameterNumber):
            def __init__(self,
                         name='',
                         description='',
                         parent_layer=None,
                         radius_param=None,
                         radius_field_param=None,
                         minValue=None,
                         maxValue=None,
                         default=None,
                         optional=False,
                         metadata={}):
                ParameterNumber.__init__(self, name, description, minValue,
                                         maxValue, default, optional, metadata)
                self.parent_layer = parent_layer
                self.radius_param = radius_param
                self.radius_field_param = radius_field_param

        self.addParameter(
            ParameterHeatmapPixelSize(
                self.PIXEL_SIZE,
                self.tr('Output raster size'),
                parent_layer=self.INPUT_LAYER,
                radius_param=self.RADIUS,
                radius_field_param=self.RADIUS_FIELD,
                minValue=0.0,
                maxValue=9999999999,
                default=0.1,
                metadata={'widget_wrapper': HeatmapPixelSizeWidgetWrapper}))

        weight_field_param = ParameterTableField(
            self.WEIGHT_FIELD,
            self.tr('Weight from field'),
            self.INPUT_LAYER,
            optional=True,
            datatype=ParameterTableField.DATA_TYPE_NUMBER)
        weight_field_param.isAdvanced = True
        self.addParameter(weight_field_param)
        kernel_shape_param = ParameterSelection(self.KERNEL,
                                                self.tr('Kernel shape'),
                                                self.KERNELS)
        kernel_shape_param.isAdvanced = True
        self.addParameter(kernel_shape_param)
        decay_ratio = ParameterNumber(
            self.DECAY, self.tr('Decay ratio (Triangular kernels only)'),
            -100.0, 100.0, 0.0)
        decay_ratio.isAdvanced = True
        self.addParameter(decay_ratio)
        output_scaling = ParameterSelection(self.OUTPUT_VALUE,
                                            self.tr('Output value scaling'),
                                            self.OUTPUT_VALUES)
        output_scaling.isAdvanced = True
        self.addParameter(output_scaling)
        self.addOutput(OutputRaster(self.OUTPUT_LAYER, self.tr('Heatmap')))
Ejemplo n.º 19
0
 def defineCharacteristics(self):
     self.name, self.i18n_name = self.trAlgorithm(
         'Import Vector into PostGIS database (available connections)')
     self.group, self.i18n_group = self.trAlgorithm('Vector miscellaneous')
     self.addParameter(
         ParameterString(
             self.DATABASE,
             self.tr('Database (connection name)'),
             metadata={
                 'widget_wrapper': {
                     'class':
                     'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'
                 }
             }))
     self.addParameter(
         ParameterVector(self.INPUT_LAYER, self.tr('Input layer')))
     self.addParameter(
         ParameterString(self.SHAPE_ENCODING,
                         self.tr('Shape encoding'),
                         "",
                         optional=True))
     self.addParameter(
         ParameterSelection(self.GTYPE, self.tr('Output geometry type'),
                            self.GEOMTYPE, 0))
     self.addParameter(
         ParameterCrs(self.A_SRS,
                      self.tr('Assign an output CRS'),
                      '',
                      optional=False))
     self.addParameter(
         ParameterCrs(self.T_SRS,
                      self.tr('Reproject to this CRS on output '),
                      '',
                      optional=True))
     self.addParameter(
         ParameterCrs(self.S_SRS,
                      self.tr('Override source CRS'),
                      '',
                      optional=True))
     self.addParameter(
         ParameterString(
             self.SCHEMA,
             self.tr('Schema name'),
             'public',
             optional=True,
             metadata={
                 'widget_wrapper': {
                     'class':
                     'processing.gui.wrappers_postgis.SchemaWidgetWrapper',
                     'connection_param': self.DATABASE
                 }
             }))
     self.addParameter(
         ParameterString(
             self.TABLE,
             self.tr('Table name, leave blank to use input name'),
             '',
             optional=True,
             metadata={
                 'widget_wrapper': {
                     'class':
                     'processing.gui.wrappers_postgis.TableWidgetWrapper',
                     'schema_param': self.SCHEMA
                 }
             }))
     self.addParameter(
         ParameterString(self.PK,
                         self.tr('Primary key (new field)'),
                         'id',
                         optional=True))
     self.addParameter(
         ParameterTableField(
             self.PRIMARY_KEY,
             self.
             tr('Primary key (existing field, used if the above option is left empty)'
                ),
             self.INPUT_LAYER,
             optional=True))
     self.addParameter(
         ParameterString(self.GEOCOLUMN,
                         self.tr('Geometry column name'),
                         'geom',
                         optional=True))
     self.addParameter(
         ParameterSelection(self.DIM, self.tr('Vector dimensions'),
                            self.DIMLIST, 0))
     self.addParameter(
         ParameterString(self.SIMPLIFY,
                         self.tr('Distance tolerance for simplification'),
                         '',
                         optional=True))
     self.addParameter(
         ParameterString(
             self.SEGMENTIZE,
             self.tr('Maximum distance between 2 nodes (densification)'),
             '',
             optional=True))
     self.addParameter(
         ParameterExtent(
             self.SPAT,
             self.tr(
                 'Select features by extent (defined in input layer CRS)')))
     self.addParameter(
         ParameterBoolean(
             self.CLIP,
             self.tr(
                 'Clip the input layer using the above (rectangle) extent'),
             False))
     self.addParameter(
         ParameterString(
             self.WHERE,
             self.
             tr('Select features using a SQL "WHERE" statement (Ex: column=\'value\')'
                ),
             '',
             optional=True))
     self.addParameter(
         ParameterString(
             self.GT,
             self.tr('Group N features per transaction (Default: 20000)'),
             '',
             optional=True))
     self.addParameter(
         ParameterBoolean(self.OVERWRITE,
                          self.tr('Overwrite existing table'), True))
     self.addParameter(
         ParameterBoolean(self.APPEND, self.tr('Append to existing table'),
                          False))
     self.addParameter(
         ParameterBoolean(
             self.ADDFIELDS,
             self.tr('Append and add new fields to existing table'), False))
     self.addParameter(
         ParameterBoolean(self.LAUNDER,
                          self.tr('Do not launder columns/table names'),
                          False))
     self.addParameter(
         ParameterBoolean(self.INDEX,
                          self.tr('Do not create spatial index'), False))
     self.addParameter(
         ParameterBoolean(
             self.SKIPFAILURES,
             self.tr(
                 'Continue after a failure, skipping the failed feature'),
             False))
     self.addParameter(
         ParameterBoolean(self.PROMOTETOMULTI,
                          self.tr('Promote to Multipart'), True))
     self.addParameter(
         ParameterBoolean(
             self.PRECISION,
             self.tr('Keep width and precision of input attributes'), True))
     self.addParameter(
         ParameterString(self.OPTIONS,
                         self.tr('Additional creation options'),
                         '',
                         optional=True))
Ejemplo n.º 20
0
    def defineCharacteristics(self):
        self.addParameter(ParameterVector(self.INPUT, self.tr('Input layer')))
        self.addParameter(ParameterTableField(self.FIELD,
                                              self.tr('Unique ID field'), self.INPUT))

        self.addOutput(OutputVector(self.OUTPUT, self.tr('Multipart')))
Ejemplo n.º 21
0
 def defineCharacteristics(self):
     self.addParameter(ParameterVector(self.INPUT,
                                       self.tr('Input layer')))
     self.addParameter(ParameterTableField(self.COLUMNS,
                                           self.tr('Fields to delete'), self.INPUT, multiple=True))
     self.addOutput(OutputVector(self.OUTPUT, self.tr('Output layer')))
Ejemplo n.º 22
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)))
 def okPressed(self):
     description = str(self.nameTextBox.text())
     if description.strip() == '':
         QMessageBox.warning(self, self.tr('Unable to define parameter'),
                             self.tr('Invalid parameter name'))
         return
     if self.param is None:
         validChars = \
             'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
         safeName = ''.join(c for c in description if c in validChars)
         name = safeName.lower()
         i = 2
         while name in self.alg.inputs:
             name = safeName.lower() + str(i)
     else:
         name = self.param.name()
     if (self.paramType
             == ModelerParameterDefinitionDialog.PARAMETER_BOOLEAN
             or isinstance(self.param, ParameterBoolean)):
         self.param = ParameterBoolean(name, description,
                                       self.state.isChecked())
     elif (self.paramType
           == ModelerParameterDefinitionDialog.PARAMETER_TABLE_FIELD
           or isinstance(self.param, ParameterTableField)):
         if self.parentCombo.currentIndex() < 0:
             QMessageBox.warning(
                 self, self.tr('Unable to define parameter'),
                 self.tr('Wrong or missing parameter values'))
             return
         parent = self.parentCombo.currentData()
         datatype = self.datatypeCombo.currentData()
         self.param = ParameterTableField(
             name,
             description,
             parent,
             datatype,
             multiple=self.multipleCheck.isChecked())
     elif (self.paramType
           == ModelerParameterDefinitionDialog.PARAMETER_RASTER
           or isinstance(self.param, ParameterRaster)):
         self.param = ParameterRaster(name, description)
     elif (self.paramType
           == ModelerParameterDefinitionDialog.PARAMETER_TABLE
           or isinstance(self.param, ParameterTable)):
         self.param = ParameterTable(name, description)
     elif (self.paramType
           == ModelerParameterDefinitionDialog.PARAMETER_VECTOR
           or isinstance(self.param, ParameterVector)):
         self.param = ParameterVector(
             name, description, [self.shapetypeCombo.currentIndex() - 1])
     elif (self.paramType
           == ModelerParameterDefinitionDialog.PARAMETER_MULTIPLE
           or isinstance(self.param, ParameterMultipleInput)):
         self.param = ParameterMultipleInput(
             name, description,
             self.datatypeCombo.currentIndex() - 1)
     elif (self.paramType
           == ModelerParameterDefinitionDialog.PARAMETER_NUMBER
           or isinstance(self.param, ParameterNumber)):
         try:
             vmin = self.minTextBox.text().strip()
             if vmin == '':
                 vmin = None
             else:
                 vmin = float(vmin)
             vmax = self.maxTextBox.text().strip()
             if vmax == '':
                 vmax = None
             else:
                 vmax = float(vmax)
             self.param = ParameterNumber(name, description, vmin, vmax,
                                          str(self.defaultTextBox.text()))
         except:
             QMessageBox.warning(
                 self, self.tr('Unable to define parameter'),
                 self.tr('Wrong or missing parameter values'))
             return
     elif (self.paramType
           == ModelerParameterDefinitionDialog.PARAMETER_EXPRESSION
           or isinstance(self.param, ParameterExpression)):
         parent = self.parentCombo.currentData()
         self.param = ParameterExpression(
             name,
             description,
             default=str(self.defaultEdit.expression()),
             parent_layer=parent)
     elif (self.paramType
           == ModelerParameterDefinitionDialog.PARAMETER_STRING
           or isinstance(self.param, ParameterString)):
         self.param = ParameterString(name, description,
                                      str(self.defaultTextBox.text()))
     elif (self.paramType
           == ModelerParameterDefinitionDialog.PARAMETER_EXTENT
           or isinstance(self.param, ParameterExtent)):
         self.param = ParameterExtent(name, description)
     elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_FILE
           or isinstance(self.param, ParameterFile)):
         isFolder = self.fileFolderCombo.currentIndex() == 1
         self.param = ParameterFile(name, description, isFolder=isFolder)
     elif (self.paramType
           == ModelerParameterDefinitionDialog.PARAMETER_POINT
           or isinstance(self.param, ParameterPoint)):
         self.param = ParameterPoint(name, description,
                                     str(self.defaultTextBox.text()))
     elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_CRS
           or isinstance(self.param, ParameterCrs)):
         self.param = ParameterCrs(name,
                                   description,
                                   default=self.selector.crs().authid())
     if not self.requiredCheck.isChecked():
         self.param.setFlags(
             self.param.flags()
             | QgsProcessingParameterDefinition.FlagOptional)
     self.close()
 def defineCharacteristics(self):
     self.name, self.i18n_name = self.trAlgorithm(
         'SLMS - Import Static Vector into PostGIS (OVERWRITE MODE)')
     self.group, self.i18n_group = self.trAlgorithm('[OGR] Miscellaneous')
     self.DB_CONNECTIONS = self.dbConnectionNames()
     self.addParameter(
         ParameterSelection(self.DATABASE,
                            self.tr('Database (connection name)'),
                            self.DB_CONNECTIONS))
     self.addParameter(
         ParameterVector(self.INPUT_LAYER, self.tr('Input layer'),
                         [ParameterVector.VECTOR_TYPE_ANY], False))
     #self.addParameter(ParameterSelection(self.GTYPE,
     #                                     self.tr('Output geometry type'), self.GEOMTYPE, 0))
     #self.addParameter(ParameterCrs(self.A_SRS,
     #                               self.tr('Assign an output CRS'), '', optional=True))
     self.addParameter(
         ParameterCrs(self.T_SRS,
                      self.tr('Reproject to this CRS on output '),
                      '',
                      optional=True))
     #self.addParameter(ParameterCrs(self.S_SRS,
     #                               self.tr('Override source CRS'), '', optional=True))
     self.addParameter(
         ParameterString(self.SCHEMA, self.tr('Schema name'),
                         'stg_geoserver'))
     self.addParameter(
         ParameterString(self.TABLE,
                         self.tr('The output PostGIS table name'), False))
     self.addParameter(
         ParameterString(self.PK,
                         self.tr('Primary key (new field)'),
                         'id',
                         optional=True))
     self.addParameter(
         ParameterTableField(
             self.PRIMARY_KEY,
             self.
             tr('Primary key (existing field, used if the above option is left empty)'
                ),
             self.INPUT_LAYER,
             optional=True))
     self.addParameter(
         ParameterString(self.GEOCOLUMN,
                         self.tr('Geometry column name'),
                         'the_geom',
                         optional=True))
     #self.addParameter(ParameterSelection(self.DIM,
     #                                     self.tr('Vector dimensions'), self.DIMLIST, 0))
     #self.addParameter(ParameterString(self.SIMPLIFY,
     #                                  self.tr('Distance tolerance for simplification'),
     #                                  '', optional=True))
     #self.addParameter(ParameterString(self.SEGMENTIZE,
     #                                  self.tr('Maximum distance between 2 nodes (densification)'),
     #                                  '', optional=True))
     #self.addParameter(ParameterExtent(self.SPAT,
     #                                  self.tr('Select features by extent (defined in input layer CRS)')))
     #self.addParameter(ParameterBoolean(self.CLIP,
     #                                   self.tr('Clip the input layer using the above (rectangle) extent'),
     #                                   False))
     #self.addParameter(ParameterString(self.WHERE,
     #                                  self.tr('Select features using a SQL "WHERE" statement (Ex: column=\'value\')'),
     #                                  '', optional=True))
     #self.addParameter(ParameterString(self.GT,
     #                                  self.tr('Group N features per transaction (Default: 20000)'),
     #                                  '', optional=True))
     #self.addParameter(ParameterBoolean(self.OVERWRITE,
     #                                   self.tr('Overwrite existing table'), True))
     #self.addParameter(ParameterBoolean(self.APPEND,
     #                                   self.tr('Append to existing table'), False))
     #self.addParameter(ParameterBoolean(self.ADDFIELDS,
     #                                   self.tr('Append and add new fields to existing table'), False))
     #self.addParameter(ParameterBoolean(self.LAUNDER,
     #                                   self.tr('Do not launder columns/table names'), False))
     #self.addParameter(ParameterBoolean(self.INDEX,
     #                                   self.tr('Do not create spatial index'), False))
     self.addParameter(
         ParameterBoolean(
             self.SKIPFAILURES,
             self.tr(
                 'Continue after a failure, skipping the failed feature'),
             False))