Example #1
0
    def initAlgorithm(self, config=None):
        self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT, self.tr('Input layer')))
        self.addParameter(QgsProcessingParameterBand(self.BANDS,
                                                     self.tr('Selected band(s)'),
                                                     None,
                                                     self.INPUT,
                                                     allowMultiple=True))

        options_param = QgsProcessingParameterString(self.OPTIONS,
                                                     self.tr('Additional creation options'),
                                                     defaultValue='',
                                                     optional=True)
        options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class': 'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'}})
        self.addParameter(options_param)

        dataType_param = QgsProcessingParameterEnum(self.DATA_TYPE,
                                                    self.tr('Output data type'),
                                                    self.TYPES,
                                                    allowMultiple=False,
                                                    defaultValue=0)
        dataType_param.setFlags(dataType_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                                  self.tr('Converted')))
Example #2
0
    def initAlgorithm(self, config=None):
        self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT,
                                                            self.tr('Input layer')))
        self.addParameter(QgsProcessingParameterExtent(self.EXTENT,
                                                       self.tr('Clipping extent')))
        self.addParameter(QgsProcessingParameterNumber(self.NODATA,
                                                       self.tr('Assign a specified nodata value to output bands'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       defaultValue=None,
                                                       optional=True))

        options_param = QgsProcessingParameterString(self.OPTIONS,
                                                     self.tr('Additional creation options'),
                                                     defaultValue='',
                                                     optional=True)
        options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class': 'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'}})
        self.addParameter(options_param)

        dataType_param = QgsProcessingParameterEnum(self.DATA_TYPE,
                                                    self.tr('Output data type'),
                                                    self.TYPES,
                                                    allowMultiple=False,
                                                    defaultValue=0)
        dataType_param.setFlags(dataType_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                                  self.tr('Clipped (extent)')))
Example #3
0
    def initAlgorithm(self, config=None):
        self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
                                                              self.tr('Point layer'),
                                                              [QgsProcessing.TypeVectorPoint]))

        z_field_param = QgsProcessingParameterField(self.Z_FIELD,
                                                    self.tr('Z value from field'),
                                                    None,
                                                    self.INPUT,
                                                    QgsProcessingParameterField.Numeric,
                                                    optional=True)
        z_field_param.setFlags(z_field_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(z_field_param)

        self.addParameter(QgsProcessingParameterNumber(self.RADIUS_1,
                                                       self.tr('The first radius of search ellipse'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       minValue=0.0,
                                                       defaultValue=0.0))
        self.addParameter(QgsProcessingParameterNumber(self.RADIUS_2,
                                                       self.tr('The second radius of search ellipse'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       minValue=0.0,
                                                       defaultValue=0.0))
        self.addParameter(QgsProcessingParameterNumber(self.ANGLE,
                                                       self.tr('Angle of search ellipse rotation in degrees (counter clockwise)'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       minValue=0.0,
                                                       maxValue=360.0,
                                                       defaultValue=0.0))
        self.addParameter(QgsProcessingParameterNumber(self.MIN_POINTS,
                                                       self.tr('Minimum number of data points to use'),
                                                       type=QgsProcessingParameterNumber.Integer,
                                                       minValue=0,
                                                       defaultValue=0))
        self.addParameter(QgsProcessingParameterNumber(self.NODATA,
                                                       self.tr('NODATA marker to fill empty points'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       defaultValue=0.0))

        options_param = QgsProcessingParameterString(self.OPTIONS,
                                                     self.tr('Additional creation parameters'),
                                                     defaultValue='',
                                                     optional=True)
        options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class': 'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'}})
        self.addParameter(options_param)

        dataType_param = QgsProcessingParameterEnum(self.DATA_TYPE,
                                                    self.tr('Output data type'),
                                                    self.TYPES,
                                                    allowMultiple=False,
                                                    defaultValue=5)
        dataType_param.setFlags(dataType_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                                  self.tr('Interpolated (moving average)')))
Example #4
0
    def initAlgorithm(self, config=None):
        self.predicates = (
            ('intersects', self.tr('intersects')),
            ('contains', self.tr('contains')),
            ('isEqual', self.tr('equals')),
            ('touches', self.tr('touches')),
            ('overlaps', self.tr('overlaps')),
            ('within', self.tr('within')),
            ('crosses', self.tr('crosses')))

        self.statistics = [
            ('count', self.tr('count')),
            ('unique', self.tr('unique')),
            ('min', self.tr('min')),
            ('max', self.tr('max')),
            ('range', self.tr('range')),
            ('sum', self.tr('sum')),
            ('mean', self.tr('mean')),
            ('median', self.tr('median')),
            ('stddev', self.tr('stddev')),
            ('minority', self.tr('minority')),
            ('majority', self.tr('majority')),
            ('q1', self.tr('q1')),
            ('q3', self.tr('q3')),
            ('iqr', self.tr('iqr')),
            ('empty', self.tr('empty')),
            ('filled', self.tr('filled')),
            ('min_length', self.tr('min_length')),
            ('max_length', self.tr('max_length')),
            ('mean_length', self.tr('mean_length'))]

        self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
                                                              self.tr('Input layer'),
                                                              [QgsProcessing.TypeVectorAnyGeometry]))
        self.addParameter(QgsProcessingParameterFeatureSource(self.JOIN,
                                                              self.tr('Join layer'),
                                                              [QgsProcessing.TypeVectorAnyGeometry]))
        predicate = QgsProcessingParameterEnum(self.PREDICATE,
                                               self.tr('Geometric predicate'),
                                               options=[p[1] for p in self.predicates],
                                               allowMultiple=True, defaultValue=[0])
        predicate.setMetadata({
            'widget_wrapper': {
                'useCheckBoxes': True,
                'columns': 2}})
        self.addParameter(predicate)
        self.addParameter(QgsProcessingParameterField(self.JOIN_FIELDS,
                                                      self.tr('Fields to summarise (leave empty to use all fields)'),
                                                      parentLayerParameterName=self.JOIN,
                                                      allowMultiple=True, optional=True))
        self.addParameter(QgsProcessingParameterEnum(self.SUMMARIES,
                                                     self.tr(
                                                         'Summaries to calculate (leave empty to use all available)'),
                                                     options=[p[1] for p in self.statistics],
                                                     allowMultiple=True, optional=True))
        self.addParameter(QgsProcessingParameterBoolean(self.DISCARD_NONMATCHING,
                                                        self.tr('Discard records which could not be joined'),
                                                        defaultValue=False))
        self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT,
                                                            self.tr('Joined layer')))
Example #5
0
    def initAlgorithm(self, config=None):
        self.methods = ((self.tr('Nearest Neighbour'), 'nearest'),
                        (self.tr('Bilinear'), 'bilinear'),
                        (self.tr('Cubic'), 'cubic'),
                        (self.tr('Cubic Spline'), 'cubicspline'),
                        (self.tr('Lanczos Windowed Sinc'), 'lanczos'),
                        (self.tr('Average'), 'average'))

        self.addParameter(QgsProcessingParameterRasterLayer(self.SPECTRAL,
                                                            self.tr('Spectral dataset')))
        self.addParameter(QgsProcessingParameterRasterLayer(self.PANCHROMATIC,
                                                            self.tr('Panchromatic dataset')))

        resampling_param = QgsProcessingParameterEnum(self.RESAMPLING,
                                                      self.tr('Resampling algorithm'),
                                                      options=[i[0] for i in self.methods],
                                                      defaultValue=2)
        resampling_param.setFlags(resampling_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(resampling_param)

        options_param = QgsProcessingParameterString(self.OPTIONS,
                                                     self.tr('Additional creation options'),
                                                     defaultValue='',
                                                     optional=True)
        options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class': 'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'}})
        self.addParameter(options_param)

        self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                                  self.tr('Output')))
Example #6
0
    def initAlgorithm(self, config=None):
        self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT, self.tr('Input layer')))
        self.addParameter(QgsProcessingParameterCrs(self.TARGET_CRS,
                                                    self.tr('Override the projection for the output file'),
                                                    defaultValue=None,
                                                    optional=True))
        self.addParameter(QgsProcessingParameterNumber(self.NODATA,
                                                       self.tr('Assign a specified nodata value to output bands'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       defaultValue=None,
                                                       optional=True))
        self.addParameter(QgsProcessingParameterBoolean(self.COPY_SUBDATASETS,
                                                        self.tr('Copy all subdatasets of this file to individual output files'),
                                                        defaultValue=False))

        options_param = QgsProcessingParameterString(self.OPTIONS,
                                                     self.tr('Additional creation options'),
                                                     defaultValue='',
                                                     optional=True)
        options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class': 'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'}})
        self.addParameter(options_param)

        dataType_param = QgsProcessingParameterEnum(self.DATA_TYPE,
                                                    self.tr('Output data type'),
                                                    self.TYPES,
                                                    allowMultiple=False,
                                                    defaultValue=0)
        dataType_param.setFlags(dataType_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                                  self.tr('Converted')))
Example #7
0
    def initAlgorithm(self, config=None):
        self.addParameter(
            QgsProcessingParameterRasterLayer(self.INPUT_A,
                                              self.tr('Input layer A'),
                                              optional=False))
        self.addParameter(
            QgsProcessingParameterBand(self.BAND_A,
                                       self.tr('Number of raster band for A'),
                                       parentLayerParameterName=self.INPUT_A))
        self.addParameter(
            QgsProcessingParameterRasterLayer(self.INPUT_B,
                                              self.tr('Input layer B'),
                                              optional=True))
        self.addParameter(
            QgsProcessingParameterBand(self.BAND_B,
                                       self.tr('Number of raster band for B'),
                                       parentLayerParameterName=self.INPUT_B,
                                       optional=True))
        self.addParameter(
            QgsProcessingParameterRasterLayer(self.INPUT_C,
                                              self.tr('Input layer C'),
                                              optional=True))
        self.addParameter(
            QgsProcessingParameterBand(self.BAND_C,
                                       self.tr('Number of raster band for C'),
                                       parentLayerParameterName=self.INPUT_C,
                                       optional=True))
        self.addParameter(
            QgsProcessingParameterRasterLayer(self.INPUT_D,
                                              self.tr('Input layer D'),
                                              optional=True))
        self.addParameter(
            QgsProcessingParameterBand(self.BAND_D,
                                       self.tr('Number of raster band for D'),
                                       parentLayerParameterName=self.INPUT_D,
                                       optional=True))
        self.addParameter(
            QgsProcessingParameterRasterLayer(self.INPUT_E,
                                              self.tr('Input layer E'),
                                              optional=True))
        self.addParameter(
            QgsProcessingParameterBand(self.BAND_E,
                                       self.tr('Number of raster band for E'),
                                       parentLayerParameterName=self.INPUT_E,
                                       optional=True))
        self.addParameter(
            QgsProcessingParameterRasterLayer(self.INPUT_F,
                                              self.tr('Input layer F'),
                                              optional=True))
        self.addParameter(
            QgsProcessingParameterBand(self.BAND_F,
                                       self.tr('Number of raster band for F'),
                                       parentLayerParameterName=self.INPUT_F,
                                       optional=True))
        self.addParameter(
            QgsProcessingParameterString(
                self.FORMULA,
                self.
                tr('Calculation in gdalnumeric syntax using +-/* or any numpy array functions (i.e. logical_and())'
                   ),
                'A*2',
                optional=False))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.NO_DATA,
                self.tr('Set output nodata value'),
                type=QgsProcessingParameterNumber.Double,
                defaultValue=None,
                optional=True))
        self.addParameter(
            QgsProcessingParameterEnum(self.RTYPE,
                                       self.tr('Output raster type'),
                                       options=self.TYPE,
                                       defaultValue=5))

        options_param = QgsProcessingParameterString(
            self.OPTIONS,
            self.tr('Additional creation options'),
            defaultValue='',
            optional=True)
        options_param.setFlags(options_param.flags()
                               | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class':
                'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'
            }
        })
        self.addParameter(options_param)

        self.addParameter(
            QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                    self.tr('Calculated')))
