def initAlgorithm(self, config):
        parameter = QgsProcessingParameterString(
            self.LISTE_CODE_INSEE,
            'Liste des code INSEE à télécharger',
            # defaultValue='25047,05046'
        )
        self.set_tooltip_parameter(parameter, 'séparés par ","')
        self.addParameter(parameter)

        parameter = QgsProcessingParameterString(
            self.FILTRE,
            'Filtre sur les feuilles',
            # defaultValue='050170000C03,AB',
            optional=True,
        )
        self.set_tooltip_parameter(
            parameter,
            'séparés par ",", peut-être "050170000C03,AB" qui téléchargent toutes les feuilles AB et '
            '050170000C03')
        self.addParameter(parameter)

        parameter = QgsProcessingParameterFolderDestination(
            self.DOSSIER, 'Dossier de destination')
        self.set_tooltip_parameter(
            parameter, 'Dossier de destination pour les fichiers Edigeo')
        self.addParameter(parameter, createOutput=True)

        parameter = QgsProcessingParameterString(
            self.DATE,
            'Date, disponible sur le site cadastre.data.gouv.fr (exemple "2021-02-01")',
            defaultValue='latest',
        )
        self.set_tooltip_parameter(parameter, 'Par défaut "latest"')
        self.addParameter(parameter)

        parameter = QgsProcessingParameterString(
            self.URL_TEMPLATE,
            'URL modèle, avec {date}, {departement}, {commune}',
            defaultValue=self.url(),
        )
        self.set_tooltip_parameter(parameter,
                                   'À ne changer que si l\'URL change')
        parameter.setFlags(parameter.flags()
                           | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(parameter)

        self.addOutput(
            QgsProcessingOutputNumber(self.NB_COMMUNES, 'Nombre de communes'))
        self.addOutput(
            QgsProcessingOutputNumber(self.NB_FEUILLES, 'Nombre de feuilles'))
        self.addOutput(
            QgsProcessingOutputString(self.DEPARTEMENTS,
                                      'Départements, séparés par ","'))
예제 #2
0
    def initAlgorithm(self, config):
        self.addParameter(
            QgsProcessingParameterString(self.ORIGINAL, self.tr('Original string - use {0}, {1}, {2}, ... to be replaced by inputs'), multiLine=True)
        )

        for i in self._RANGE:
            self.addParameter(
                QgsProcessingParameterString(self.VALUES[i], self.tr('Replace value {}').format(i), optional=True)
            )
        self.addOutput(
            QgsProcessingOutputString(self.OUTPUT, self.tr('Output string'))
        )
    def initAlgorithm(self, config={}):
        """ Virtual override

            see https://qgis.org/api/classQgsProcessingAlgorithm.html
        """
        self.map_uri = config.get('map_uri', self.map_uri)
        self.addParameter(
            QgsProcessingParameterString(self.INPUT,
                                         'Input string',
                                         defaultValue=self.map_uri))

        self.addOutput(QgsProcessingOutputString(self.OUTPUT, "Output"))
예제 #4
0
    def initAlgorithm(self, config=None):
        """ Virtual override

            see https://qgis.org/api/classQgsProcessingAlgorithm.html
        """
        self.addParameter(
            QgsProcessingParameterEnum(self.INPUT,
                                       'Values',
                                       optional=True,
                                       defaultValue=1,
                                       options=self.IN_OPTIONS))
        self.addOutput(QgsProcessingOutputString(self.OUTPUT, "Output"))
예제 #5
0
    def initAlgorithm(self, config=None):
        self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
                                                              self.tr('Input layer'), types=[QgsProcessing.TypeVector]))
        self.addParameter(QgsProcessingParameterField(self.FIELDS,
                                                      self.tr('Target field(s)'),
                                                      parentLayerParameterName=self.INPUT, type=QgsProcessingParameterField.Any, allowMultiple=True))

        self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Unique values'), optional=True, defaultValue=''))

        self.addParameter(QgsProcessingParameterFileDestination(self.OUTPUT_HTML_FILE, self.tr('HTML report'), self.tr('HTML files (*.html)'), None, True))
        self.addOutput(QgsProcessingOutputNumber(self.TOTAL_VALUES, self.tr('Total unique values')))
        self.addOutput(QgsProcessingOutputString(self.UNIQUE_VALUES, self.tr('Unique values')))
    def initAlgorithm(self, config):
        # LizSync config file from ini
        ls = lizsyncConfig()
        connection_name = ls.variable('postgresql:central/name')

        label = tr('PostgreSQL connection to the central database')
        tooltip = tr('The PostgreSQL connection to the central database.')
        tooltip += tr(
            ' You need to have the right to create a new schema in this database,'
            ' as a schema lizsync will be created and filled with the needed tables and functions'
        )
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.CONNECTION_NAME,
                label,
                "postgres",
                defaultValue=connection_name,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(
                self.CONNECTION_NAME,
                label,
                defaultValue=connection_name,
                optional=False,
            )
            param.setMetadata({
                "widget_wrapper": {
                    "class":
                    "processing.gui.wrappers_postgis.ConnectionWidgetWrapper"
                }
            })
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        param = QgsProcessingParameterBoolean(
            self.OVERRIDE,
            tr("Erase the schema {} ?").format(SCHEMA),
            defaultValue=False,
        )
        tooltip = tr("** Be careful ** This will remove data in the schema !")
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        self.addOutput(
            QgsProcessingOutputString(self.DATABASE_VERSION,
                                      tr("Database version")))
예제 #7
0
파일: outputs.py 프로젝트: iqnaul/QGIS
def getOutputFromString(s):
    try:
        if "|" in s and s.startswith("Output"):
            tokens = s.split("|")
            params = [t if str(t) != "None" else None for t in tokens[1:]]
            clazz = getattr(sys.modules[__name__], tokens[0])
            return clazz(*params)
        else:
            tokens = s.split("=")
            if not tokens[1].lower()[:len('output')] == 'output':
                return None

            name = tokens[0]
            description = tokens[0]

            token = tokens[1].strip()[len('output') + 1:]
            out = None

            if token.lower().strip().startswith('outputraster'):
                out = QgsProcessingOutputRasterLayer(name, description)
            elif token.lower().strip() == 'outputvector':
                out = QgsProcessingOutputVectorLayer(name, description)
            elif token.lower().strip() == 'outputlayer':
                out = QgsProcessingOutputMapLayer(name, description)
            elif token.lower().strip() == 'outputmultilayers':
                out = QgsProcessingOutputMultipleLayers(name, description)
#            elif token.lower().strip() == 'vector point':
#                out = OutputVector(datatype=[dataobjects.TYPE_VECTOR_POINT])
#            elif token.lower().strip() == 'vector line':
#                out = OutputVector(datatype=[OutputVector.TYPE_VECTOR_LINE])
#            elif token.lower().strip() == 'vector polygon':
#                out = OutputVector(datatype=[OutputVector.TYPE_VECTOR_POLYGON])
#            elif token.lower().strip().startswith('table'):
#                out = OutputTable()
            elif token.lower().strip().startswith('outputhtml'):
                out = QgsProcessingOutputHtml(name, description)
#            elif token.lower().strip().startswith('file'):
#                out = OutputFile()
#                ext = token.strip()[len('file') + 1:]
#                if ext:
#                    out.ext = ext
            elif token.lower().strip().startswith('outputfolder'):
                out = QgsProcessingOutputFolder(name, description)
            elif token.lower().strip().startswith('outputnumber'):
                out = QgsProcessingOutputNumber(name, description)
            elif token.lower().strip().startswith('outputstring'):
                out = QgsProcessingOutputString(name, description)