Example #8
0
    def initAlgorithm(self, config=None):
        class ParameterVrtDestination(QgsProcessingParameterRasterDestination):
            def __init__(self, name, description):
                super().__init__(name, description)

            def clone(self):
                copy = ParameterVrtDestination(self.name(), self.description())
                return copy

            def type(self):
                return 'vrt_destination'

            def defaultFileExtension(self):
                return 'vrt'

        self.addParameter(
            QgsProcessingParameterMultipleLayers(
                self.INPUT,
                QCoreApplication.translate("ParameterVrtDestination",
                                           'Input layers'),
                QgsProcessing.TypeRaster))
        self.addParameter(
            QgsProcessingParameterEnum(self.RESOLUTION,
                                       QCoreApplication.translate(
                                           "ParameterVrtDestination",
                                           'Resolution'),
                                       options=self.RESOLUTION_OPTIONS,
                                       defaultValue=0))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.SEPARATE,
                QCoreApplication.translate(
                    "ParameterVrtDestination",
                    'Place each input file into a separate band'),
                defaultValue=True))
        self.addParameter(
            QgsProcessingParameterBoolean(self.PROJ_DIFFERENCE,
                                          QCoreApplication.translate(
                                              "ParameterVrtDestination",
                                              'Allow projection difference'),
                                          defaultValue=False))

        add_alpha_param = QgsProcessingParameterBoolean(
            self.ADD_ALPHA,
            QCoreApplication.translate(
                "ParameterVrtDestination",
                'Add alpha mask band to VRT when source raster has none'),
            defaultValue=False)
        add_alpha_param.setFlags(
            add_alpha_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(add_alpha_param)

        assign_crs = QgsProcessingParameterCrs(
            self.ASSIGN_CRS,
            QCoreApplication.translate(
                "ParameterVrtDestination",
                'Override projection for the output file'),
            defaultValue=None,
            optional=True)
        assign_crs.setFlags(assign_crs.flags()
                            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(assign_crs)

        resampling = QgsProcessingParameterEnum(
            self.RESAMPLING,
            QCoreApplication.translate("ParameterVrtDestination",
                                       'Resampling algorithm'),
            options=self.RESAMPLING_OPTIONS,
            defaultValue=0)
        resampling.setFlags(resampling.flags()
                            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(resampling)

        self.addParameter(
            ParameterVrtDestination(
                self.OUTPUT,
                QCoreApplication.translate("ParameterVrtDestination",
                                           'Virtual')))
Example #9
0
    def accept(self):
        description = 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 self.alg.parameterDefinition(name):
                name = safeName.lower() + str(i)
                i += 1
        else:
            name = self.param.name()
        if (self.paramType == parameters.PARAMETER_BOOLEAN
                or isinstance(self.param, QgsProcessingParameterBoolean)):
            self.param = QgsProcessingParameterBoolean(name, description,
                                                       self.state.isChecked())
        elif (self.paramType == parameters.PARAMETER_TABLE_FIELD
              or isinstance(self.param, QgsProcessingParameterField)):
            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()
            default = self.defaultTextBox.text()
            if not default:
                default = None
            self.param = QgsProcessingParameterField(
                name,
                description,
                defaultValue=default,
                parentLayerParameterName=parent,
                type=datatype,
                allowMultiple=self.multipleCheck.isChecked())
        elif (self.paramType == parameters.PARAMETER_BAND
              or isinstance(self.param, QgsProcessingParameterBand)):
            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()
            self.param = QgsProcessingParameterBand(name, description, None,
                                                    parent)
        elif (self.paramType == parameters.PARAMETER_MAP_LAYER
              or isinstance(self.param, QgsProcessingParameterMapLayer)):
            self.param = QgsProcessingParameterMapLayer(name, description)
        elif (self.paramType == parameters.PARAMETER_RASTER
              or isinstance(self.param, QgsProcessingParameterRasterLayer)):
            self.param = QgsProcessingParameterRasterLayer(name, description)
        elif (self.paramType == parameters.PARAMETER_TABLE
              or isinstance(self.param, QgsProcessingParameterVectorLayer)):
            self.param = QgsProcessingParameterVectorLayer(
                name, description, [self.shapetypeCombo.currentData()])
        elif (self.paramType == parameters.PARAMETER_VECTOR
              or isinstance(self.param, QgsProcessingParameterFeatureSource)):
            self.param = QgsProcessingParameterFeatureSource(
                name, description, [self.shapetypeCombo.currentData()])
        elif (self.paramType == parameters.PARAMETER_MULTIPLE
              or isinstance(self.param, QgsProcessingParameterMultipleLayers)):
            self.param = QgsProcessingParameterMultipleLayers(
                name, description, self.datatypeCombo.currentData())
        elif (self.paramType == parameters.PARAMETER_NUMBER or isinstance(
                self.param,
            (QgsProcessingParameterNumber, QgsProcessingParameterDistance))):
            try:
                self.param = QgsProcessingParameterNumber(
                    name, description, QgsProcessingParameterNumber.Double,
                    self.defaultTextBox.text())
                vmin = self.minTextBox.text().strip()
                if not vmin == '':
                    self.param.setMinimum(float(vmin))
                vmax = self.maxTextBox.text().strip()
                if not vmax == '':
                    self.param.setMaximum(float(vmax))
            except:
                QMessageBox.warning(
                    self, self.tr('Unable to define parameter'),
                    self.tr('Wrong or missing parameter values'))
                return
        elif (self.paramType == parameters.PARAMETER_EXPRESSION
              or isinstance(self.param, QgsProcessingParameterExpression)):
            parent = self.parentCombo.currentData()
            self.param = QgsProcessingParameterExpression(
                name, description, str(self.defaultEdit.expression()), parent)
        elif (self.paramType == parameters.PARAMETER_STRING
              or isinstance(self.param, QgsProcessingParameterString)):
            self.param = QgsProcessingParameterString(
                name, description, str(self.defaultTextBox.text()))
        elif (self.paramType == parameters.PARAMETER_EXTENT
              or isinstance(self.param, QgsProcessingParameterExtent)):
            self.param = QgsProcessingParameterExtent(name, description)
        elif (self.paramType == parameters.PARAMETER_FILE
              or isinstance(self.param, QgsProcessingParameterFile)):
            isFolder = self.fileFolderCombo.currentIndex() == 1
            self.param = QgsProcessingParameterFile(
                name, description, QgsProcessingParameterFile.Folder
                if isFolder else QgsProcessingParameterFile.File)
        elif (self.paramType == parameters.PARAMETER_POINT
              or isinstance(self.param, QgsProcessingParameterPoint)):
            self.param = QgsProcessingParameterPoint(
                name, description, str(self.defaultTextBox.text()))
        elif (self.paramType == parameters.PARAMETER_CRS
              or isinstance(self.param, QgsProcessingParameterCrs)):
            self.param = QgsProcessingParameterCrs(
                name, description,
                self.selector.crs().authid())
        elif (self.paramType == parameters.PARAMETER_ENUM
              or isinstance(self.param, QgsProcessingParameterEnum)):
            self.param = QgsProcessingParameterEnum(
                name, description, self.widget.options(),
                self.widget.allowMultiple(), self.widget.defaultOptions())
        elif (self.paramType == parameters.PARAMETER_MATRIX
              or isinstance(self.param, QgsProcessingParameterMatrix)):
            self.param = QgsProcessingParameterMatrix(
                name,
                description,
                hasFixedNumberRows=self.widget.fixedRows(),
                headers=self.widget.headers(),
                defaultValue=self.widget.value())

        # Destination parameter
        elif (isinstance(self.param, QgsProcessingParameterFeatureSink)):
            self.param = QgsProcessingParameterFeatureSink(
                name=name,
                description=self.param.description(),
                type=self.param.dataType(),
                defaultValue=self.defaultWidget.getValue())
        elif (isinstance(self.param, QgsProcessingParameterFileDestination)):
            self.param = QgsProcessingParameterFileDestination(
                name=name,
                description=self.param.description(),
                fileFilter=self.param.fileFilter(),
                defaultValue=self.defaultWidget.getValue())
        elif (isinstance(self.param, QgsProcessingParameterFolderDestination)):
            self.param = QgsProcessingParameterFolderDestination(
                name=name,
                description=self.param.description(),
                defaultValue=self.defaultWidget.getValue())
        elif (isinstance(self.param, QgsProcessingParameterRasterDestination)):
            self.param = QgsProcessingParameterRasterDestination(
                name=name,
                description=self.param.description(),
                defaultValue=self.defaultWidget.getValue())
        elif (isinstance(self.param, QgsProcessingParameterVectorDestination)):
            self.param = QgsProcessingParameterVectorDestination(
                name=name,
                description=self.param.description(),
                type=self.param.dataType(),
                defaultValue=self.defaultWidget.getValue())

        else:
            if self.paramType:
                typeId = self.paramType
            else:
                typeId = self.param.type()

            paramTypeDef = QgsApplication.instance().processingRegistry(
            ).parameterType(typeId)
            if not paramTypeDef:
                msg = self.tr(
                    'The parameter `{}` is not registered, are you missing a required plugin?'
                    .format(typeId))
                raise UndefinedParameterException(msg)
            self.param = paramTypeDef.create(name)
            self.param.setDescription(description)
            self.param.setMetadata(paramTypeDef.metadata())

        if not self.requiredCheck.isChecked():
            self.param.setFlags(
                self.param.flags()
                | QgsProcessingParameterDefinition.FlagOptional)
        else:
            self.param.setFlags(
                self.param.flags()
                & ~QgsProcessingParameterDefinition.FlagOptional)

        settings = QgsSettings()
        settings.setValue(
            "/Processing/modelParametersDefinitionDialogGeometry",
            self.saveGeometry())

        QDialog.accept(self)
    def initAlgorithm(self, config=None):
        """
        Here we define the inputs and output of the algorithm, along
        with some other properties.
        """

        # We add the input vector features source. It can have any kind of
        # point.
        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.INPUT, self.tr('Input Point Layer'),
                [QgsProcessing.TypeVectorPoint]))
        self.keys = [
            'accommodation', 'administrative-areas-buildings',
            'administrative-region', 'airport', 'ambulance-services',
            'amusement-holiday-park', 'atm-bank-exchange', 'bar-pub',
            'body-of-water', 'bookshop', 'building', 'business-industry',
            'business-services', 'camping', 'car-dealer-repair', 'car-rental',
            'casino', 'cinema', 'city-town-village',
            'clothing-accessories-shop', 'coffee', 'coffee-tea',
            'communication-media', 'dance-night-club', 'department-store',
            'eat-drink', 'education-facility', 'electronics-shop',
            'ev-charging-station', 'facilities', 'facility',
            'fair-convention-facility', 'ferry-terminal', 'fire-department',
            'food-drink', 'forest-heath-vegetation', 'going-out',
            'government-community-facility', 'hardware-house-garden-shop',
            'hospital-health-care-facility', 'hospital-health-care-facility',
            'hostel', 'hotel', 'intersection', 'kiosk-convenience-store',
            'landmark-attraction', 'leisure-outdoor', 'library', 'mall',
            'motel', 'mountain-hill', 'museum', 'natural-geographical',
            'outdoor-area-complex', 'parking-facility', 'petrol-station',
            'pharmacy', 'police-emergency', 'police-station', 'post-office',
            'postal-area', 'public-transport', 'railway-station', 'recreation',
            'religious-place', 'restaurant', 'service', 'shop', 'shopping',
            'sights-museums', 'snacks-fast-food', 'sport-outdoor-shop',
            'sports-facility-venue', 'street-square', 'taxi-stand', 'tea',
            'theatre-music-culture', 'toilet-rest-area', 'tourist-information',
            'transport', 'travel-agency', 'undersea-feature',
            'wine-and-liquor', 'zoo'
        ]
        self.addParameter(
            QgsProcessingParameterEnum(
                self.KEYS,
                self.tr('POI Categories'),
                options=self.keys,
                # defaultValue=0,
                optional=False,
                allowMultiple=True))
        # self.modes = [
        #    "walk", #indicates that the user is on foot.
        #    "drive", #indicates that the user is driving.
        #    "public_transport", #indicates that the user is on public transport.
        #    "bicycle", #indicates that the user is on bicycle.
        #    "none" #if the user is neither on foot nor driving.
        # ]
        # self.addParameter(
        #    QgsProcessingParameterEnum(
        #        self.MODES,
        #        self.tr('Traffic Mode'),
        #        options=self.modes,
        #        #defaultValue=0,
        #        optional=False,
        #        allowMultiple=False
        #    )
        # )
        # self.addParameter(
        #    QgsProcessingParameterNumber(
        #        self.RADIUS,
        #        self.tr('Radius around Points [m]'),
        # parentParameterName=self.INPUT,
        # options=self.keys,
        #        defaultValue=100,
        #        minValue=1,
        #        maxValue=100000,
        #    defaultUnit="DistanceMeters",
        #        optional=False,
        #    )#.setDefaultUnit(QgsUnitTypes.DistanceMeters)
        # )

        # We add a feature sink in which to store our processed features (this
        # usually takes the form of a newly created vector layer when the
        # algorithm is run in QGIS).
        self.addParameter(
            QgsProcessingParameterFeatureSink(self.OUTPUT,
                                              self.tr('POI layer')))
Example #11
0
    def initAlgorithm(self, config=None):
        self.predicates = (
            ('intersects', self.tr('intersects')),
            ('contains', self.tr('contains')),
            ('equals', self.tr('equals')),
            ('touches', self.tr('touches')),
            ('overlaps', self.tr('overlaps')),
            ('within', self.tr('within')),
            ('crosses', self.tr('crosses')))

        self.statistics = [
            ('count', self.tr('count')),
            ('unique', self.tr('unique')),
            ('min', self.tr('min')),
            ('max', self.tr('max')),
            ('range', self.tr('range')),
            ('sum', self.tr('sum')),
            ('mean', self.tr('mean')),
            ('median', self.tr('median')),
            ('stddev', self.tr('stddev')),
            ('minority', self.tr('minority')),
            ('majority', self.tr('majority')),
            ('q1', self.tr('q1')),
            ('q3', self.tr('q3')),
            ('iqr', self.tr('iqr')),
            ('empty', self.tr('empty')),
            ('filled', self.tr('filled')),
            ('min_length', self.tr('min_length')),
            ('max_length', self.tr('max_length')),
            ('mean_length', self.tr('mean_length'))]

        self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
                                                              self.tr('Input layer'),
                                                              [QgsProcessing.TypeVectorAnyGeometry]))
        self.addParameter(QgsProcessingParameterFeatureSource(self.JOIN,
                                                              self.tr('Join layer'),
                                                              [QgsProcessing.TypeVectorAnyGeometry]))
        predicate = QgsProcessingParameterEnum(self.PREDICATE,
                                               self.tr('Geometric predicate'),
                                               options=[p[1] for p in self.predicates],
                                               allowMultiple=True, defaultValue=[0])
        predicate.setMetadata({
            'widget_wrapper': {
                'class': 'processing.gui.wrappers.EnumWidgetWrapper',
                'useCheckBoxes': True,
                'columns': 2}})
        self.addParameter(predicate)
        self.addParameter(QgsProcessingParameterField(self.JOIN_FIELDS,
                                                      self.tr('Fields to summarise (leave empty to use all fields)'),
                                                      parentLayerParameterName=self.JOIN,
                                                      allowMultiple=True, optional=True))
        self.addParameter(QgsProcessingParameterEnum(self.SUMMARIES,
                                                     self.tr(
                                                         'Summaries to calculate (leave empty to use all available)'),
                                                     options=[p[1] for p in self.statistics],
                                                     allowMultiple=True, optional=True))
        self.addParameter(QgsProcessingParameterBoolean(self.DISCARD_NONMATCHING,
                                                        self.tr('Discard records which could not be joined'),
                                                        defaultValue=False))
        self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT,
                                                            self.tr('Joined layer')))
Example #12
0
    def initAlgorithm(self, config=None):
        self.KERNELS = OrderedDict([
            (self.tr('Quartic'), QgsKernelDensityEstimation.KernelQuartic),
            (self.tr('Triangular'),
             QgsKernelDensityEstimation.KernelTriangular),
            (self.tr('Uniform'), QgsKernelDensityEstimation.KernelUniform),
            (self.tr('Triweight'), QgsKernelDensityEstimation.KernelTriweight),
            (self.tr('Epanechnikov'),
             QgsKernelDensityEstimation.KernelEpanechnikov)
        ])

        self.OUTPUT_VALUES = OrderedDict([
            (self.tr('Raw'), QgsKernelDensityEstimation.OutputRaw),
            (self.tr('Scaled'), QgsKernelDensityEstimation.OutputScaled)
        ])

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.INPUT, self.tr('Point layer'),
                [QgsProcessing.TypeVectorPoint]))

        self.addParameter(
            QgsProcessingParameterNumber(self.RADIUS,
                                         self.tr('Radius (layer units)'),
                                         QgsProcessingParameterNumber.Double,
                                         100.0, False, 0.0, 9999999999.99))

        radius_field_param = QgsProcessingParameterField(
            self.RADIUS_FIELD,
            self.tr('Radius from field'),
            None,
            self.INPUT,
            QgsProcessingParameterField.Numeric,
            optional=True)
        radius_field_param.setFlags(
            radius_field_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(radius_field_param)

        class ParameterHeatmapPixelSize(QgsProcessingParameterNumber):
            def __init__(self,
                         name='',
                         description='',
                         parent_layer=None,
                         radius_param=None,
                         radius_field_param=None,
                         minValue=None,
                         maxValue=None,
                         default=None,
                         optional=False):
                QgsProcessingParameterNumber.__init__(
                    self, name, description,
                    QgsProcessingParameterNumber.Double, default, optional,
                    minValue, maxValue)
                self.parent_layer = parent_layer
                self.radius_param = radius_param
                self.radius_field_param = radius_field_param

            def clone(self):
                copy = ParameterHeatmapPixelSize(
                    self.name(), self.description(), self.parent_layer,
                    self.radius_param, self.radius_field_param, self.minimum(),
                    self.maximum(),
                    self.defaultValue(
                        (),
                        self.flags()
                        & QgsProcessingParameterDefinition.FlagOptional))
                return copy

        pixel_size_param = ParameterHeatmapPixelSize(
            self.PIXEL_SIZE,
            self.tr('Output raster size'),
            parent_layer=self.INPUT,
            radius_param=self.RADIUS,
            radius_field_param=self.RADIUS_FIELD,
            minValue=0.0,
            maxValue=9999999999,
            default=0.1)
        pixel_size_param.setMetadata({
            'widget_wrapper': {
                'class':
                'processing.algs.qgis.ui.HeatmapWidgets.HeatmapPixelSizeWidgetWrapper'
            }
        })
        self.addParameter(pixel_size_param)

        weight_field_param = QgsProcessingParameterField(
            self.WEIGHT_FIELD,
            self.tr('Weight from field'),
            None,
            self.INPUT,
            QgsProcessingParameterField.Numeric,
            optional=True)
        weight_field_param.setFlags(
            weight_field_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(weight_field_param)

        keys = list(self.KERNELS.keys())
        kernel_shape_param = QgsProcessingParameterEnum(
            self.KERNEL,
            self.tr('Kernel shape'),
            keys,
            allowMultiple=False,
            defaultValue=0)
        kernel_shape_param.setFlags(
            kernel_shape_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(kernel_shape_param)

        decay_ratio = QgsProcessingParameterNumber(
            self.DECAY, self.tr('Decay ratio (Triangular kernels only)'),
            QgsProcessingParameterNumber.Double, 0.0, True, -100.0, 100.0)
        decay_ratio.setFlags(decay_ratio.flags()
                             | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(decay_ratio)

        keys = list(self.OUTPUT_VALUES.keys())
        output_scaling = QgsProcessingParameterEnum(
            self.OUTPUT_VALUE,
            self.tr('Output value scaling'),
            keys,
            allowMultiple=False,
            defaultValue=0)
        output_scaling.setFlags(
            output_scaling.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(output_scaling)

        self.addParameter(
            QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                    self.tr('Heatmap')))
 def initAlgorithm(self, config):
     self.addParameter(
         QgsProcessingParameterFeatureSource(
             self.PrmInputLayer, tr('Input point layer'),
             [QgsProcessing.TypeVectorPoint]))
     self.addParameter(
         QgsProcessingParameterEnum(self.PrmShapeType,
                                    tr('Shape type'),
                                    options=SHAPE_TYPE,
                                    defaultValue=0,
                                    optional=False))
     self.addParameter(
         QgsProcessingParameterField(
             self.PrmSemiMajorAxisField,
             tr('Semi-major axis field'),
             parentLayerParameterName=self.PrmInputLayer,
             type=QgsProcessingParameterField.Any,
             optional=True))
     self.addParameter(
         QgsProcessingParameterField(
             self.PrmSemiMinorAxisField,
             tr('Semi-minor axis field'),
             parentLayerParameterName=self.PrmInputLayer,
             type=QgsProcessingParameterField.Any,
             optional=True))
     self.addParameter(
         QgsProcessingParameterField(
             self.PrmOrientationField,
             tr('Orientation of axis field'),
             parentLayerParameterName=self.PrmInputLayer,
             type=QgsProcessingParameterField.Any,
             optional=True))
     self.addParameter(
         QgsProcessingParameterNumber(self.PrmDefaultSemiMajorAxis,
                                      tr('Default semi-major axis'),
                                      QgsProcessingParameterNumber.Double,
                                      defaultValue=40.0,
                                      minValue=0.00001,
                                      optional=True))
     self.addParameter(
         QgsProcessingParameterNumber(self.PrmDefaultSemiMinorAxis,
                                      tr('Default semi-minor axis'),
                                      QgsProcessingParameterNumber.Double,
                                      defaultValue=20.0,
                                      minValue=0.00001,
                                      optional=True))
     self.addParameter(
         QgsProcessingParameterNumber(self.PrmDefaultOrientation,
                                      tr('Default orientation of axis'),
                                      QgsProcessingParameterNumber.Double,
                                      defaultValue=0,
                                      minValue=-360,
                                      maxValue=360,
                                      optional=True))
     self.addParameter(
         QgsProcessingParameterEnum(self.PrmUnitsOfMeasure,
                                    tr('Radius units'),
                                    options=DISTANCE_LABELS,
                                    defaultValue=0,
                                    optional=False))
     self.addParameter(
         QgsProcessingParameterNumber(
             self.PrmDrawingSegments,
             tr('Number of drawing segments (approximate)'),
             QgsProcessingParameterNumber.Integer,
             defaultValue=64,
             minValue=8,
             optional=True))
     self.addParameter(
         QgsProcessingParameterBoolean(
             self.PrmExportInputGeometry,
             tr('Add input geometry fields to output table'),
             False,
             optional=True))
     self.addParameter(
         QgsProcessingParameterFeatureSink(self.PrmOutputLayer,
                                           tr('Output layer')))
Example #14
0
 def initAlgorithm(self, config):
     for par in self.param:
         pl = par.split('|')
         if pl[0] == 'ParameterRaster':
             self.addParameter(
                 QgsProcessingParameterRasterLayer(pl[1],
                                                   self.tr(pl[2]), '',
                                                   bool(strtobool(pl[3]))))
         if pl[0] == 'ParameterVector':
             self.addParameter(
                 QgsProcessingParameterVectorLayer(pl[1], self.tr(
                     pl[2]), [QgsProcessing.TypeVector], '',
                                                   bool(strtobool(pl[4]))))
         if pl[0] == 'ParameterNumber':
             try:
                 int(pl[5])
                 if pl[4] != 'None':
                     self.addParameter(
                         QgsProcessingParameterNumber(
                             pl[1], self.tr(pl[2]), 0, int(pl[5]), False,
                             int(pl[3]), int(pl[4])))
                 else:
                     self.addParameter(
                         QgsProcessingParameterNumber(
                             pl[1], self.tr(pl[2]), 0, int(pl[5]), False,
                             int(pl[3])))
             except ValueError:
                 if pl[4] != 'None':
                     self.addParameter(
                         QgsProcessingParameterNumber(
                             pl[1], self.tr(pl[2]), 1, float(pl[5]), False,
                             float(pl[3]), float(pl[4])))
                 else:
                     self.addParameter(
                         QgsProcessingParameterNumber(
                             pl[1], self.tr(pl[2]), 1, float(pl[5]), False,
                             float(pl[3])))
         if pl[0] == 'ParameterBoolean':
             self.addParameter(
                 QgsProcessingParameterBoolean(pl[1], self.tr(pl[2]),
                                               bool(strtobool(pl[3])),
                                               False))
         if pl[0] == 'ParameterEnum':
             self.addParameter(
                 QgsProcessingParameterEnum(pl[1], self.tr(pl[2]),
                                            literal_eval(pl[3]), False,
                                            pl[4], False))
     for out in self.outputline:
         ol = out.split('|')
         if ol[0] == 'OutputRaster':
             self.addParameter(
                 QgsProcessingParameterRasterDestination(
                     ol[1][1:], self.tr(ol[2])))
         if ol[0] == 'OutputVector':
             self.addParameter(
                 QgsProcessingParameterVectorDestination(
                     ol[1][1:], self.tr(ol[2])))
         if ol[0] == 'OutputFile':
             self.addParameter(
                 QgsProcessingParameterFileDestination(
                     ol[1][1:], self.tr(ol[2])))
Example #15
0
    def initAlgorithm(self, config=None):
        self.addParameter(
            QgsProcessingParameterRasterLayer(self.INPUT,
                                              self.tr('Input layer')))
        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.MASK, self.tr('Mask layer'),
                [QgsProcessing.TypeVectorPolygon]))
        self.addParameter(
            QgsProcessingParameterCrs(self.SOURCE_CRS,
                                      self.tr('Source CRS'),
                                      optional=True))
        self.addParameter(
            QgsProcessingParameterCrs(self.TARGET_CRS,
                                      self.tr('Target CRS'),
                                      optional=True))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.NODATA,
                self.tr('Assign a specified nodata value to output bands'),
                type=QgsProcessingParameterNumber.Double,
                defaultValue=None,
                optional=True))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.ALPHA_BAND,
                self.tr('Create an output alpha band'),
                defaultValue=False))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.CROP_TO_CUTLINE,
                self.
                tr('Match the extent of the clipped raster to the extent of the mask layer'
                   ),
                defaultValue=True))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.KEEP_RESOLUTION,
                self.tr('Keep resolution of input raster'),
                defaultValue=False))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.SET_RESOLUTION,
                self.tr('Set output file resolution'),
                defaultValue=False))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.X_RESOLUTION,
                self.tr('X Resolution to output bands'),
                type=QgsProcessingParameterNumber.Double,
                defaultValue=None,
                optional=True))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.Y_RESOLUTION,
                self.tr('Y Resolution to output bands'),
                type=QgsProcessingParameterNumber.Double,
                defaultValue=None,
                optional=True))
        multithreading_param = QgsProcessingParameterBoolean(
            self.MULTITHREADING,
            self.tr('Use multithreaded warping implementation'),
            defaultValue=False)
        multithreading_param.setFlags(
            multithreading_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(multithreading_param)
        options_param = QgsProcessingParameterString(
            self.OPTIONS,
            self.tr('Additional creation options'),
            defaultValue='',
            optional=True)
        options_param.setFlags(options_param.flags()
                               | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class':
                'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'
            }
        })
        self.addParameter(options_param)

        dataType_param = QgsProcessingParameterEnum(
            self.DATA_TYPE,
            self.tr('Output data type'),
            self.TYPES,
            allowMultiple=False,
            defaultValue=0)
        dataType_param.setFlags(
            dataType_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        self.addParameter(
            QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                    self.tr('Clipped (mask)')))
Example #16
0
    def initAlgorithm(self, config=None):

        db_param = QgsProcessingParameterString(
            self.DATABASE, self.tr('Database (connection name)'))
        db_param.setMetadata({
            'widget_wrapper': {
                'class':
                'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'
            }
        })
        self.addParameter(db_param)
        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.INPUT,
                self.tr('Input layer'),
                types=[QgsProcessing.TypeVector]))
        self.addParameter(
            QgsProcessingParameterString(self.SHAPE_ENCODING,
                                         self.tr('Shape encoding'),
                                         "",
                                         optional=True))
        self.addParameter(
            QgsProcessingParameterEnum(self.GTYPE,
                                       self.tr('Output geometry type'),
                                       options=self.GEOMTYPE,
                                       defaultValue=0))
        self.addParameter(
            QgsProcessingParameterCrs(self.A_SRS,
                                      self.tr('Assign an output CRS'),
                                      defaultValue='',
                                      optional=False))
        self.addParameter(
            QgsProcessingParameterCrs(
                self.T_SRS,
                self.tr('Reproject to this CRS on output '),
                defaultValue='',
                optional=True))
        self.addParameter(
            QgsProcessingParameterCrs(self.S_SRS,
                                      self.tr('Override source CRS'),
                                      defaultValue='',
                                      optional=True))

        schema_param = QgsProcessingParameterString(
            self.SCHEMA, self.tr('Schema (schema name)'), 'public', False,
            True)
        schema_param.setMetadata({
            'widget_wrapper': {
                'class': 'processing.gui.wrappers_postgis.SchemaWidgetWrapper',
                'connection_param': self.DATABASE
            }
        })
        self.addParameter(schema_param)

        table_param = QgsProcessingParameterString(
            self.TABLE,
            self.tr('Table to import to (leave blank to use layer name)'), '',
            False, True)
        table_param.setMetadata({
            'widget_wrapper': {
                'class': 'processing.gui.wrappers_postgis.TableWidgetWrapper',
                'schema_param': self.SCHEMA
            }
        })
        self.addParameter(table_param)

        self.addParameter(
            QgsProcessingParameterString(self.PK,
                                         self.tr('Primary key (new field)'),
                                         defaultValue='id',
                                         optional=True))
        self.addParameter(
            QgsProcessingParameterField(
                self.PRIMARY_KEY,
                self.
                tr('Primary key (existing field, used if the above option is left empty)'
                   ),
                parentLayerParameterName=self.INPUT,
                optional=True))
        self.addParameter(
            QgsProcessingParameterString(self.GEOCOLUMN,
                                         self.tr('Geometry column name'),
                                         defaultValue='geom',
                                         optional=True))
        self.addParameter(
            QgsProcessingParameterEnum(self.DIM,
                                       self.tr('Vector dimensions'),
                                       options=self.DIMLIST,
                                       defaultValue=0))
        self.addParameter(
            QgsProcessingParameterString(
                self.SIMPLIFY,
                self.tr('Distance tolerance for simplification'),
                defaultValue='',
                optional=True))
        self.addParameter(
            QgsProcessingParameterString(
                self.SEGMENTIZE,
                self.tr('Maximum distance between 2 nodes (densification)'),
                defaultValue='',
                optional=True))
        self.addParameter(
            QgsProcessingParameterExtent(
                self.SPAT,
                self.tr(
                    'Select features by extent (defined in input layer CRS)'),
                optional=True))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.CLIP,
                self.tr(
                    'Clip the input layer using the above (rectangle) extent'),
                defaultValue=False))
        self.addParameter(
            QgsProcessingParameterString(
                self.WHERE,
                self.
                tr('Select features using a SQL "WHERE" statement (Ex: column=\'value\')'
                   ),
                defaultValue='',
                optional=True))
        self.addParameter(
            QgsProcessingParameterString(
                self.GT,
                self.tr('Group N features per transaction (Default: 20000)'),
                defaultValue='',
                optional=True))
        self.addParameter(
            QgsProcessingParameterBoolean(self.OVERWRITE,
                                          self.tr('Overwrite existing table'),
                                          defaultValue=True))
        self.addParameter(
            QgsProcessingParameterBoolean(self.APPEND,
                                          self.tr('Append to existing table'),
                                          defaultValue=False))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.ADDFIELDS,
                self.tr('Append and add new fields to existing table'),
                defaultValue=False))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.LAUNDER,
                self.tr('Do not launder columns/table names'),
                defaultValue=False))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.INDEX,
                self.tr('Do not create spatial index'),
                defaultValue=False))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.SKIPFAILURES,
                self.tr(
                    'Continue after a failure, skipping the failed feature'),
                defaultValue=False))
        self.addParameter(
            QgsProcessingParameterBoolean(self.PROMOTETOMULTI,
                                          self.tr('Promote to Multipart'),
                                          defaultValue=True))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.PRECISION,
                self.tr('Keep width and precision of input attributes'),
                defaultValue=True))
        self.addParameter(
            QgsProcessingParameterString(
                self.OPTIONS,
                self.tr('Additional creation options'),
                defaultValue='',
                optional=True))