#            elif token.lower().strip().startswith('extent'):
#                out = OutputExtent()

            return out
    except:
        return None
    def initAlgorithm(self, config):
        label = tr("Connexion PostgreSQL vers la base de données")
        tooltip = tr("Base de données de destination")
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.DATABASE,
                label,
                "postgres",
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(self.DATABASE, label)
            param.setMetadata(
                {
                    "widget_wrapper": {
                        "class": "processing.gui.wrappers_postgis.ConnectionWidgetWrapper"
                    }
                }
            )
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        label = tr("Schéma")
        tooltip = 'Nom du schéma pour chercher les couches'
        default = 'veloroutes'
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterDatabaseSchema(
                self.SCHEMA,
                label,
                self.DATABASE,
                defaultValue=default,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(self.SCHEMA, label, default, False, True)
            param.setMetadata(
                {
                    "widget_wrapper": {
                        "class": "processing.gui.wrappers_postgis.SchemaWidgetWrapper",
                        "connection_param": self.DATABASE,
                    }
                }
            )
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        # OUTPUTS
        output = QgsProcessingOutputString(self.OUTPUT_MSG, tr("Message de sortie"))
        output.tooltip_3liz = output.description()
        self.addOutput(output)

        output = QgsProcessingOutputMultipleLayers(self.OUTPUT, tr("Couches dont le style a été modifié"))
        output.tooltip_3liz = 'Les différentes couches de l\'extension véloroutes et voies vertes'
        self.addOutput(output)
    def initAlgorithm(self, config=None):
        """
        Definition of inputs and outputs of the algorithm, along with some other properties.
        """

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

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

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

        if self.settings.is_hd_enabled():
            self.addParameter(
                QgsProcessingParameterBoolean(self.HD_WAYSEGMENTS,
                                              self.tr('HD Waysegments'), False,
                                              True))

        self.addParameter(
            QgsProcessingParameterBoolean(self.KEEP_METADATA,
                                          self.tr('Keep metadata'), True,
                                          True))

        self.addOutput(
            QgsProcessingOutputString(self.OUTPUT_STATE, self.tr('State')))
예제 #10
0
    def initAlgorithm(self, config):
        # LizSync config file from ini
        ls = lizsyncConfig()
        connection_name = ls.variable('postgresql:central/name')

        label = tr("Connection to the PostgreSQL database")
        tooltip = tr(
            "The database where the schema '{}' is installed.").format(SCHEMA)
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.CONNECTION_NAME,
                label,
                "postgres",
                defaultValue=connection_name,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(
                self.CONNECTION_NAME,
                label,
                defaultValue=connection_name,
                optional=False,
            )
            param.setMetadata({
                "widget_wrapper": {
                    "class":
                    "processing.gui.wrappers_postgis.ConnectionWidgetWrapper"
                }
            })
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        param = QgsProcessingParameterBoolean(
            self.RUN_MIGRATIONS,
            tr("Use this checkbox to upgrade."),
            defaultValue=False,
        )
        tooltip = tr(
            "For security reason, we ask that you explicitly use this checkbox."
        )
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        self.addOutput(
            QgsProcessingOutputString(self.DATABASE_VERSION,
                                      tr("Database version")))
예제 #11
0
    def initAlgorithm(self, config):
        connections, _ = connections_list()
        if connections:
            connection_name = connections[0]
        else:
            connection_name = ''

        label = tr("Connection to the PostgreSQL database")
        tooltip = tr("The database where the schema '{}' will be installed.").format(SCHEMA)
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.CONNECTION_NAME,
                label,
                "postgres",
                defaultValue=connection_name,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(
                self.CONNECTION_NAME,
                label,
                defaultValue=connection_name,
                optional=False,
            )
            param.setMetadata(
                {
                    "widget_wrapper": {
                        "class": "processing.gui.wrappers_postgis.ConnectionWidgetWrapper"
                    }
                }
            )
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        param = QgsProcessingParameterBoolean(
            self.OVERRIDE,
            tr("Erase the schema {} ?").format(SCHEMA),
            defaultValue=False,
        )
        tooltip = tr("** Be careful ** This will remove data in the schema !")
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        self.addOutput(
            QgsProcessingOutputString(self.DATABASE_VERSION, tr("Database version"))
        )
    def initAlgorithm(self, config):
        connection_name = QgsExpressionContextUtils.globalScope().variable(
            "veloroutes_connection_name")
        label = tr("Connexion PostgreSQL vers la base de données")
        tooltip = 'Nom de la connexion dans QGIS pour se connecter à la base de données'
        if Qgis.QGIS_VERSION_INT >= 31400:
            param = QgsProcessingParameterProviderConnection(
                self.CONNECTION_NAME,
                label,
                "postgres",
                defaultValue=connection_name,
                optional=False,
            )
        else:
            param = QgsProcessingParameterString(
                self.CONNECTION_NAME,
                label,
                defaultValue=connection_name,
                optional=False,
            )
            param.setMetadata({
                "widget_wrapper": {
                    "class":
                    "processing.gui.wrappers_postgis.ConnectionWidgetWrapper"
                }
            })
        if Qgis.QGIS_VERSION_INT >= 31600:
            param.setHelp(tooltip)
        else:
            param.tooltip_3liz = tooltip
        self.addParameter(param)

        self.addParameter(
            QgsProcessingParameterBoolean(
                self.OVERRIDE,
                tr("Écraser le schéma {} ? ** ATTENTION ** "
                   "Cela supprimera toutes les données !").format(SCHEMA),
                defaultValue=False,
                optional=False,
            ))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.ADD_TEST_DATA,
                tr("Ajouter des données de test ?"),
                defaultValue=False,
                optional=False,
            ))

        self.addOutput(
            QgsProcessingOutputString(self.DATABASE_VERSION,
                                      "Version de la base de données"))
    def initAlgorithm(self, config):
        """
        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
        # geometry.
        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.POLYLAYER, self.tr('Polygon layer'),
                [QgsProcessing.TypeVectorPolygon]))

        # 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(
            QgsProcessingParameterField(self.CATEGORYFIELD,
                                        self.tr('Category layer'), None,
                                        self.POLYLAYER,
                                        QgsProcessingParameterField.String))

        # add point layer Input/Output
        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.POINTLAYER, self.tr('Point layer'),
                [QgsProcessing.TypeVectorPoint]))

        self.addParameter(
            QgsProcessingParameterField(self.SPECIESFIELD,
                                        self.tr('Species fields'), None,
                                        self.POINTLAYER,
                                        QgsProcessingParameterField.String))

        self.addParameter(
            QgsProcessingParameterBoolean(
                self.DETAILED,
                self.tr('Include raw data'),
                True,
            ))

        self.addParameter(
            QgsProcessingParameterFileDestination(
                self.SUMMARY_HTML,
                self.tr('Output HTML File'),
                'HTML Files *.html',
            ))

        self.addOutput(
            QgsProcessingOutputString(self.SUMMARY_DICTIONARY,
                                      self.tr("Results (string)")))
예제 #14
0
    def initAlgorithm(self, config):
        # INPUTS
        # Source layer
        self.addParameter(
            QgsProcessingParameterVectorLayer(self.SOURCELAYER,
                                              tr('Source data layer'),
                                              optional=False,
                                              types=[QgsProcessing.TypeVector
                                                     ]))
        for k, v in self.DATE_FIELDS.items():
            # Date field
            self.addParameter(
                QgsProcessingParameterField(
                    v['field'],
                    tr(k) + ' ' + tr('date and time field. ISO Format'),
                    optional=True,
                    parentLayerParameterName=self.SOURCELAYER))
            # Manual date field
            self.addParameter(
                QgsProcessingParameterString(
                    v['manual'],
                    tr(k) + ' ' +
                    tr('manual date or timestamp, (2019-01-06 or 2019-01-06 22:59:50) Use when the data refers to only one date or time'
                       ),
                    optional=True))

        # Spatial object id field
        self.addParameter(
            QgsProcessingParameterField(
                self.FIELD_SPATIAL_OBJECT,
                tr('Field containing the spatial object id'),
                optional=False,
                parentLayerParameterName=self.SOURCELAYER))

        # Parse new parameters
        project = QgsProject.instance()
        new_params = self.getAdditionnalParameters(project)
        if new_params:
            for param in new_params:
                self.addParameter(param['widget'](
                    param['name'],
                    param['label'],
                    optional=param['optional'],
                    parentLayerParameterName=param['parentLayerParameterName'],
                    type=param['type']))

        # OUTPUTS
        # Add output for message
        self.addOutput(
            QgsProcessingOutputString(self.OUTPUT_STRING,
                                      tr('Output message')))
예제 #15
0
    def initAlgorithm(self, config=None):
        self.addParameter(
            QgsProcessingParameterString(self.QUERY,
                                         tr('Query'),
                                         optional=False,
                                         multiLine=True))

        self.addParameter(
            QgsProcessingParameterExtent(
                self.EXTENT,
                tr('Extent, if "{{bbox}}" in the query'),
                optional=True))

        server = get_setting('defaultOAPI',
                             OVERPASS_SERVERS[0]) + 'interpreter'
        parameter = QgsProcessingParameterString(self.SERVER,
                                                 tr('Overpass server'),
                                                 optional=False,
                                                 defaultValue=server)
        parameter.setFlags(parameter.flags()
                           | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(parameter)

        parameter = QgsProcessingParameterString(
            self.AREA,
            tr('Area (if you want to override {{geocodeArea}} in the query)'),
            optional=True)
        parameter.setFlags(parameter.flags()
                           | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(parameter)

        self.addOutput(
            QgsProcessingOutputString(self.OUTPUT_URL,
                                      tr('Query as encoded URL')))

        self.addOutput(
            QgsProcessingOutputString(self.OUTPUT_OQL_QUERY,
                                      tr('Raw query as OQL')))
    def initAlgorithm(self, config):
        # INPUTS
        parameter = QgsProcessingParameterString(self.INPUT,
                                                 "Champ qui ne sert à rien !",
                                                 optional=True)
        parameter.setFlags(parameter.flags()
                           | QgsProcessingParameterDefinition.FlagHidden)
        self.addParameter(parameter)

        # OUTPUTS

        self.addOutput(
            QgsProcessingOutputString(self.OUTPUT_MSG,
                                      tr("Message de sortie")))
    def initAlgorithm(self, config=None):
        """
        Definition of inputs and outputs of the algorithm, along with some other properties.
        """

        # read server connections and prepare enum items
        self.connection_options.clear()
        selected_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(selected_graph_server, str)\
                    and connection.name == selected_graph_server:
                selected_index = index
        self.addParameter(
            QgsProcessingParameterEnum(self.SERVER_NAME,
                                       self.tr('Server name'),
                                       self.connection_options, False,
                                       selected_index, False))

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

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

        self.addParameter(
            QgsProcessingParameterEnum(self.ATTRIBUTE, self.tr('Attribute'),
                                       self.attribute_options, False, 0,
                                       False))

        self.addParameter(
            QgsProcessingParameterString(self.NEW_VALUE, self.tr('New value'),
                                         None, False, False))

        self.addOutput(
            QgsProcessingOutputString(self.OUTPUT_NEW_VALUE, self.tr('State')))
예제 #18
0
    def initAlgorithm(self, config=None):
        """ Virtual override

            see https://qgis.org/api/classQgsProcessingAlgorithm.html
        """
        self.addParameter(
            QgsProcessingParameterNumber(
                self.PARAM1,
                'Parameter 1',
                type=QgsProcessingParameterNumber.Integer,
                minValue=0,
                maxValue=999,
                defaultValue=10))
        self.addOutput(QgsProcessingOutputString(self.OUTPUT, "Output"))
예제 #19
0
 def initAlgorithm(self, config=None):
     self.addParameter(
         QgsProcessingParameterFile(
             'Sourcefolder',
             'Source folder',
             behavior=QgsProcessingParameterFile.Folder,
             fileFilter='All files (*.*)',
             defaultValue='/Adat/PREGA/Download/2019'))
     self.addParameter(
         QgsProcessingParameterString('mask',
                                      'File name mask',
                                      multiLine=False,
                                      defaultValue="*.jp2"))
     self.addOutput(QgsProcessingOutputString('OUTPUT', 'Product list'))
예제 #20
0
    def initAlgorithm(self, config):
        # LizSync config file from ini
        ls = lizsyncConfig()

        # INPUTS
        connection_name = ls.variable('postgresql:central/name')
        db_param_a = QgsProcessingParameterString(
            self.CONNECTION_NAME,
            tr('PostgreSQL connection to the central database'),
            defaultValue=connection_name,
        )
        db_param_a.setMetadata({
            'widget_wrapper': {
                'class': 'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'
            }
        })
        self.addParameter(db_param_a)

        # Hidden parameters which allow to drop the schemas
        # Hidden to avoid misuse and data loss
        # Drop schema audit
        p = QgsProcessingParameterBoolean(
            self.OVERRIDE_AUDIT,
            tr('Drop audit schema and all data ?'),
            defaultValue=False,
        )
        p.setFlags(QgsProcessingParameterDefinition.FlagHidden)
        self.addParameter(p)
        # Drop schema lizsync
        p = QgsProcessingParameterBoolean(
            self.OVERRIDE_LIZSYNC,
            tr('Drop lizsync schema and all data ?'),
            defaultValue=False,
        )
        p.setFlags(QgsProcessingParameterDefinition.FlagHidden)
        self.addParameter(p)

        # OUTPUTS
        # Add output for status (integer)
        self.addOutput(
            QgsProcessingOutputNumber(
                self.OUTPUT_STATUS,
                tr('Output status')
            )
        )
        self.addOutput(
            QgsProcessingOutputString(
                self.OUTPUT_STRING, tr('Output message')
            )
        )
예제 #21
0
    def initAlgorithm(self, config=None):
        # Inputs
        self.addParameter(
            QgsProcessingParameterFile('INPUT',
                                       self.tr('Input carbon analysis file')))
        self.addParameter(
            QgsProcessingParameterNumber('YEAR_START',
                                         self.tr('Starting year')))
        self.addParameter(
            QgsProcessingParameterNumber('YEAR_END', self.tr('Ending year')))

        # Outputs
        self.addOutput(
            QgsProcessingOutputString(
                'FOREST_LOSS', self.tr('Forest loss per year in sq km.')))
        self.addOutput(
            QgsProcessingOutputString(
                'CARBON_LOSS', self.tr('Carbon loss per year in tonnes of C')))
        self.addOutput(
            QgsProcessingOutputNumber('CARBON_INITIAL',
                                      self.tr('Initial tonnes of C')))
        self.addOutput(
            QgsProcessingOutputNumber('AREA_FOREST',
                                      self.tr('Area of forest in sq km')))
        self.addOutput(
            QgsProcessingOutputNumber('AREA_NON_FOREST',
                                      self.tr('Area of non-forest in sq km')))
        self.addOutput(
            QgsProcessingOutputNumber(
                'AREA_MISSING', self.tr('Area of missing data in sq km')))
        self.addOutput(
            QgsProcessingOutputNumber('AREA_WATER',
                                      self.tr('Area of water in sq km')))
        self.addOutput(
            QgsProcessingOutputNumber('AREA_SITE',
                                      self.tr('Area of site in sq km')))
예제 #22
0
    def initAlgorithm(self, config=None):
        self.addParameter(
            QgsProcessingParameterFile(self.INPUT,
                                       'Input LYR file',
                                       extension='lyr'))

        self.addParameter(
            QgsProcessingParameterFileDestination(
                self.OUTPUT,
                'Destination QML file',
                fileFilter='QML files (*.qml)'))

        if QgsProcessingOutputBoolean is not None:
            self.addOutput(
                QgsProcessingOutputBoolean(self.CONVERTED, 'Converted'))
        self.addOutput(QgsProcessingOutputString(self.ERROR, 'Error message'))
예제 #23
0
    def initAlgorithm(self, config=None):  # pylint: disable=missing-docstring,unused-argument
        self.addParameter(
            QgsProcessingParameterFile(self.INPUT,
                                       'Input AVL file',
                                       extension='avl'))

        self.addParameter(
            QgsProcessingParameterFileDestination(
                self.OUTPUT,
                'Destination QML file',
                fileFilter='QML files (*.qml)'))

        if HAS_BOOLEAN_OUTPUT:
            self.addOutput(
                QgsProcessingOutputBoolean(self.CONVERTED, 'Converted'))
        self.addOutput(QgsProcessingOutputString(self.ERROR, 'Error message'))
예제 #24
0
    def initAlgorithm(self, config):
        connection_name = QgsExpressionContextUtils.globalScope().variable(
            "veloroutes_connection_name"
        )
        print(connection_name)
        db_param_a = QgsProcessingParameterString(
            self.CONNECTION_NAME,
            tr("Connexion PostgreSQL vers la base de données"),
            defaultValue=connection_name,
            optional=False,
        )
        db_param_a.setMetadata(
            {
                "widget_wrapper": {
                    "class": "processing.gui.wrappers_postgis.ConnectionWidgetWrapper"
                }
            }
        )
        self.addParameter(db_param_a)

        self.addParameter(
            QgsProcessingParameterBoolean(
                self.OVERRIDE,
                tr(
                    "Écraser le schéma {} ? ** ATTENTION ** "
                    "Cela supprimera toutes les données !"
                ).format(SCHEMA),
                defaultValue=False,
                optional=False,
            )
        )
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.ADD_TEST_DATA,
                tr("Ajouter des données de test ?"),
                defaultValue=False,
                optional=False,
            )
        )

        # OUTPUTS
        self.addOutput(
            QgsProcessingOutputNumber(self.OUTPUT_STATUS, tr("Output status"))
        )
        self.addOutput(
            QgsProcessingOutputString(self.OUTPUT_STRING, tr("Output message"))
        )
예제 #25
0
    def initAlgorithm(self, config):
        """
        Here we define the inputs and output of the algorithm, along
        with some other properties.
        """
        # INPUTS
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.OVERRIDE,
                'Écraser le schéma raepa et toutes les données ? ** ATTENTION **',
                defaultValue=False,
                optional=False))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.ADD_AUDIT,
                'Ajouter un audit de suivi des modifications sur les tables ?',
                defaultValue=True,
                optional=False))
        self.addParameter(
            QgsProcessingParameterCrs(self.SRID,
                                      'Projection des géométries',
                                      defaultValue='EPSG:2154',
                                      optional=False))
        self.addParameter(
            QgsProcessingParameterString(
                self.NOM,
                'Nom du gestionnaire',
                defaultValue='Communauté d\'Agglomération de Test',
                optional=False))
        self.addParameter(
            QgsProcessingParameterString(self.SIREN,
                                         'SIREN',
                                         defaultValue='123456789',
                                         optional=False))
        self.addParameter(
            QgsProcessingParameterString(self.CODE,
                                         'Nom abbrégé en 3 caractères',
                                         defaultValue='cat',
                                         optional=False))

        # OUTPUTS
        # Add output for status (integer)
        self.addOutput(
            QgsProcessingOutputNumber(self.OUTPUT_STATUS, 'Statut de sortie'))
        self.addOutput(
            QgsProcessingOutputString(self.OUTPUT_STRING, 'Message de sortie'))
예제 #26
0
    def initAlgorithm(self, config):

        self.addParameter(
            QgsProcessingParameterBoolean(
                self.RUN_MIGRATIONS,
                'Cocher cette case pour faire la mise à jour. Autrement, aucune action ne se passera.',
                defaultValue=False,
            ))
        self.addParameter(
            QgsProcessingParameterCrs(self.SRID,
                                      'Projection des géométries',
                                      defaultValue='EPSG:2154',
                                      optional=False))
        self.addOutput(
            QgsProcessingOutputNumber(self.OUTPUT_STATUS, 'Statut de sortie'))
        self.addOutput(
            QgsProcessingOutputString(self.OUTPUT_STRING, 'Message de sortie'))
    def initAlgorithm(self, config):
        # INPUTS
        connection_name = QgsExpressionContextUtils.globalScope().variable(
            'gobs_connection_name')
        get_data = QgsExpressionContextUtils.globalScope().variable(
            'gobs_get_database_data')

        # List of spatial_layer
        sql = '''
            SELECT id, sl_label
            FROM gobs.spatial_layer
            ORDER BY sl_label
        '''
        dbpluginclass = createDbPlugin('postgis')
        connections = [c.connectionName() for c in dbpluginclass.connections()]
        data = []
        if get_data == 'yes' and connection_name in connections:
            [header, data, rowCount, ok,
             error_message] = fetchDataFromSqlQuery(connection_name, sql)
        self.SPATIALLAYERS = ['%s - %s' % (a[1], a[0]) for a in data]
        self.addParameter(
            QgsProcessingParameterEnum(self.SPATIALLAYER,
                                       tr('Target spatial layer'),
                                       options=self.SPATIALLAYERS,
                                       optional=False))
        self.addParameter(
            QgsProcessingParameterVectorLayer(self.SOURCELAYER,
                                              tr('Source data layer'),
                                              optional=False))
        self.addParameter(
            QgsProcessingParameterField(
                self.UNIQUEID,
                tr('Unique identifier'),
                parentLayerParameterName=self.SOURCELAYER))
        self.addParameter(
            QgsProcessingParameterField(
                self.UNIQUELABEL,
                tr('Unique label'),
                parentLayerParameterName=self.SOURCELAYER,
                type=QgsProcessingParameterField.String))

        # OUTPUTS
        # Add output for message
        self.addOutput(
            QgsProcessingOutputString(self.OUTPUT_STRING,
                                      tr('Output message')))
예제 #28
0
    def initAlgorithm(self, config=None):
        self.addParameter(
            QgsProcessingParameterMultipleLayers(self.INPUT,
                                                 self.tr('Input datasources'),
                                                 QgsProcessing.TypeVector))
        self.addParameter(
            QgsProcessingParameterBoolean(self.UNIONED,
                                          self.tr('Create "unioned" VRT'),
                                          defaultValue=False))

        class ParameterVectorVrtDestination(
                QgsProcessingParameterVectorDestination):
            def __init__(self, name, description):
                super().__init__(name, description)

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

            def defaultFileExtension(self):
                return 'vrt'

            def createFileFilter(self):
                return '{} (*.vrt *.VRT)'.format(
                    QCoreApplication.translate("GdalAlgorithm", 'VRT files'))

            def supportedOutputRasterLayerExtensions(self):
                return ['vrt']

            def isSupportedOutputValue(self, value, context):
                output_path = QgsProcessingParameters.parameterAsOutputLayer(
                    self, value, context)
                if pathlib.Path(output_path).suffix.lower() != '.vrt':
                    return False, QCoreApplication.translate(
                        "GdalAlgorithm",
                        'Output filename must use a .vrt extension')
                return True, ''

        self.addParameter(
            ParameterVectorVrtDestination(self.OUTPUT,
                                          self.tr('Virtual vector')))
        self.addOutput(
            QgsProcessingOutputString(self.VRT_STRING,
                                      self.tr('Virtual string')))
예제 #29
0
    def initAlgorithm(self, config={}):
        """ Virtual override

            see https://qgis.org/api/classQgsProcessingAlgorithm.html
        """
        # XXX Do not modify anything to 'self': we CANNOT presume that same
        # instance will be used for processAlgorithm().
        project_name = config.get('project_uri')
        try:
            self.addParameter(
                QgsProcessingParameterString(self.INPUT,
                                             'Input string',
                                             defaultValue=project_name,
                                             optional=True))
        except Exception:
            traceback.print_exc()

        self.addOutput(QgsProcessingOutputString(self.OUTPUT, "Output"))
예제 #30
0
    def initAlgorithm(self, config=None):
        # LizSync config file from ini
        ls = lizsyncConfig()

        # INPUTS

        # Central database connection
        # Needed because we need to check we can connect to central database
        connection_name_central = ls.variable('postgresql:central/name')
        db_param_a = QgsProcessingParameterString(
            self.CONNECTION_NAME_CENTRAL,
            tr('PostgreSQL connection to the central database'),
            defaultValue=connection_name_central,
            optional=False)
        db_param_a.setMetadata({
            'widget_wrapper': {
                'class':
                'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'
            }
        })
        self.addParameter(db_param_a)

        # Clone database connection parameters
        connection_name_clone = ls.variable('postgresql:clone/name')
        db_param_b = QgsProcessingParameterString(
            self.CONNECTION_NAME_CLONE,
            tr('PostgreSQL connection to the clone database'),
            defaultValue=connection_name_clone,
            optional=False)
        db_param_b.setMetadata({
            'widget_wrapper': {
                'class':
                'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'
            }
        })
        self.addParameter(db_param_b)

        # OUTPUTS
        # Add output for message
        self.addOutput(
            QgsProcessingOutputNumber(self.OUTPUT_STATUS, tr('Output status')))
        self.addOutput(
            QgsProcessingOutputString(self.OUTPUT_STRING,
                                      tr('Output message')))