Example #17
0
    def initAlgorithm(self, config=None):
        self.predicates = (('intersects', self.tr('intersects')),
                           ('contains', self.tr('contains')),
                           ('isEqual', self.tr('equals')),
                           ('touches',
                            self.tr('touches')), ('overlaps',
                                                  self.tr('overlaps')),
                           ('within', self.tr('within')), ('crosses',
                                                           self.tr('crosses')))

        self.reversed_predicates = {
            'intersects': 'intersects',
            'contains': 'within',
            'isEqual': 'isEqual',
            'touches': 'touches',
            'overlaps': 'overlaps',
            'within': 'contains',
            'crosses': 'crosses'
        }

        self.methods = [
            self.
            tr('Create separate feature for each located feature (one-to-many)'
               ),
            self.
            tr('Take attributes of the first located feature only (one-to-one)'
               )
        ]

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.INPUT, self.tr('Input layer'),
                [QgsProcessing.TypeVectorAnyGeometry]))
        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.JOIN, self.tr('Join layer'),
                [QgsProcessing.TypeVectorAnyGeometry]))

        predicate = QgsProcessingParameterEnum(
            self.PREDICATE,
            self.tr('Geometric predicate'),
            options=[p[1] for p in self.predicates],
            allowMultiple=True,
            defaultValue=[0])
        predicate.setMetadata({
            'widget_wrapper': {
                'class': 'processing.gui.wrappers.EnumWidgetWrapper',
                'useCheckBoxes': True,
                'columns': 2
            }
        })
        self.addParameter(predicate)
        self.addParameter(
            QgsProcessingParameterField(
                self.JOIN_FIELDS,
                self.tr('Fields to add (leave empty to use all fields)'),
                parentLayerParameterName=self.JOIN,
                allowMultiple=True,
                optional=True))
        self.addParameter(
            QgsProcessingParameterEnum(self.METHOD, self.tr('Join type'),
                                       self.methods))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.DISCARD_NONMATCHING,
                self.tr('Discard records which could not be joined'),
                defaultValue=False))
        self.addParameter(
            QgsProcessingParameterString(self.PREFIX,
                                         self.tr('Joined field prefix'),
                                         optional=True))
        self.addParameter(
            QgsProcessingParameterFeatureSink(
                self.OUTPUT,
                self.tr('Joined layer'),
                QgsProcessing.TypeVectorAnyGeometry,
                defaultValue=None,
                optional=True,
                createByDefault=True))

        non_matching = QgsProcessingParameterFeatureSink(
            self.NON_MATCHING,
            self.tr('Unjoinable features from first layer'),
            QgsProcessing.TypeVectorAnyGeometry,
            defaultValue=None,
            optional=True,
            createByDefault=False)
        # TODO GUI doesn't support advanced outputs yet
        # non_matching.setFlags(non_matching.flags() | QgsProcessingParameterDefinition.FlagAdvanced )
        self.addParameter(non_matching)

        self.addOutput(
            QgsProcessingOutputNumber(
                self.JOINED_COUNT,
                self.tr("Number of joined features from input table")))
Example #18
0
 def initAlgorithm(self, config=None):
     """
     Here we define the inputs and output of the algorithm, along
     with some other properties.
     """
     self.addParameter(
         QgsProcessingParameterRasterLayer(
             self.INPUT, self.tr('Input DEM raster layer'),
             [QgsProcessing.TypeRaster]))
     self.addParameter(
         QgsProcessingParameterNumber(
             name="VE_FACTOR",
             description="Vertical exaggeration factor",
             type=QgsProcessingParameterNumber.Double,
             defaultValue=1,
             minValue=-1000,
             maxValue=1000))
     self.addParameter(
         QgsProcessingParameterEnum(name="SKY_MODEL",
                                    description="Sky model",
                                    options=self.sky_model_options,
                                    defaultValue="overcast"))
     self.addParameter(
         QgsProcessingParameterNumber(
             name="NUM_DIRECTIONS",
             description="Number of horizon search directions",
             type=QgsProcessingParameterNumber.Integer,
             defaultValue=32,
             minValue=8,
             maxValue=128))
     self.addParameter(
         QgsProcessingParameterNumber(
             name="SHADOW_DIST",
             description="Max shadow modeling distance",
             type=QgsProcessingParameterNumber.Integer,
             defaultValue=100,
             minValue=10,
             maxValue=1000))
     self.addParameter(
         QgsProcessingParameterNumber(
             name="SHADOW_AZIMUTH",
             description="Shadow azimuth",
             type=QgsProcessingParameterNumber.Double,
             defaultValue=315,
             minValue=0,
             maxValue=360))
     self.addParameter(
         QgsProcessingParameterNumber(
             name="SHADOW_ELEVATION",
             description="Shadow elevation",
             type=QgsProcessingParameterNumber.Double,
             defaultValue=35,
             minValue=0,
             maxValue=90))
     self.addParameter(
         QgsProcessingParameterBoolean(name="SAVE_AS_8BIT",
                                       description="Save as 8bit raster",
                                       defaultValue=False))
     self.addParameter(
         QgsProcessingParameterBoolean(name="FILL_NO_DATA",
                                       description="Fill no-data (holes)",
                                       defaultValue=True))
     self.addParameter(
         QgsProcessingParameterBoolean(name="KEEP_ORIG_NO_DATA",
                                       description="Keep original no-data",
                                       defaultValue=False))
     self.addParameter(
         QgsProcessingParameterRasterDestination(
             self.OUTPUT, self.tr('Output visualization raster layer')))
Example #19
0
    def initAlgorithm(self, config=None):
        """
        Definition of inputs and outputs of the algorithm, along with some other properties.
        """

        # We add the input vector layer. It can have any kind of geometry
        # It is a mandatory (not optional) one, hence the False argument

        self.addParameter(
            QgsProcessingParameterFeatureSource(self.INPUT,
                                                self.tr('Input layer'),
                                                [QgsProcessing.TypeVector],
                                                None, False))
        self.addParameter(
            QgsProcessingParameterField(self.FIELD_SEGMENT_ID,
                                        self.tr('Segment ID field'), None,
                                        self.INPUT,
                                        QgsProcessingParameterField.Any))

        # read server connections and prepare enum items
        self.connection_options.clear()
        default_graph_server = Settings.get_selected_graph_server()
        selected_index = 0
        for index, connection in enumerate(
                self.connection_manager.read_connections()):
            self.connection_options.append(connection.name)
            if selected_index == 0 and isinstance(default_graph_server, str)\
                    and connection.name == default_graph_server:
                selected_index = index
        self.addParameter(
            QgsProcessingParameterEnum(self.SERVER_NAME,
                                       self.tr('Server name'),
                                       self.connection_options, False,
                                       selected_index, False))

        default_graph_name = Settings.get_selected_graph_name()
        graph_name = ''
        if isinstance(default_graph_name, str):
            graph_name = default_graph_name
        self.addParameter(
            QgsProcessingParameterString(self.GRAPH_NAME,
                                         self.tr('Graph name'), graph_name,
                                         False, False))

        default_graph_version = Settings.get_selected_graph_version()
        graph_version = ''
        if isinstance(default_graph_version, str):
            graph_version = default_graph_version
        self.addParameter(
            QgsProcessingParameterString(self.GRAPH_VERSION,
                                         self.tr('Graph version'),
                                         graph_version, False, False))

        # We add a vector layer as output
        self.addParameter(
            QgsProcessingParameterFeatureSink(self.OUTPUT_SEGMENTS,
                                              self.tr('Segments'),
                                              QgsProcessing.TypeVectorLine))

        self.addOutput(
            QgsProcessingOutputNumber(self.OUTPUT_SEGMENT_COUNT,
                                      self.tr('Number of segments')))
        self.addOutput(
            QgsProcessingOutputNumber(
                self.OUTPUT_SEGMENT_WITH_GEOMETRY_COUNT,
                self.tr('Number of segments with geometry')))
Example #20
0
    def initAlgorithm(self, config=None):
        self.profiles = ((self.tr('Mercator'), 'mercator'),
                         (self.tr('Geodetic'), 'geodetic'), (self.tr('Raster'),
                                                             'raster'))

        self.methods = ((self.tr('Average'),
                         'average'), (self.tr('Nearest neighbour'), 'near'),
                        (self.tr('Bilinear'), 'bilinear'),
                        (self.tr('Cubic'), 'cubic'), (self.tr('Cubic spline'),
                                                      'cubicspline'),
                        (self.tr('Lanczos windowed sinc'),
                         'lanczos'), (self.tr('Antialias'), 'antialias'))

        self.viewers = ((self.tr('All'), 'all'), (self.tr('GoogleMaps'),
                                                  'google'),
                        (self.tr('OpenLayers'),
                         'openlayers'), (self.tr('Leaflet'),
                                         'leaflet'), (self.tr('None'), 'none'))

        self.addParameter(
            QgsProcessingParameterRasterLayer(self.INPUT,
                                              self.tr('Input layer')))
        self.addParameter(
            QgsProcessingParameterEnum(self.PROFILE,
                                       self.tr('Tile cutting profile'),
                                       options=[i[0] for i in self.profiles],
                                       allowMultiple=False,
                                       defaultValue=0))
        self.addParameter(
            QgsProcessingParameterString(self.ZOOM,
                                         self.tr('Zoom levels to render'),
                                         defaultValue='',
                                         optional=True))
        self.addParameter(
            QgsProcessingParameterEnum(self.VIEWER,
                                       self.tr('Web viewer to generate'),
                                       options=[i[0] for i in self.viewers],
                                       allowMultiple=False,
                                       defaultValue=0))
        self.addParameter(
            QgsProcessingParameterString(self.TITLE,
                                         self.tr('Title of the map'),
                                         optional=True))
        self.addParameter(
            QgsProcessingParameterString(self.COPYRIGHT,
                                         self.tr('Copyright of the map'),
                                         optional=True))

        params = []
        params.append(
            QgsProcessingParameterEnum(self.RESAMPLING,
                                       self.tr('Resampling method'),
                                       options=[i[0] for i in self.methods],
                                       allowMultiple=False,
                                       defaultValue=0))
        params.append(
            QgsProcessingParameterCrs(
                self.SOURCE_CRS,
                self.
                tr('The spatial reference system used for the source input data'
                   ),
                optional=True))
        params.append(
            QgsProcessingParameterNumber(
                self.NODATA,
                self.tr('Transparency value to assign to the input data'),
                type=QgsProcessingParameterNumber.Double,
                defaultValue=0,
                optional=True))
        params.append(
            QgsProcessingParameterString(
                self.URL,
                self.
                tr('URL address where the generated tiles are going to be published'
                   ),
                optional=True))
        params.append(
            QgsProcessingParameterString(
                self.GOOGLE_KEY,
                self.
                tr('Google Maps API key (http://code.google.com/apis/maps/signup.html)'
                   ),
                optional=True))
        params.append(
            QgsProcessingParameterString(
                self.BING_KEY,
                self.tr('Bing Maps API key (https://www.bingmapsportal.com/)'),
                optional=True))
        params.append(
            QgsProcessingParameterBoolean(
                self.RESUME,
                self.tr('Generate only missing files'),
                defaultValue=False))
        params.append(
            QgsProcessingParameterBoolean(
                self.KML,
                self.tr('Generate KML for Google Earth'),
                defaultValue=False))
        params.append(
            QgsProcessingParameterBoolean(
                self.NO_KML,
                self.tr(
                    'Avoid automatic generation of KML files for EPSG:4326'),
                defaultValue=False))
        for param in params:
            param.setFlags(param.flags()
                           | QgsProcessingParameterDefinition.FlagAdvanced)
            self.addParameter(param)

        self.addParameter(
            QgsProcessingParameterFolderDestination(
                self.OUTPUT, self.tr('Output directory')))
Example #21
0
    def initAlgorithm(self, config=None):
        self.DIRECTIONS = OrderedDict([
            (self.tr('Forward direction'),
             QgsVectorLayerDirector.DirectionForward),
            (self.tr('Backward direction'),
             QgsVectorLayerDirector.DirectionBackward),
            (self.tr('Both directions'), QgsVectorLayerDirector.DirectionBoth)
        ])

        self.STRATEGIES = [
            self.tr('Shortest Path (distance optimization)'),
            self.tr('Fastest Path (time optimization)')
        ]

        self.ENTRY_COST_CALCULATION_METHODS = [
            self.tr('Ellipsoidal'),
            self.tr('Planar (only use with projected CRS)')
        ]

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.INPUT, self.tr('Network Layer'),
                [QgsProcessing.TypeVectorLine]))
        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.POINTS, self.tr('Point Layer'),
                [QgsProcessing.TypeVectorPoint]))
        self.addParameter(
            QgsProcessingParameterField(self.ID_FIELD,
                                        self.tr('Unique Point ID Field'),
                                        None,
                                        self.POINTS,
                                        optional=False))
        self.addParameter(
            QgsProcessingParameterEnum(self.STRATEGY,
                                       self.tr('Optimization Criterion'),
                                       self.STRATEGIES,
                                       defaultValue=0))

        params = []
        params.append(
            QgsProcessingParameterEnum(
                self.ENTRY_COST_CALCULATION_METHOD,
                self.tr('Entry Cost calculation method'),
                self.ENTRY_COST_CALCULATION_METHODS,
                defaultValue=0))
        params.append(
            QgsProcessingParameterField(self.DIRECTION_FIELD,
                                        self.tr('Direction field'),
                                        None,
                                        self.INPUT,
                                        optional=True))
        params.append(
            QgsProcessingParameterString(
                self.VALUE_FORWARD,
                self.tr('Value for forward direction'),
                optional=True))
        params.append(
            QgsProcessingParameterString(
                self.VALUE_BACKWARD,
                self.tr('Value for backward direction'),
                optional=True))
        params.append(
            QgsProcessingParameterString(self.VALUE_BOTH,
                                         self.tr('Value for both directions'),
                                         optional=True))
        params.append(
            QgsProcessingParameterEnum(self.DEFAULT_DIRECTION,
                                       self.tr('Default direction'),
                                       list(self.DIRECTIONS.keys()),
                                       defaultValue=2))
        params.append(
            QgsProcessingParameterField(self.SPEED_FIELD,
                                        self.tr('Speed field'),
                                        None,
                                        self.INPUT,
                                        optional=True))
        params.append(
            QgsProcessingParameterNumber(self.DEFAULT_SPEED,
                                         self.tr('Default speed (km/h)'),
                                         QgsProcessingParameterNumber.Double,
                                         5.0, False, 0, 99999999.99))
        params.append(
            QgsProcessingParameterNumber(self.TOLERANCE,
                                         self.tr('Topology tolerance'),
                                         QgsProcessingParameterNumber.Double,
                                         0.0, False, 0, 99999999.99))

        for p in params:
            p.setFlags(p.flags()
                       | QgsProcessingParameterDefinition.FlagAdvanced)
            self.addParameter(p)

        self.addParameter(
            QgsProcessingParameterFeatureSink(self.OUTPUT,
                                              self.tr('Output OD Matrix'),
                                              QgsProcessing.TypeVectorLine),
            True)
 def initAlgorithm(self, config):
     self.addParameter(
         QgsProcessingParameterFeatureSource(
             self.PrmInputLayer, tr('Input point vector layer'),
             [QgsProcessing.TypeVectorPoint]))
     self.addParameter(
         QgsProcessingParameterEnum(self.PrmOutputFormat,
                                    tr('Output format'),
                                    options=[
                                        tr('Coordinates in 2 fields'),
                                        tr('Coordinates in 1 field'),
                                        'GeoJSON', 'WKT', 'MGRS',
                                        'Plus Codes'
                                    ],
                                    defaultValue=0,
                                    optional=True))
     self.addParameter(
         QgsProcessingParameterString(
             self.PrmYFieldName,
             tr('Latitude (Y), GeoJSON, WKT, MGRS, or Plus Codes field name'
                ),
             defaultValue='y',
             optional=True))
     self.addParameter(
         QgsProcessingParameterString(self.PrmXFieldName,
                                      tr('Longitude (X) field name'),
                                      defaultValue='x',
                                      optional=True))
     self.addParameter(
         QgsProcessingParameterEnum(
             self.PrmCoordinateOrder,
             tr('Coordinate order when using 1 field'),
             options=[
                 tr('Lat,Lon (Y,X) - Google map order'),
                 tr('Lon,Lat (X,Y) order')
             ],
             defaultValue=0,
             optional=True))
     self.addParameter(
         QgsProcessingParameterEnum(
             self.PrmCoordinateDelimiter,
             tr('Coordinate delimiter when using 1 field'),
             options=[tr('Comma'),
                      tr('Space'),
                      tr('Tab'),
                      tr('Other')],
             defaultValue=0,
             optional=True))
     self.addParameter(
         QgsProcessingParameterString(
             self.PrmOtherDelimiter,
             tr('Other delimiter when using 1 field'),
             defaultValue='',
             optional=True))
     self.addParameter(
         QgsProcessingParameterEnum(
             self.PrmOutputCRSType,
             tr('Output CRS of coordinates added to a field'),
             options=[
                 tr('WGS 84'),
                 tr('Layer CRS'),
                 tr('Project CRS'),
                 tr('Custom CRS')
             ],
             defaultValue=0,
             optional=True))
     self.addParameter(
         QgsProcessingParameterCrs(
             self.PrmCustomCRS,
             tr('Custom CRS for coordinates added to a field'),
             'EPSG:4326',
             optional=True))
     self.addParameter(
         QgsProcessingParameterEnum(
             self.PrmWgs84NumberFormat,
             tr('Select Decimal or DMS degress for WGS 84 numbers'),
             options=[tr('Decimal degrees'),
                      tr('DMS'),
                      tr('DDMMSS')],
             defaultValue=0,
             optional=True))
     self.addParameter(
         QgsProcessingParameterNumber(
             self.PrmCoordinatePrecision,
             tr('Decimal number precision'),
             type=QgsProcessingParameterNumber.Integer,
             defaultValue=8,
             optional=True,
             minValue=0))
     self.addParameter(
         QgsProcessingParameterNumber(
             self.PrmDMSSecondPrecision,
             tr('DMS second precision'),
             type=QgsProcessingParameterNumber.Integer,
             defaultValue=0,
             optional=True,
             minValue=0))
     self.addParameter(
         QgsProcessingParameterNumber(
             self.PrmPlusCodesLength,
             'Plus Codes length',
             type=QgsProcessingParameterNumber.Integer,
             defaultValue=11,
             optional=False,
             minValue=10,
             maxValue=20))
     self.addParameter(
         QgsProcessingParameterFeatureSink(self.PrmOutputLayer,
                                           'Output layer'))
Example #23
0
    def initAlgorithm(self, config=None):
        self.addParameter(
            QgsProcessingParameterMultipleLayers(self.INPUT,
                                                 self.tr('Input layers'),
                                                 QgsProcessing.TypeRaster))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.PCT,
                self.tr('Grab pseudocolor table from first layer'),
                defaultValue=False))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.SEPARATE,
                self.tr('Place each input file into a separate band'),
                defaultValue=False))

        nodata_param = QgsProcessingParameterNumber(
            self.NODATA_INPUT,
            self.tr('Input pixel value to treat as "nodata"'),
            type=QgsProcessingParameterNumber.Integer,
            defaultValue=None,
            optional=True)
        nodata_param.setFlags(nodata_param.flags()
                              | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(nodata_param)

        nodata_out_param = QgsProcessingParameterNumber(
            self.NODATA_OUTPUT,
            self.tr('Assign specified "nodata" value to output'),
            type=QgsProcessingParameterNumber.Integer,
            defaultValue=None,
            optional=True)
        nodata_out_param.setFlags(
            nodata_out_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(nodata_out_param)

        options_param = QgsProcessingParameterString(
            self.OPTIONS,
            self.tr('Additional creation parameters'),
            defaultValue='',
            optional=True)
        options_param.setFlags(options_param.flags()
                               | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class':
                'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'
            }
        })
        self.addParameter(options_param)

        self.addParameter(
            QgsProcessingParameterEnum(self.DATA_TYPE,
                                       self.tr('Output data type'),
                                       self.TYPES,
                                       allowMultiple=False,
                                       defaultValue=5))

        self.addParameter(
            QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                    self.tr('Merged')))
Example #24
0
 def initAlgorithm(self, config=None):
     self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
                                                           self.tr('Input layer')))
     self.addParameter(QgsProcessingParameterEnum(self.METHOD,
                                                  self.tr('Calculate using'), options=self.calc_methods, defaultValue=0))
     self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Added geom info')))
    def initAlgorithm(self, config=None):
        self.DIRECTIONS = OrderedDict([
            (self.tr('Forward direction'), QgsVectorLayerDirector.DirectionForward),
            (self.tr('Backward direction'), QgsVectorLayerDirector.DirectionBackward),
            (self.tr('Both directions'), QgsVectorLayerDirector.DirectionBoth)])

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

        self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
                                                              self.tr('Vector layer representing network'),
                                                              [QgsProcessing.TypeVectorLine]))
        self.addParameter(QgsProcessingParameterFeatureSource(self.START_POINTS,
                                                              self.tr('Vector layer with start points'),
                                                              [QgsProcessing.TypeVectorPoint]))
        self.addParameter(QgsProcessingParameterEnum(self.STRATEGY,
                                                     self.tr('Path type to calculate'),
                                                     self.STRATEGIES,
                                                     defaultValue=0))
        self.addParameter(QgsProcessingParameterNumber(self.TRAVEL_COST,
                                                       self.tr('Travel cost (distance for "Shortest", time for "Fastest")'),
                                                       QgsProcessingParameterNumber.Double,
                                                       0.0, False, 0, 99999999.99))

        params = []
        params.append(QgsProcessingParameterField(self.DIRECTION_FIELD,
                                                  self.tr('Direction field'),
                                                  None,
                                                  self.INPUT,
                                                  optional=True))
        params.append(QgsProcessingParameterString(self.VALUE_FORWARD,
                                                   self.tr('Value for forward direction'),
                                                   optional=True))
        params.append(QgsProcessingParameterString(self.VALUE_BACKWARD,
                                                   self.tr('Value for backward direction'),
                                                   optional=True))
        params.append(QgsProcessingParameterString(self.VALUE_BOTH,
                                                   self.tr('Value for both directions'),
                                                   optional=True))
        params.append(QgsProcessingParameterEnum(self.DEFAULT_DIRECTION,
                                                 self.tr('Default direction'),
                                                 list(self.DIRECTIONS.keys()),
                                                 defaultValue=2))
        params.append(QgsProcessingParameterField(self.SPEED_FIELD,
                                                  self.tr('Speed field'),
                                                  None,
                                                  self.INPUT,
                                                  optional=True))
        params.append(QgsProcessingParameterNumber(self.DEFAULT_SPEED,
                                                   self.tr('Default speed (km/h)'),
                                                   QgsProcessingParameterNumber.Double,
                                                   5.0, False, 0, 99999999.99))
        params.append(QgsProcessingParameterNumber(self.TOLERANCE,
                                                   self.tr('Topology tolerance'),
                                                   QgsProcessingParameterNumber.Double,
                                                   0.0, False, 0, 99999999.99))

        for p in params:
            p.setFlags(p.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
            self.addParameter(p)

        self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT,
                                                            self.tr('Service area (boundary nodes)'),
                                                            QgsProcessing.TypeVectorPoint))
Example #26
0
    def initAlgorithm(self, config=None):
        self.units = [self.tr("Pixels"), self.tr("Georeferenced units")]

        self.addParameter(
            QgsProcessingParameterFeatureSource(self.INPUT,
                                                self.tr('Input layer')))
        self.addParameter(
            QgsProcessingParameterField(
                self.FIELD,
                self.tr('Field to use for a burn-in value'),
                None,
                self.INPUT,
                QgsProcessingParameterField.Numeric,
                optional=True))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.BURN,
                self.tr('A fixed value to burn'),
                type=QgsProcessingParameterNumber.Double,
                defaultValue=0.0,
                optional=True))
        self.addParameter(
            QgsProcessingParameterEnum(self.UNITS,
                                       self.tr('Output raster size units'),
                                       self.units))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.WIDTH,
                self.tr('Width/Horizontal resolution'),
                type=QgsProcessingParameterNumber.Double,
                minValue=0.0,
                defaultValue=0.0))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.HEIGHT,
                self.tr('Height/Vertical resolution'),
                type=QgsProcessingParameterNumber.Double,
                minValue=0.0,
                defaultValue=0.0))
        self.addParameter(
            QgsProcessingParameterExtent(self.EXTENT,
                                         self.tr('Output extent')))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.NODATA,
                self.tr('Assign a specified nodata value to output bands'),
                type=QgsProcessingParameterNumber.Double,
                defaultValue=0.0,
                optional=True))

        options_param = QgsProcessingParameterString(
            self.OPTIONS,
            self.tr('Additional creation options'),
            defaultValue='',
            optional=True)
        options_param.setFlags(options_param.flags()
                               | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class':
                'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'
            }
        })
        self.addParameter(options_param)

        dataType_param = QgsProcessingParameterEnum(
            self.DATA_TYPE,
            self.tr('Output data type'),
            self.TYPES,
            allowMultiple=False,
            defaultValue=5)
        dataType_param.setFlags(
            dataType_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        init_param = QgsProcessingParameterNumber(
            self.INIT,
            self.tr('Pre-initialize the output image with value'),
            type=QgsProcessingParameterNumber.Double,
            optional=True)
        init_param.setFlags(init_param.flags()
                            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(init_param)

        invert_param = QgsProcessingParameterBoolean(
            self.INVERT, self.tr('Invert rasterization'), defaultValue=False)
        invert_param.setFlags(invert_param.flags()
                              | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(invert_param)

        self.addParameter(
            QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                    self.tr('Rasterized')))
Example #27
0
    def initAlgorithm(self, config=None):
        self.methods = ((self.tr('Nearest neighbour'),
                         'near'), (self.tr('Bilinear'), 'bilinear'),
                        (self.tr('Cubic'), 'cubic'), (self.tr('Cubic spline'),
                                                      'cubicspline'),
                        (self.tr('Lanczos windowed sinc'),
                         'lanczos'), (self.tr('Average'), 'average'),
                        (self.tr('Mode'), 'mode'), (self.tr('Maximum'), 'max'),
                        (self.tr('Minimum'),
                         'min'), (self.tr('Median'),
                                  'med'), (self.tr('First quartile'), 'q1'),
                        (self.tr('Third quartile'), 'q3'))

        self.addParameter(
            QgsProcessingParameterRasterLayer(self.INPUT,
                                              self.tr('Input layer')))
        self.addParameter(
            QgsProcessingParameterCrs(self.SOURCE_CRS,
                                      self.tr('Source CRS'),
                                      optional=True))
        self.addParameter(
            QgsProcessingParameterCrs(self.TARGET_CRS, self.tr('Target CRS'),
                                      'EPSG:4326'))
        self.addParameter(
            QgsProcessingParameterEnum(self.RESAMPLING,
                                       self.tr('Resampling method to use'),
                                       options=[i[0] for i in self.methods],
                                       defaultValue=0))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.NODATA,
                self.tr('Nodata value for output bands'),
                type=QgsProcessingParameterNumber.Double,
                defaultValue=None,
                optional=True))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.TARGET_RESOLUTION,
                self.tr(
                    'Output file resolution in target georeferenced units'),
                type=QgsProcessingParameterNumber.Double,
                minValue=0.0,
                defaultValue=None,
                optional=True))

        options_param = QgsProcessingParameterString(
            self.OPTIONS,
            self.tr('Additional creation options'),
            defaultValue='',
            optional=True)
        options_param.setFlags(options_param.flags()
                               | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class':
                'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'
            }
        })
        self.addParameter(options_param)

        dataType_param = QgsProcessingParameterEnum(
            self.DATA_TYPE,
            self.tr('Output data type'),
            self.TYPES,
            allowMultiple=False,
            defaultValue=0)
        dataType_param.setFlags(
            dataType_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        target_extent_param = QgsProcessingParameterExtent(
            self.TARGET_EXTENT,
            self.tr('Georeferenced extents of output file to be created'),
            optional=True)
        target_extent_param.setFlags(
            target_extent_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(target_extent_param)

        target_extent_crs_param = QgsProcessingParameterCrs(
            self.TARGET_EXTENT_CRS,
            self.tr('CRS of the target raster extent'),
            optional=True)
        target_extent_crs_param.setFlags(
            target_extent_crs_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(target_extent_crs_param)

        multithreading_param = QgsProcessingParameterBoolean(
            self.MULTITHREADING,
            self.tr('Use multithreaded warping implementation'),
            defaultValue=False)
        multithreading_param.setFlags(
            multithreading_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(multithreading_param)

        extra_param = QgsProcessingParameterString(
            self.EXTRA,
            self.tr('Additional command-line parameters'),
            defaultValue=None,
            optional=True)
        extra_param.setFlags(extra_param.flags()
                             | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(extra_param)

        self.addParameter(
            QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                    self.tr('Reprojected')))
Example #28
0
 def initAlgorithm(self, config=None):
     self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
                                                           self.tr('Input layer')))
     self.addParameter(QgsProcessingParameterString(self.SHAPE_ENCODING,
                                                    self.tr('Shape encoding'), "", optional=True))
     self.addParameter(QgsProcessingParameterEnum(self.GTYPE,
                                                  self.tr('Output geometry type'), options=self.GEOMTYPE, defaultValue=0))
     self.addParameter(QgsProcessingParameterCrs(self.A_SRS,
                                                 self.tr('Assign an output CRS'), defaultValue='', optional=False))
     self.addParameter(QgsProcessingParameterCrs(self.T_SRS,
                                                 self.tr('Reproject to this CRS on output '), defaultValue='', optional=True))
     self.addParameter(QgsProcessingParameterCrs(self.S_SRS,
                                                 self.tr('Override source CRS'), defaultValue='', optional=True))
     self.addParameter(QgsProcessingParameterString(self.HOST,
                                                    self.tr('Host'), defaultValue='localhost', optional=True))
     self.addParameter(QgsProcessingParameterString(self.PORT,
                                                    self.tr('Port'), defaultValue='5432', optional=True))
     self.addParameter(QgsProcessingParameterString(self.USER,
                                                    self.tr('Username'), defaultValue='', optional=True))
     self.addParameter(QgsProcessingParameterString(self.DBNAME,
                                                    self.tr('Database name'), defaultValue='', optional=True))
     self.addParameter(QgsProcessingParameterString(self.PASSWORD,
                                                    self.tr('Password'), defaultValue='', optional=True))
     self.addParameter(QgsProcessingParameterString(self.SCHEMA,
                                                    self.tr('Schema name'), defaultValue='public', optional=True))
     self.addParameter(QgsProcessingParameterString(self.TABLE,
                                                    self.tr('Table name, leave blank to use input name'),
                                                    defaultValue='', optional=True))
     self.addParameter(QgsProcessingParameterString(self.PK,
                                                    self.tr('Primary key (new field)'), defaultValue='id', optional=True))
     self.addParameter(QgsProcessingParameterField(self.PRIMARY_KEY,
                                                   self.tr('Primary key (existing field, used if the above option is left empty)'), parentLayerParameterName=self.INPUT, optional=True))
     self.addParameter(QgsProcessingParameterString(self.GEOCOLUMN,
                                                    self.tr('Geometry column name'), defaultValue='geom', optional=True))
     self.addParameter(QgsProcessingParameterEnum(self.DIM,
                                                  self.tr('Vector dimensions'), options=self.DIMLIST, defaultValue=0))
     self.addParameter(QgsProcessingParameterString(self.SIMPLIFY,
                                                    self.tr('Distance tolerance for simplification'),
                                                    defaultValue='', optional=True))
     self.addParameter(QgsProcessingParameterString(self.SEGMENTIZE,
                                                    self.tr('Maximum distance between 2 nodes (densification)'),
                                                    defaultValue='', optional=True))
     self.addParameter(QgsProcessingParameterExtent(self.SPAT,
                                                    self.tr('Select features by extent (defined in input layer CRS)'), optional=True))
     self.addParameter(QgsProcessingParameterBoolean(self.CLIP,
                                                     self.tr('Clip the input layer using the above (rectangle) extent'),
                                                     defaultValue=False))
     self.addParameter(QgsProcessingParameterString(self.WHERE,
                                                    self.tr('Select features using a SQL "WHERE" statement (Ex: column=\'value\')'),
                                                    defaultValue='', optional=True))
     self.addParameter(QgsProcessingParameterString(self.GT,
                                                    self.tr('Group N features per transaction (Default: 20000)'),
                                                    defaultValue='', optional=True))
     self.addParameter(QgsProcessingParameterBoolean(self.OVERWRITE,
                                                     self.tr('Overwrite existing table'), defaultValue=True))
     self.addParameter(QgsProcessingParameterBoolean(self.APPEND,
                                                     self.tr('Append to existing table'), defaultValue=False))
     self.addParameter(QgsProcessingParameterBoolean(self.ADDFIELDS,
                                                     self.tr('Append and add new fields to existing table'), defaultValue=False))
     self.addParameter(QgsProcessingParameterBoolean(self.LAUNDER,
                                                     self.tr('Do not launder columns/table names'), defaultValue=False))
     self.addParameter(QgsProcessingParameterBoolean(self.INDEX,
                                                     self.tr('Do not create spatial index'), defaultValue=False))
     self.addParameter(QgsProcessingParameterBoolean(self.SKIPFAILURES,
                                                     self.tr('Continue after a failure, skipping the failed feature'), defaultValue=False))
     self.addParameter(QgsProcessingParameterBoolean(self.PROMOTETOMULTI,
                                                     self.tr('Promote to Multipart'),
                                                     defaultValue=True))
     self.addParameter(QgsProcessingParameterBoolean(self.PRECISION,
                                                     self.tr('Keep width and precision of input attributes'),
                                                     defaultValue=True))
     self.addParameter(QgsProcessingParameterString(self.OPTIONS,
                                                    self.tr('Additional creation options'), defaultValue='', optional=True))
Example #29
0
    def initAlgorithm(self, config=None):
        self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
                                                              self.tr('Point layer'),
                                                              [QgsProcessing.TypeVectorPoint]))

        z_field_param = QgsProcessingParameterField(self.Z_FIELD,
                                                    self.tr('Z value from field'),
                                                    None,
                                                    self.INPUT,
                                                    QgsProcessingParameterField.Numeric,
                                                    optional=True)
        z_field_param.setFlags(z_field_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(z_field_param)

        self.addParameter(QgsProcessingParameterNumber(self.POWER,
                                                       self.tr('Weighting power'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       minValue=0.0,
                                                       maxValue=100.0,
                                                       defaultValue=2.0))
        self.addParameter(QgsProcessingParameterNumber(self.SMOOTHING,
                                                       self.tr('Smoothing'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       minValue=0.0,
                                                       defaultValue=0.0))
        self.addParameter(QgsProcessingParameterNumber(self.RADIUS_1,
                                                       self.tr('The first radius of search ellipse'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       minValue=0.0,
                                                       defaultValue=0.0))
        self.addParameter(QgsProcessingParameterNumber(self.RADIUS_2,
                                                       self.tr('The second radius of search ellipse'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       minValue=0.0,
                                                       defaultValue=0.0))
        self.addParameter(QgsProcessingParameterNumber(self.ANGLE,
                                                       self.tr('Angle of search ellipse rotation in degrees (counter clockwise)'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       minValue=0.0,
                                                       maxValue=360.0,
                                                       defaultValue=0.0))
        self.addParameter(QgsProcessingParameterNumber(self.MAX_POINTS,
                                                       self.tr('Maximum number of data points to use'),
                                                       type=QgsProcessingParameterNumber.Integer,
                                                       minValue=0,
                                                       defaultValue=0))
        self.addParameter(QgsProcessingParameterNumber(self.MIN_POINTS,
                                                       self.tr('Minimum number of data points to use'),
                                                       type=QgsProcessingParameterNumber.Integer,
                                                       minValue=0,
                                                       defaultValue=0))
        self.addParameter(QgsProcessingParameterNumber(self.NODATA,
                                                       self.tr('NODATA marker to fill empty points'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       defaultValue=0.0))

        options_param = QgsProcessingParameterString(self.OPTIONS,
                                                     self.tr('Additional creation parameters'),
                                                     defaultValue='',
                                                     optional=True)
        options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class': 'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'}})
        self.addParameter(options_param)

        dataType_param = QgsProcessingParameterEnum(self.DATA_TYPE,
                                                    self.tr('Output data type'),
                                                    self.TYPES,
                                                    allowMultiple=False,
                                                    defaultValue=5)
        dataType_param.setFlags(dataType_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                                  self.tr('Interpolated (IDW)')))
Example #30
0
    def initAlgorithm(self, config):
        """
        Here we define the inputs and output of the algorithm, along
        with some other properties.
        """
        # LizSync config file from ini
        ls = lizsyncConfig()

        # INPUTS

        # Central database connection name
        connection_name_central = ls.variable('postgresql:central/name')
        label = tr('PostgreSQL connection to the central database')
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.CONNECTION_NAME_CENTRAL,
                label,
                "postgres",
                defaultValue=connection_name_central,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(
                self.CONNECTION_NAME_CENTRAL,
                label,
                defaultValue=connection_name_central,
                optional=False)
            param.setMetadata({
                'widget_wrapper': {
                    'class':
                    'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'
                }
            })
        tooltip = tr('The PostgreSQL connection to the central database.')
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        # Clone database connection parameters
        connection_name_clone = ls.variable('postgresql:clone/name')
        label = tr('PostgreSQL connection to the clone database')
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.CONNECTION_NAME_CLONE,
                label,
                "postgres",
                defaultValue=connection_name_clone,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(
                self.CONNECTION_NAME_CLONE,
                label,
                defaultValue=connection_name_clone,
                optional=False)
            param.setMetadata({
                'widget_wrapper': {
                    'class':
                    'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'
                }
            })
        tooltip = tr('The PostgreSQL connection to the clone database.')
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        # PostgreSQL binary path (with psql, pg_dump, pg_restore)
        postgresql_binary_path = ls.variable('binaries/postgresql')
        param = QgsProcessingParameterFile(
            self.POSTGRESQL_BINARY_PATH,
            tr('PostgreSQL binary path'),
            defaultValue=postgresql_binary_path,
            behavior=QgsProcessingParameterFile.Folder,
            optional=False)
        param.setFlags(param.flags()
                       | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(param)

        # Recreate clone server id
        param = QgsProcessingParameterBoolean(
            self.RECREATE_CLONE_SERVER_ID,
            tr('Recreate clone server id. Do it only to fully reset the clone ID !'
               ),
            defaultValue=False,
            optional=False)
        param.setFlags(param.flags()
                       | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(param)

        # For Windows, WinSCP binary path
        winscp_binary_path = ls.variable('binaries/winscp')
        if not winscp_binary_path.strip():
            winscp_binary_path = plugin_path('install', 'WinSCP')
        param = QgsProcessingParameterFile(
            self.WINSCP_BINARY_PATH,
            tr('WinSCP binary path'),
            defaultValue=winscp_binary_path,
            behavior=QgsProcessingParameterFile.Folder,
            optional=True)
        param.setFlags(param.flags()
                       | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(param)

        # Clone FTP connection parameters
        # method
        self.CLONE_FTP_PROTOCOLS = ['SFTP', 'FTP']
        param = QgsProcessingParameterEnum(
            self.CLONE_FTP_PROTOCOL,
            tr('Clone (S)FTP protocol'),
            options=self.CLONE_FTP_PROTOCOLS,
            defaultValue=0,
            optional=False,
        )
        self.addParameter(param)

        # host
        clone_ftp_host = ls.variable('ftp:clone/host')
        param = QgsProcessingParameterString(self.CLONE_FTP_HOST,
                                             tr('Clone FTP Server host'),
                                             defaultValue=clone_ftp_host,
                                             optional=False)
        self.addParameter(param)

        # port
        clone_ftp_port = ls.variable('ftp:clone/port')
        if not clone_ftp_port:
            clone_ftp_port = '8022'
        param = QgsProcessingParameterNumber(self.CLONE_FTP_PORT,
                                             tr('Clone FTP Server port'),
                                             defaultValue=clone_ftp_port,
                                             optional=False)
        self.addParameter(param)

        # login
        clone_ftp_login = ls.variable('ftp:clone/user')
        param = QgsProcessingParameterString(self.CLONE_FTP_LOGIN,
                                             tr('Clone FTP Server login'),
                                             defaultValue=clone_ftp_login,
                                             optional=False)
        self.addParameter(param)

        # password
        param = QgsProcessingParameterString(self.CLONE_FTP_PASSWORD,
                                             tr('Clone FTP Server password'),
                                             optional=True)
        self.addParameter(param)

        # remote directory
        clone_ftp_remote_dir = ls.variable('ftp:clone/remote_directory')
        if not clone_ftp_remote_dir:
            clone_ftp_remote_dir = 'storage/downloads/qgis/'
        param = QgsProcessingParameterString(
            self.CLONE_FTP_REMOTE_DIR,
            tr('Clone FTP Server remote directory'),
            defaultValue=clone_ftp_remote_dir,
            optional=False)
        self.addParameter(param)

        # Exclude some directories from sync
        excluded_directories = ls.variable('local/excluded_directories')
        if not excluded_directories:
            excluded_directories = 'data'
        param = QgsProcessingParameterString(
            self.FTP_EXCLUDE_REMOTE_SUBDIRS,
            tr('List of sub-directory to exclude from synchro, separated by commas.'
               ),
            defaultValue=excluded_directories,
            optional=True)
        param.setFlags(param.flags()
                       | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(param)

        # OUTPUTS
        # Add output for message
        self.addOutput(
            QgsProcessingOutputNumber(self.OUTPUT_STATUS, tr('Output status')))
        self.addOutput(
            QgsProcessingOutputString(self.OUTPUT_STRING,
                                      tr('Output message')))
    def initAlgorithm(self, config=None):
        """
        Here we define the inputs and output of the algorithm, along
        with some other properties.
        """

        self.isoconfig = {
            "squaresizes": ['1000', '500', '100'],
            "mapDatabases": {
                "Syss belägenhet": {
                    "NamnRad7_0": "Rutid ",
                    "NamnRad7_1": " m SWEREF99",
                    "FACTTABLE": "Personer",
                    "VALUESET_0": "kSaRutid",
                    "VALUESET_1": "_SWEREF99"
                },
                "Bef belägenhet": {
                    "NamnRad7_0": "Rutid ",
                    "NamnRad7_1": " m SWEREF99",
                    "FACTTABLE": "fBBefolkning",
                    "VALUESET_0": "kBRutid",
                    "VALUESET_1": "_SWEREF99"
                },
                "Flytt belägenhet": {
                    "NamnRad7_0": "Rutid ",
                    "NamnRad7_1": " m SWEREF99",
                    "FACTTABLE": "fFlyttning",
                    "VALUESET_0": "kFRutid",
                    "VALUESET_1": "_SWEREF99"
                },
                "Syss relationsbelägenhet": {
                    "NamnRad7_0": "RelationsRutid ",
                    "NamnRad7_1": " m SWEREF99",
                    "FACTTABLE": "Personer",
                    "VALUESET_0": "kSaRutid",
                    "VALUESET_1": "_SWEREF99"
                },
                "Flytt relationsbelägenhet": {
                    "NamnRad7_0": "Rutid ",
                    "NamnRad7_1": " m SWEREF99 flyttningsrelation",
                    "FACTTABLE": "fFlyttning",
                    "VALUESET_0": "kFRutid",
                    "VALUESET_1": "_SWEREF99"
                }
            }
        }

        # Input file
        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.INPUT, self.tr('Rutlager att skapa recodes från'),
                [QgsProcessing.TypeVectorPolygon]))

        # Rutid field
        self.addParameter(
            QgsProcessingParameterField(self.RUTID, self.tr('RutID-kolumn'),
                                        'Rutid_txt', self.INPUT))

        # Cost_level field
        self.addParameter(
            QgsProcessingParameterField(
                self.COSTLEVEL,
                self.tr('Kolumn som innehåller kategorier för recode'),
                'cost_level', self.INPUT))

        # Rutstorlek options
        #name,description,options,allowMultiple,defaultValue
        self.addParameter(
            QgsProcessingParameterEnum(self.RUTSTORLEK, self.tr('Rutstorlek'),
                                       self.isoconfig["squaresizes"], False,
                                       0))

        # Database options
        self.addParameter(
            QgsProcessingParameterEnum(
                self.DATABAS, self.tr('Typ av databas i Supercross'),
                [k for k in self.isoconfig["mapDatabases"]], False, 0))

        # Add rad 1-6 input
        self.addParameter(
            QgsProcessingParameterString(
                self.RADER,
                self.
                tr('Första raderna i recode-filen (ska normalt inte behöva ändras)'
                   ),
                'HEADER\n	VERSION 2\n	UNICODE\n	ESCAPE_CHAR & ITEM_BY_CODE\nEND HEADER\n',
                True))

        # Optional prefix for rutid.
        self.addParameter(
            QgsProcessingParameterString(
                self.PREFIXRUTID,
                self.
                tr('Prefix för RutID som används i recodefilen (vanligtvis är det länskoden)'
                   ), 20, False, False))

        # Output file destination
        self.addParameter(
            QgsProcessingParameterFileDestination(
                self.OUTPUT, self.tr('Utdatafil'), 'Text file(*.txt)',
                'C:\\Lokalt\\GIS\\Outputfil.txt'))
Example #32
0
    def defineCharacteristicsFromFile(self):
        """
        Create algorithm parameters and outputs from a text file.
        """
        with open(self.descriptionFile) as lines:
            # First line of the file is the Grass algorithm name
            line = lines.readline().strip('\n').strip()
            self.grass7Name = line
            # Second line if the algorithm name in Processing
            line = lines.readline().strip('\n').strip()
            self._name = line
            self._display_name = QCoreApplication.translate("GrassAlgorithm", line)
            if " - " not in self._name:
                self._name = self.grass7Name + " - " + self._name
                self._display_name = self.grass7Name + " - " + self._display_name

            self._name = self._name[:self._name.find(' ')].lower()
            # Read the grass group
            line = lines.readline().strip('\n').strip()
            self._group = QCoreApplication.translate("GrassAlgorithm", line)
            hasRasterOutput = False
            hasRasterInput = False
            hasVectorInput = False
            vectorOutputs = False
            # Then you have parameters/output definition
            line = lines.readline().strip('\n').strip()
            while line != '':
                try:
                    line = line.strip('\n').strip()
                    if line.startswith('Hardcoded'):
                        self.hardcodedStrings.append(line[len('Hardcoded|'):])
                    parameter = getParameterFromString(line)
                    if parameter is not None:
                        self.params.append(parameter)
                        if isinstance(parameter, QgsProcessingParameterVectorLayer):
                            hasVectorInput = True
                        elif isinstance(parameter, QgsProcessingParameterRasterLayer):
                            hasRasterInput = True
                        elif isinstance(parameter, QgsProcessingParameterMultipleLayers):
                            if parameter.layerType() < 3 or parameter.layerType() == 5:
                                hasVectorInput = True
                            elif parameter.layerType() == 3:
                                hasRasterInput = True
                        elif isinstance(parameter, QgsProcessingParameterVectorDestination):
                            vectorOutputs = True
                        elif isinstance(parameter, QgsProcessingParameterRasterDestination):
                            hasRasterOutput = True
                    line = lines.readline().strip('\n').strip()
                except Exception as e:
                    QgsMessageLog.logMessage(self.tr('Could not open GRASS GIS 7 algorithm: {0}\n{1}').format(self.descriptionFile, line), self.tr('Processing'), QgsMessageLog.CRITICAL)
                    raise e

        param = QgsProcessingParameterExtent(
            self.GRASS_REGION_EXTENT_PARAMETER,
            self.tr('GRASS GIS 7 region extent'),
            optional=True
        )
        param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.params.append(param)

        if hasRasterOutput or hasRasterInput:
            # Add a cellsize parameter
            param = QgsProcessingParameterNumber(
                self.GRASS_REGION_CELLSIZE_PARAMETER,
                self.tr('GRASS GIS 7 region cellsize (leave 0 for default)'),
                type=QgsProcessingParameterNumber.Double,
                minValue=0.0, maxValue=sys.float_info.max + 1, defaultValue=0.0
            )
            param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
            self.params.append(param)

        if hasRasterOutput:
            # Add a createopt parameter for format export
            param = QgsProcessingParameterString(
                self.GRASS_RASTER_FORMAT_OPT,
                self.tr('Output Rasters format options (createopt)'),
                multiLine=True, optional=True
            )
            param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
            self.params.append(param)

            # Add a metadata parameter for format export
            param = QgsProcessingParameterString(
                self.GRASS_RASTER_FORMAT_META,
                self.tr('Output Rasters format metadata options (metaopt)'),
                multiLine=True, optional=True
            )
            param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
            self.params.append(param)

        if hasVectorInput:
            param = QgsProcessingParameterNumber(self.GRASS_SNAP_TOLERANCE_PARAMETER,
                                                 self.tr('v.in.ogr snap tolerance (-1 = no snap)'),
                                                 type=QgsProcessingParameterNumber.Double,
                                                 minValue=-1.0, maxValue=sys.float_info.max + 1,
                                                 defaultValue=-1.0)
            param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
            self.params.append(param)
            param = QgsProcessingParameterNumber(self.GRASS_MIN_AREA_PARAMETER,
                                                 self.tr('v.in.ogr min area'),
                                                 type=QgsProcessingParameterNumber.Double,
                                                 minValue=0.0, maxValue=sys.float_info.max + 1,
                                                 defaultValue=0.0001)
            param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
            self.params.append(param)

        if vectorOutputs:
            param = QgsProcessingParameterEnum(self.GRASS_OUTPUT_TYPE_PARAMETER,
                                               self.tr('v.out.ogr output type'),
                                               self.OUTPUT_TYPES)
            param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
            self.params.append(param)
Example #33
0
    def initAlgorithm(self, config=None):
        self.predicates = (('intersects', self.tr('intersects')),
                           ('contains', self.tr('contains')),
                           ('equals', self.tr('equals')), ('touches',
                                                           self.tr('touches')),
                           ('overlaps', self.tr('overlaps')),
                           ('within', self.tr('within')), ('crosses',
                                                           self.tr('crosses')))

        self.reversed_predicates = {
            'intersects': 'intersects',
            'contains': 'within',
            'isEqual': 'isEqual',
            'touches': 'touches',
            'overlaps': 'overlaps',
            'within': 'contains',
            'crosses': 'crosses'
        }

        self.methods = [
            self.tr('Create separate feature for each located feature'),
            self.tr('Take attributes of the first located feature only')
        ]

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.INPUT, self.tr('Input layer'),
                [QgsProcessing.TypeVectorAnyGeometry]))
        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.JOIN, self.tr('Join layer'),
                [QgsProcessing.TypeVectorAnyGeometry]))

        predicate = QgsProcessingParameterEnum(
            self.PREDICATE,
            self.tr('Geometric predicate'),
            options=[p[1] for p in self.predicates],
            allowMultiple=True,
            defaultValue=[0])
        predicate.setMetadata({
            'widget_wrapper': {
                'class': 'processing.gui.wrappers.EnumWidgetWrapper',
                'useCheckBoxes': True,
                'columns': 2
            }
        })
        self.addParameter(predicate)
        self.addParameter(
            QgsProcessingParameterField(
                self.JOIN_FIELDS,
                self.tr('Fields to add (leave empty to use all fields)'),
                parentLayerParameterName=self.JOIN,
                allowMultiple=True,
                optional=True))
        self.addParameter(
            QgsProcessingParameterEnum(self.METHOD, self.tr('Join type'),
                                       self.methods))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.DISCARD_NONMATCHING,
                self.tr('Discard records which could not be joined'),
                defaultValue=False))
        self.addParameter(
            QgsProcessingParameterFeatureSink(self.OUTPUT,
                                              self.tr('Joined layer')))
Example #34
0
    def initAlgorithm(self, config):

        currentPath = getCurrentPath(self)
        FULL_PATH_A01 = buildFullPathName(
            currentPath, nameWithOuputExtension(NAMES_INDEX['IA01'][1]))
        FULL_PATH_A02 = buildFullPathName(
            currentPath, nameWithOuputExtension(NAMES_INDEX['IA02'][1]))
        FULL_PATH_A03 = buildFullPathName(
            currentPath, nameWithOuputExtension(NAMES_INDEX['IA03'][1]))
        FULL_PATH_A04 = buildFullPathName(
            currentPath, nameWithOuputExtension(NAMES_INDEX['IA04'][1]))
        FULL_PATH_A05 = buildFullPathName(
            currentPath, nameWithOuputExtension(NAMES_INDEX['IA05'][1]))
        FULL_PATH_A06 = buildFullPathName(
            currentPath, nameWithOuputExtension(NAMES_INDEX['IA06'][1]))
        FULL_PATH_A07 = buildFullPathName(
            currentPath, nameWithOuputExtension(NAMES_INDEX['IA07'][1]))
        FULL_PATH_A08 = buildFullPathName(
            currentPath, nameWithOuputExtension(NAMES_INDEX['IA08'][1]))
        FULL_PATH_A09 = buildFullPathName(
            currentPath, nameWithOuputExtension(NAMES_INDEX['IA09'][1]))
        FULL_PATH_A10 = buildFullPathName(
            currentPath, nameWithOuputExtension(NAMES_INDEX['IA10'][1]))
        FULL_PATH_A11 = buildFullPathName(
            currentPath, nameWithOuputExtension(NAMES_INDEX['IA11'][1]))
        FULL_PATH_A12 = buildFullPathName(
            currentPath, nameWithOuputExtension(NAMES_INDEX['IA12'][1]))
        FULL_PATH_A13 = buildFullPathName(
            currentPath, nameWithOuputExtension(NAMES_INDEX['IA13'][1]))

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.STUDY_AREA_GRID,
                self.tr(TEXT_GRID_INPUT),
                [QgsProcessing.TypeVectorPolygon],
                optional=OPTIONAL_GRID_INPUT,
            ))

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.BLOCKS,
                self.tr('Manzanas'), [QgsProcessing.TypeVectorPolygon],
                optional=True,
                defaultValue=""))

        self.addParameter(
            QgsProcessingParameterField(self.FIELD_POPULATION,
                                        self.tr('Población'),
                                        'poblacion',
                                        'BLOCKS',
                                        optional=True))

        self.addParameter(
            QgsProcessingParameterField(self.FIELD_HOUSING,
                                        self.tr('Viviendas'),
                                        'viviendas',
                                        'BLOCKS',
                                        optional=True))

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.CADASTRE,
                self.tr('Catastro'), [QgsProcessing.TypeVectorPolygon],
                optional=True,
                defaultValue=""))

        self.addParameter(
            QgsProcessingParameterField(self.CONSTRUCTION_AREA,
                                        self.tr('Area de construcción'),
                                        'Area Cons',
                                        'CADASTRE',
                                        optional=True))

        self.addParameter(
            QgsProcessingParameterField(
                self.FLOORS,
                self.tr('Pisos de construcción catastro'),
                'Pisos cons',
                'CADASTRE',
                optional=True))

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.BLOCKS_LAST,
                self.tr('Manzanas en el último año'),
                [QgsProcessing.TypeVectorPolygon],
                optional=True,
                defaultValue=""))

        self.addParameter(
            QgsProcessingParameterField(self.FIELD_POPULATION_LAST,
                                        self.tr('Población en el último año'),
                                        'poblacion',
                                        'BLOCKS_LAST',
                                        optional=True))

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.BLOCKS_BEGIN,
                self.tr('Manzanas en el año inicial'),
                [QgsProcessing.TypeVectorPolygon],
                optional=True,
                defaultValue=""))

        self.addParameter(
            QgsProcessingParameterField(self.FIELD_POPULATION_BEGIN,
                                        self.tr('Población en el último año'),
                                        'poblacion',
                                        'BLOCKS_BEGIN',
                                        optional=True))

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.BUILT_LAST,
                self.tr('Área edificada en el último año'),
                [QgsProcessing.TypeVectorPolygon],
                optional=True,
                defaultValue=""))

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.BUILT_BEGIN,
                self.tr('Área edificada en el año inicial'),
                [QgsProcessing.TypeVectorPolygon],
                optional=True,
                defaultValue=""))

        self.addParameter(
            QgsProcessingParameterNumber(
                self.YEARS, self.tr('Años entre el inicial y el final'),
                QgsProcessingParameterNumber.Integer, 10, False, 1, 99999999))

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.EMPTY_PROPERTIES,
                self.tr('Predios vacíos'),
                [QgsProcessing.TypeVectorAnyGeometry],
                optional=True,
                defaultValue=""))

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.EDIFICACIONES,
                self.tr('Edificaciones'), [QgsProcessing.TypeVectorPolygon],
                optional=True,
                defaultValue=""))

        self.addParameter(
            QgsProcessingParameterField(
                self.FLOORS_EDIFICACIONES,
                self.tr('Pisos de construcción edificaciones'),
                'Pisos cons',
                'EDIFICACIONES',
                optional=True))

        self.addParameter(
            QgsProcessingParameterFeatureSource(self.ROADS,
                                                self.tr('Red vial'),
                                                [QgsProcessing.TypeVectorLine],
                                                optional=True,
                                                defaultValue=''))

        self.addParameter(
            QgsProcessingParameterEnum(self.DISTANCE_OPTIONS,
                                       self.tr('Tipo de distancia'),
                                       options=['ISOCRONA', 'RADIAL'],
                                       allowMultiple=False,
                                       defaultValue=1))

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.EDUCATION,
                self.tr('Educación'), [QgsProcessing.TypeVectorPoint],
                optional=True,
                defaultValue=""))

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.HEALTH,
                self.tr('Salud'), [QgsProcessing.TypeVectorPoint],
                optional=True,
                defaultValue=""))

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.APPROVAL,
                self.tr('Aprovisionamiento'), [QgsProcessing.TypeVectorPoint],
                optional=True,
                defaultValue=""))

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.SPORTS,
                self.tr('Deportivos recreativos'),
                [QgsProcessing.TypeVectorPoint],
                optional=True,
                defaultValue=""))

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.ADMIN_PUBLIC,
                self.tr('Gestión Pública'), [QgsProcessing.TypeVectorPoint],
                optional=True,
                defaultValue=""))

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.EQUIPMENT_PUBLIC_SPACE,
                self.tr('Espacios públicos abiertos'),
                [QgsProcessing.TypeVectorAnyGeometry],
                optional=True,
                defaultValue=""))

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.SHOP,
                self.tr('Tiendas de abarrotes, despensas, minimercado'),
                [QgsProcessing.TypeVectorPoint], '', True))

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.PHARMACY, self.tr('Farmacias y droguerías'),
                [QgsProcessing.TypeVectorPoint], '', True))

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.STATIONERY, self.tr('Papelerías y bazares'),
                [QgsProcessing.TypeVectorPoint], '', True))

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.BAKERY, self.tr('Panaderías, heladería y pastelería'),
                [QgsProcessing.TypeVectorPoint], '', True))
        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.GAS,
                self.tr('Depósitos de distribución de cilindros de gas'),
                [QgsProcessing.TypeVectorPoint], '', True))

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.TERTIARYUSES,
                self.tr('Uos terciarios (comercio, servicios u oficinas)'),
                [QgsProcessing.TypeVectorPoint],
                optional=True,
                defaultValue=""))

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.TERTIARYUSES_ACTIVITIES,
                self.tr('Equipamientos de actividades'),
                [QgsProcessing.TypeVectorPoint],
                optional=True,
                defaultValue=""))

        self.addParameter(
            QgsProcessingParameterField(self.FIELD_ACTIVITIES,
                                        self.tr('Actividades'),
                                        'categoria',
                                        'TERTIARYUSES_ACTIVITIES',
                                        optional=True))

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.ROADS_SINTAXIS,
                self.tr('Vías SINTAXIS ESPACIAL'),
                [QgsProcessing.TypeVectorLine],
                optional=True,
                defaultValue=""))

        # self.addParameter(
        #     QgsProcessingParameterField(
        #         self.FIELD_SINTAXIS,
        #         self.tr('Valor'),
        #         'NACH_slen', 'ROADS_SINTAXIS',
        #         optional = True
        #     )
        # )

        # ---------------------OUTPUTS---------------------------------
        self.addParameter(
            QgsProcessingParameterFeatureSink(
                self.OUTPUT_A01, self.tr('A01 Densidad neta de habitantes'),
                QgsProcessing.TypeVectorAnyGeometry, str(FULL_PATH_A01)))

        self.addParameter(
            QgsProcessingParameterFeatureSink(
                self.OUTPUT_A02, self.tr('A02 Densidad neta de viviendas'),
                QgsProcessing.TypeVectorAnyGeometry, str(FULL_PATH_A02)))

        self.addParameter(
            QgsProcessingParameterFeatureSink(
                self.OUTPUT_A03, self.tr('A03 Compacidad absoluta'),
                QgsProcessing.TypeVectorAnyGeometry, str(FULL_PATH_A03)))

        self.addParameter(
            QgsProcessingParameterFeatureSink(
                self.OUTPUT_A04,
                self.tr('A04 Eficiencia en el uso del territorio'),
                QgsProcessing.TypeVectorAnyGeometry, str(FULL_PATH_A04)))

        self.addParameter(
            QgsProcessingParameterFeatureSink(
                self.OUTPUT_A05, self.tr('A05 Área de predios vacíos'),
                QgsProcessing.TypeVectorAnyGeometry, str(FULL_PATH_A05)))

        self.addParameter(
            QgsProcessingParameterFeatureSink(
                self.OUTPUT_A06, self.tr('A06 Proporción de la calle'),
                QgsProcessing.TypeVectorAnyGeometry, str(FULL_PATH_A06)))

        self.addParameter(
            QgsProcessingParameterFeatureSink(
                self.OUTPUT_A07,
                self.tr('A07 Proximidad a servicios urbanos básicos'),
                QgsProcessing.TypeVectorAnyGeometry, str(FULL_PATH_A07)))

        self.addParameter(
            QgsProcessingParameterFeatureSink(
                self.OUTPUT_A08,
                self.tr('A08 Proximidad al espacio público abierto'),
                QgsProcessing.TypeVectorAnyGeometry, str(FULL_PATH_A08)))

        self.addParameter(
            QgsProcessingParameterFeatureSink(
                self.OUTPUT_A09,
                self.tr('A09 Cobertura de actividades comerciales cotinianas'),
                QgsProcessing.TypeVectorAnyGeometry, str(FULL_PATH_A09)))

        self.addParameter(
            QgsProcessingParameterFeatureSink(
                self.OUTPUT_A10,
                self.tr('A10 Relación entre actividad y residencia'),
                QgsProcessing.TypeVectorAnyGeometry, str(FULL_PATH_A10)))

        self.addParameter(
            QgsProcessingParameterFeatureSink(
                self.OUTPUT_A11, self.tr('A11 Complejidad urbana'),
                QgsProcessing.TypeVectorAnyGeometry, str(FULL_PATH_A11)))

        self.addParameter(
            QgsProcessingParameterFeatureSink(
                self.OUTPUT_A12,
                self.tr('A12 Densidad de intersecciones peatonales'),
                QgsProcessing.TypeVectorAnyGeometry, str(FULL_PATH_A12)))

        self.addParameter(
            QgsProcessingParameterFeatureSink(
                self.OUTPUT_A13, self.tr('A13 Accesibilidad al tejido'),
                QgsProcessing.TypeVectorAnyGeometry, str(FULL_PATH_A13)))
Example #35
0
    def initAlgorithm(self, config=None):
        self.methods = (
            (self.tr('Nearest neighbour'), 'near'),
            (self.tr('Bilinear'), 'bilinear'),
            (self.tr('Cubic'), 'cubic'),
            (self.tr('Cubic spline'), 'cubicspline'),
            (self.tr('Lanczos windowed sinc'), 'lanczos'),
        )

        self.addParameter(
            QgsProcessingParameterMultipleLayers(self.INPUT,
                                                 self.tr('Input files'),
                                                 QgsProcessing.TypeRaster))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.TILE_SIZE_X,
                self.tr('Tile width'),
                type=QgsProcessingParameterNumber.Integer,
                minValue=0,
                defaultValue=256))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.TILE_SIZE_Y,
                self.tr('Tile height'),
                type=QgsProcessingParameterNumber.Integer,
                minValue=0,
                defaultValue=256))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.OVERLAP,
                self.tr('Overlap in pixels between consecutive tiles'),
                type=QgsProcessingParameterNumber.Integer,
                minValue=0,
                defaultValue=0))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.LEVELS,
                self.tr('Number of pyramids levels to build'),
                type=QgsProcessingParameterNumber.Integer,
                minValue=0,
                defaultValue=1))

        params = []
        params.append(
            QgsProcessingParameterCrs(
                self.SOURCE_CRS,
                self.tr('Source coordinate reference system'),
                optional=True))
        params.append(
            QgsProcessingParameterEnum(self.RESAMPLING,
                                       self.tr('Resampling method'),
                                       options=[i[0] for i in self.methods],
                                       allowMultiple=False,
                                       defaultValue=0))
        params.append(
            QgsProcessingParameterString(
                self.DELIMITER,
                self.tr('Column delimiter used in the CSV file'),
                defaultValue=';',
                optional=True))

        options_param = QgsProcessingParameterString(
            self.OPTIONS,
            self.tr('Additional creation options'),
            defaultValue='',
            optional=True)
        options_param.setMetadata({
            'widget_wrapper': {
                'class':
                'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'
            }
        })
        params.append(options_param)

        params.append(
            QgsProcessingParameterEnum(self.DATA_TYPE,
                                       self.tr('Output data type'),
                                       self.TYPES,
                                       allowMultiple=False,
                                       defaultValue=5))

        params.append(
            QgsProcessingParameterBoolean(self.ONLY_PYRAMIDS,
                                          self.tr('Build only the pyramids'),
                                          defaultValue=False))
        params.append(
            QgsProcessingParameterBoolean(
                self.DIR_FOR_ROW,
                self.tr('Use separate directory for each tiles row'),
                defaultValue=False))

        for param in params:
            param.setFlags(param.flags()
                           | QgsProcessingParameterDefinition.FlagAdvanced)
            self.addParameter(param)

        self.addParameter(
            QgsProcessingParameterFolderDestination(
                self.OUTPUT, self.tr('Output directory')))

        output_csv_param = QgsProcessingParameterFileDestination(
            self.OUTPUT_CSV,
            self.tr(
                'CSV file containing the tile(s) georeferencing information'),
            'CSV files (*.csv)',
            optional=True)
        output_csv_param.setCreateByDefault(False)
        self.addParameter(output_csv_param)
Example #36
0
    def initAlgorithm(self, config=None):
        self.distanceUnits = ((self.tr('Georeferenced coordinates'), 'GEO'),
                              (self.tr('Pixel coordinates'), 'PIXEL'))

        self.addParameter(
            QgsProcessingParameterRasterLayer(self.INPUT,
                                              self.tr('Input layer')))
        self.addParameter(
            QgsProcessingParameterBand(self.BAND,
                                       self.tr('Band number'),
                                       parentLayerParameterName=self.INPUT))
        self.addParameter(
            QgsProcessingParameterString(
                self.VALUES,
                self.
                tr('A list of pixel values in the source image to be considered target pixels'
                   ),
                optional=True))
        self.addParameter(
            QgsProcessingParameterEnum(
                self.UNITS,
                self.tr('Distance units'),
                options=[i[0] for i in self.distanceUnits],
                allowMultiple=False,
                defaultValue=1))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.MAX_DISTANCE,
                self.tr('The maximum distance to be generated'),
                type=QgsProcessingParameterNumber.Double,
                minValue=0.0,
                defaultValue=0.0,
                optional=True))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.REPLACE,
                self.
                tr('Value to be applied to all pixels that are within the -maxdist of target pixels'
                   ),
                type=QgsProcessingParameterNumber.Double,
                defaultValue=0.0,
                optional=True))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.NODATA,
                self.
                tr('Nodata value to use for the destination proximity raster'),
                type=QgsProcessingParameterNumber.Double,
                defaultValue=0.0,
                optional=True))

        options_param = QgsProcessingParameterString(
            self.OPTIONS,
            self.tr('Additional creation options'),
            defaultValue='',
            optional=True)
        options_param.setFlags(options_param.flags()
                               | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class':
                'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'
            }
        })
        self.addParameter(options_param)

        self.addParameter(
            QgsProcessingParameterEnum(self.DATA_TYPE,
                                       self.tr('Output data type'),
                                       self.TYPES,
                                       allowMultiple=False,
                                       defaultValue=5))

        self.addParameter(
            QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                    self.tr('Proximity map')))