Exemplo n.º 1
0
    def checkParameterValues(self, parameters, context):
        # Check if runit is checked
        run_migrations = self.parameterAsBool(parameters, self.RUN_MIGRATIONS,
                                              context)
        if not run_migrations:
            msg = tr('You must check the box to run the upgrade !')
            ok = False
            return ok, msg

        # Check that the connection name has been configured
        connection_name = parameters[self.CONNECTION_NAME]
        if not connection_name:
            return False, tr(
                'You must use the "Configure G-obs plugin" alg to set the database connection name'
            )

        # Check that it corresponds to an existing connection
        if connection_name not in getPostgisConnectionList():
            return False, tr(
                'The configured connection name does not exists in QGIS')

        # Check database content
        ok, msg = self.checkSchema(parameters, context)
        if not ok:
            return False, msg

        return super(UpgradeDatabaseStructure,
                     self).checkParameterValues(parameters, context)
Exemplo n.º 2
0
    def initAlgorithm(self, config):
        # INPUTS
        project = QgsProject.instance()
        connection_name = QgsExpressionContextUtils.projectScope(
            project).variable('gobs_connection_name')
        db_param = QgsProcessingParameterString(
            self.CONNECTION_NAME,
            tr('PostgreSQL connection to G-Obs database'),
            defaultValue=connection_name,
            optional=False)
        db_param.setMetadata({
            'widget_wrapper': {
                'class':
                'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'
            }
        })
        self.addParameter(db_param)

        self.addParameter(
            QgsProcessingParameterBoolean(
                self.RUN_MIGRATIONS,
                tr('Check this box to upgrade. No action will be done otherwise'
                   ),
                defaultValue=False,
            ))
        # OUTPUTS
        # Add output for status (integer) and message (string)
        self.addOutput(
            QgsProcessingOutputNumber(self.OUTPUT_STATUS, tr('Output status')))
        self.addOutput(
            QgsProcessingOutputString(self.OUTPUT_STRING,
                                      tr('Output message')))
    def checkParameterValues(self, parameters, context):

        # Check that the connection name has been configured
        connection_name = parameters[self.CONNECTION_NAME]
        if not connection_name:
            return False, tr(
                'You must use the "Configure G-obs plugin" alg to set the database connection name'
            )

        # Check that it corresponds to an existing connection
        if connection_name not in getPostgisConnectionList():
            return False, tr(
                'The configured connection name does not exists in QGIS')

        # Check if the target project file ends with qgs
        project_file = self.parameterAsString(parameters, self.PROJECT_FILE,
                                              context)
        if not project_file.endswith('.qgs'):
            return False, tr(
                'The QGIS project file name must end with extension ".qgs"')

        # Check if the current project is an administration project
        # and if it is already configured for the chosen connection name
        p_connection_name = QgsExpressionContextUtils.projectScope(
            context.project()).variable('gobs_connection_name')
        admin_project = QgsExpressionContextUtils.projectScope(
            context.project()).variable('gobs_is_admin_project')
        if admin_project == 'yes' and connection_name == p_connection_name:
            return False, tr(
                'The current QGIS project is already an administration project '
                'configured for the chosen database connection')

        return super(CreateDatabaseLocalInterface,
                     self).checkParameterValues(parameters, context)
    def checkParameterValues(self, parameters, context):

        # Check date has been given
        ok = True
        field_timestamp = self.parameterAsString(parameters,
                                                 self.FIELD_TIMESTAMP, context)
        manualdate = (self.parameterAsString(parameters, self.MANUALDATE,
                                             context)).strip().replace(
                                                 '/', '-')
        if not field_timestamp and not manualdate:
            ok = False
            msg = tr(
                'You need to enter either a date/time field or a manual date/time'
            )

        # check validity of given manual date
        if manualdate:
            ok, msg = validateTimestamp(manualdate)
            if not ok:
                return ok, tr('Manual date or timestamp: ') + msg
            ok = True

        if not ok:
            return False, msg
        return super(ImportObservationData,
                     self).checkParameterValues(parameters, context)
Exemplo n.º 5
0
    def initAlgorithm(self, config):
        # INPUTS

        # Name of the layer
        self.addParameter(
            QgsProcessingParameterString(self.OUTPUT_LAYER_NAME,
                                         tr('Name of the output layer'),
                                         optional=True))

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

        # Output vector layer
        self.addOutput(
            QgsProcessingOutputVectorLayer(self.OUTPUT_LAYER,
                                           tr('Output layer')))

        # Output vector layer name (set by the user or the alg)
        self.addOutput(
            QgsProcessingOutputString(self.OUTPUT_LAYER_RESULT_NAME,
                                      tr('Output layer name')))
    def initAlgorithm(self, config):
        # INPUTS

        # connection name
        db_param = QgsProcessingParameterString(
            self.CONNECTION_NAME,
            tr('PostgreSQL connection to G-Obs database'),
            defaultValue='',
            optional=False)
        db_param.setMetadata({
            'widget_wrapper': {
                'class':
                'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'
            }
        })
        self.addParameter(db_param)

        # target project file
        self.addParameter(
            QgsProcessingParameterFileDestination(
                self.PROJECT_FILE,
                tr('QGIS project file to create'),
                defaultValue='',
                optional=False,
                fileFilter='qgs'))

        # OUTPUTS
        # Add output for status (integer)
        self.addOutput(
            QgsProcessingOutputNumber(self.OUTPUT_STATUS, tr('Output status')))
        # Add output for message
        self.addOutput(
            QgsProcessingOutputString(self.OUTPUT_STRING,
                                      tr('Output message')))
Exemplo n.º 7
0
    def initAlgorithm(self, config):
        # INPUTS
        # Database connection parameters
        project = QgsProject.instance()
        connection_name = QgsExpressionContextUtils.projectScope(project).variable('gobs_connection_name')
        db_param = QgsProcessingParameterString(
            self.CONNECTION_NAME,
            tr('PostgreSQL connection to G-Obs database'),
            defaultValue=connection_name,
            optional=False
        )
        db_param.setMetadata({
            'widget_wrapper': {
                'class': 'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'
            }
        })
        self.addParameter(db_param)

        # OUTPUTS
        # Add output for status (integer)
        self.addOutput(
            QgsProcessingOutputNumber(
                self.OUTPUT_STATUS,
                tr('Output status')
            )
        )
        # Add output for message
        self.addOutput(
            QgsProcessingOutputString(
                self.OUTPUT_STRING,
                tr('Output message')
            )
        )
Exemplo n.º 8
0
    def checkParameterValues(self, parameters, context):
        # Check if runit is checked
        run_delete = self.parameterAsBool(parameters, self.RUN_DELETE, context)
        if not run_delete:
            msg = tr(
                'You must check the box to delete the spatial layer data !')
            ok = False
            return ok, msg

        # Check that the connection name has been configured
        connection_name = QgsExpressionContextUtils.globalScope().variable(
            'gobs_connection_name')
        if not connection_name:
            return False, tr(
                'You must use the "Configure G-obs plugin" alg to set the database connection name'
            )

        # Check that it corresponds to an existing connection
        dbpluginclass = createDbPlugin('postgis')
        connections = [c.connectionName() for c in dbpluginclass.connections()]
        if connection_name not in connections:
            return False, tr(
                'The configured connection name does not exists in QGIS')

        # Check layyer id is in the list of existing spatial layers
        spatial_layer_id = self.parameterAsInt(parameters,
                                               self.SPATIALLAYER_ID, context)
        if spatial_layer_id and spatial_layer_id > 0:
            if spatial_layer_id not in self.SPATIALLAYERS_DICT:
                return False, tr(
                    'Spatial layer ID does not exists in the database')

        return super(RemoveSpatialLayerData,
                     self).checkParameterValues(parameters, context)
Exemplo n.º 9
0
    def runImportObservationData(self):

        # Get the list of series
        series = self.getSeries()
        if not series:
            return

        # Create dialog to let the user choose the serie
        dialog = QDialog()
        dialog.setWindowTitle(tr('Import observation data'))
        layout = QVBoxLayout()
        dialog.setLayout(layout)

        # Combobox
        combo_box = QComboBox()
        combo_box.setObjectName((tr('Choose series')))
        for i, d in enumerate(series):
            combo_box.addItem(d[1])
            combo_box.setItemData(i, d[0])
        layout.addWidget(combo_box)

        # Validation button
        button_box = QDialogButtonBox()
        button_box.addButton(QDialogButtonBox.Ok)
        button_box.button(QDialogButtonBox.Ok).clicked.connect(dialog.accept)
        layout.addWidget(button_box)

        if dialog.exec_() == QDialog.Accepted:
            idx = combo_box.currentIndex()
            val = combo_box.itemData(idx)
            self.openImportObservationData(val)
Exemplo n.º 10
0
    def checkParameterValues(self, parameters, context):

        # Check that the connection name has been configured
        connection_name = QgsExpressionContextUtils.projectScope(context.project()).variable('gobs_connection_name')
        if not connection_name:
            return False, tr('You must use the "Configure G-obs plugin" alg to set the database connection name')

        # Check that it corresponds to an existing connection
        if connection_name not in getPostgisConnectionList():
            return False, tr('The configured connection name does not exists in QGIS')

        serie_id = self.parameterAsInt(parameters, self.SERIE_ID, context)

        # Check series id is in the list of existing series
        if serie_id > 0:
            if serie_id not in self.SERIES_DICT.values():
                return False, tr('Series ID does not exists in the database')

        # Check timestamps
        min_timestamp = (self.parameterAsString(parameters, self.MIN_TIMESTAMP, context)).strip().replace('/', '-')
        max_timestamp = (self.parameterAsString(parameters, self.MAX_TIMESTAMP, context)).strip().replace('/', '-')
        if min_timestamp:
            ok, msg = validateTimestamp(min_timestamp)
            if not ok:
                return ok, tr('Minimum observation timestamp: ') + msg
        if max_timestamp:
            ok, msg = validateTimestamp(max_timestamp)
            if not ok:
                return ok, tr('Maximum observation timestamp: ') + msg

        return super(GetAggregatedData, self).checkParameterValues(parameters, context)
Exemplo n.º 11
0
    def initAlgorithm(self, config):
        # use parent class to get other parameters
        super(self.__class__, self).initAlgorithm(config)
        project = QgsProject.instance()
        connection_name = QgsExpressionContextUtils.projectScope(
            project).variable('gobs_connection_name')
        get_data = QgsExpressionContextUtils.globalScope().variable(
            'gobs_get_database_data')

        # List of series
        sql = '''
            SELECT s.id,
            concat(
                id_label,
                ' (', p.pr_label, ')',
                ' / Source: ', a_label,
                ' / Layer: ', sl_label
            ) AS label
            FROM gobs.series s
            INNER JOIN gobs.protocol p ON p.id = s.fk_id_protocol
            INNER JOIN gobs.actor a ON a.id = s.fk_id_actor
            INNER JOIN gobs.indicator i ON i.id = s.fk_id_indicator
            INNER JOIN gobs.spatial_layer sl ON sl.id = s.fk_id_spatial_layer
            ORDER BY label
        '''
        data = []
        if get_data == 'yes' and connection_name in getPostgisConnectionList():
            [header, data, rowCount, ok,
             error_message] = fetchDataFromSqlQuery(connection_name, sql)

        self.SERIES = ['%s' % a[1] for a in data]
        self.SERIES_DICT = {a[1]: a[0] for a in data}
        self.addParameter(
            QgsProcessingParameterEnum(self.SERIE,
                                       tr('Series of observations'),
                                       options=self.SERIES,
                                       optional=False))

        # Id of series, to get the series directly
        # mainly used from other processing algs
        p = QgsProcessingParameterNumber(
            self.SERIE_ID,
            tr('Series ID. If given, it overrides previous choice'),
            optional=True,
            defaultValue=-1)
        p.setFlags(QgsProcessingParameterDefinition.FlagHidden)
        self.addParameter(p)

        # Add spatial object geometry ?
        self.addParameter(
            QgsProcessingParameterBoolean(self.ADD_SPATIAL_OBJECT_GEOM,
                                          tr('Add spatial object geometry ?'),
                                          defaultValue=False,
                                          optional=False))
    def setSql(self, parameters, context, feedback):

        # Database connection parameters
        connection_name = QgsExpressionContextUtils.globalScope().variable('gobs_connection_name')
        get_data = QgsExpressionContextUtils.globalScope().variable('gobs_get_database_data')
        if get_data != 'yes':
            return

        # Get id, label and geometry type from chosen spatial layer
        spatiallayer = self.SPATIALLAYERS[parameters[self.SPATIALLAYER]]
        id_spatial_layer = int(spatiallayer.split('-')[-1].strip())

        # Override spatial layer id from second number input
        spatial_layer_id = self.parameterAsInt(parameters, self.SPATIALLAYER_ID, context)
        if spatial_layer_id and spatial_layer_id in self.SPATIALLAYERS_DICT:
            id_spatial_layer = spatial_layer_id

        feedback.pushInfo(
            tr('GET DATA FROM CHOSEN SPATIAL LAYER')
        )
        sql = "SELECT id, sl_label, sl_geometry_type FROM gobs.spatial_layer WHERE id = %s" % id_spatial_layer
        [header, data, rowCount, ok, message] = fetchDataFromSqlQuery(
            connection_name,
            sql
        )
        if ok:
            label = data[0][1]
            message = tr('* Data has been fetched for spatial layer')
            message += ' %s !' % label
            feedback.pushInfo(
                message
            )
        else:
            raise QgsProcessingException(message)

        # Retrieve needed data
        id_spatial_layer = data[0][0]
        geometry_type = data[0][2]

        # Build SQL
        sql = '''
            SELECT
                id,
                so_unique_id AS code,
                so_unique_label AS label,
                geom::geometry({1}, 4326) AS geom
            FROM gobs.spatial_object
            WHERE fk_id_spatial_layer = {0}
        '''.format(
            id_spatial_layer,
            geometry_type
        )
        self.SQL = sql.replace('\n', ' ').rstrip(';')
Exemplo n.º 13
0
    def processAlgorithm(self, parameters, context, feedback):

        # parameters
        connection_name = QgsExpressionContextUtils.globalScope().variable(
            'gobs_connection_name')
        delete_spatial_layer = self.parameterAsBool(parameters,
                                                    self.DELETE_SPATIAL_LAYER,
                                                    context)

        # Get id, label and geometry type from chosen spatial layer
        spatiallayer = self.SPATIALLAYERS[parameters[self.SPATIALLAYER]]
        id_spatial_layer = int(spatiallayer.split('-')[-1].strip())

        # Override spatial layer id from second number input
        spatial_layer_id = self.parameterAsInt(parameters,
                                               self.SPATIALLAYER_ID, context)
        if spatial_layer_id and spatial_layer_id in self.SPATIALLAYERS_DICT:
            id_spatial_layer = spatial_layer_id

        sql = '''
            DELETE FROM gobs.spatial_object
            WHERE fk_id_spatial_layer = {0};
            SELECT setval(
                pg_get_serial_sequence('gobs.spatial_object', 'id'),
                coalesce(max(id),0) + 1, false
            ) FROM gobs.spatial_object;
        '''.format(id_spatial_layer)

        if delete_spatial_layer:
            sql += '''
            DELETE FROM gobs.spatial_layer
            WHERE id = {0};
            SELECT setval(
                pg_get_serial_sequence('gobs.spatial_layer', 'id'),
                coalesce(max(id),0) + 1, false
            ) FROM gobs.spatial_layer;
            '''.format(id_spatial_layer)

        [header, data, rowCount, ok,
         message] = fetchDataFromSqlQuery(connection_name, sql)
        if ok:
            message = tr(
                'Spatial objects has been deleted for the chosen spatial layer'
            )
            if delete_spatial_layer:
                message += '. ' + tr('The spatial layer has also been deleted')
            feedback.pushInfo(message)
        else:
            raise QgsProcessingException(message)

        status = 1
        return {self.OUTPUT_STATUS: status, self.OUTPUT_STRING: message}
Exemplo n.º 14
0
    def runAlgorithm(self, name):

        if name not in self.algorithms:
            self.iface.messageBar().pushMessage(
                tr("Error"),
                tr("This algorithm cannot be found") + ' {}'.format(name),
                level=Qgis.Critical
            )
            return

        # Run alg
        param = {}
        alg_name = 'gobs:{0}'.format(name)
        execAlgorithmDialog(alg_name, param)
Exemplo n.º 15
0
    def processAlgorithm(self, parameters, context, feedback):
        connection_name = parameters[self.CONNECTION_NAME]

        # Set project variable
        QgsExpressionContextUtils.setProjectVariable(context.project(), 'gobs_connection_name', connection_name)
        feedback.pushInfo(tr('PostgreSQL connection to G-Obs database') + ' = ' + connection_name)

        msg = tr('Configuration has been saved')
        feedback.pushInfo(msg)
        status = 1

        return {
            self.OUTPUT_STATUS: status,
            self.OUTPUT_STRING: msg
        }
Exemplo n.º 16
0
 def shortHelpString(self):
     short_help = tr(
         'You must run this script before any other script.'
         '\n'
         'Every parameter will be used in the other algorithms, as default values for parameters.'
     )
     return short_help
 def shortHelpString(self):
     short_help = tr(
         'This algorithm allows to import data from a QGIS spatial layer into the G-Obs database'
         '\n'
         '\n'
         'The G-Obs administrator must have created the needed spatial layer beforehand by addind the required items in the related database tables: gobs.actor_category, gobs.actor and gobs.spatial_layer.'
         '\n'
         '* Target spatial layer: choose one of the spatial layers available in G-Obs database'
         '\n'
         '* Source data layer: choose the QGIS vector layer containing the spatial data you want to import into the chosen spatial layer.'
         '\n'
         '* Unique identifier: choose the field containing the unique ID. It can be an integer or a text field, but must be unique.'
         '\n'
         '* Unique label: choose the text field containing the unique label of the layer feature. You could use the QGIS field calculator to create one if needed.'
         '\n'
         '* Start of validity: choose the field with the start timestamp of validity for each feature.'
         ' Leave empty if all the features share the same date/time and manually enter the value in the next input.'
         ' This field content must respect the ISO format. For example 2020-05-01 10:50:30 or 2020-01-01'
         '\n'
         '* Start of validity for all features'
         ' Specify the start timestamp of validity for all the objects in the spatial layer.'
         ' This value must respect the ISO format. For example 2020-05-01 10:50:30 or 2020-01-01'
         '\n'
         '* End of validity: choose the field with the end timestamp of validity for each feature.'
         ' Leave empty if all the features share the same date/time and manually enter the value in the next input.'
         ' This field content must respect the ISO format. For example 2020-05-01 10:50:30 or 2020-01-01'
         '\n'
         '* End of validity for all features'
         ' Specify the end timestamp of validity for all the objects in the spatial layer.'
         ' This value must respect the ISO format. For example 2020-05-01 10:50:30 or 2020-01-01'
         '\n')
     return short_help
    def initAlgorithm(self, config):
        # INPUTS
        # Source layer
        self.addParameter(
            QgsProcessingParameterVectorLayer(self.SOURCELAYER,
                                              tr('Source data layer'),
                                              optional=False,
                                              types=[QgsProcessing.TypeVector
                                                     ]))
        # Date field
        self.addParameter(
            QgsProcessingParameterField(
                self.FIELD_TIMESTAMP,
                tr('Date and time field. ISO Format'),
                optional=True,
                parentLayerParameterName=self.SOURCELAYER))
        # Manual date field
        self.addParameter(
            QgsProcessingParameterString(
                self.MANUALDATE,
                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
        new_params = self.getAdditionnalParameters()
        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')))
Exemplo n.º 19
0
    def checkParameterValues(self, parameters, context):

        # Check that the connection name has been configured
        connection_name = QgsExpressionContextUtils.projectScope(
            context.project()).variable('gobs_connection_name')
        if not connection_name:
            return False, tr(
                'You must use the "Configure G-obs plugin" alg to set the database connection name'
            )

        # Check that it corresponds to an existing connection
        if connection_name not in getPostgisConnectionList():
            return False, tr(
                'The configured connection name does not exists in QGIS')

        return super(GetDataAsLayer,
                     self).checkParameterValues(parameters, context)
    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')))
 def shortHelpString(self):
     short_help = tr(
         'This algorithm allows to add a vector layer in your QGIS project containing the spatial data from the chosen G-Obs spatial layer. Data are dynamically fetched from the database, meaning they are always up-to-date.'
         '\n'
         '* Name of the output layer: choose the name of the QGIS layer to create. If not given, the label of the spatial layer will be used.'
         '\n'
         '* Spatial layer: choose the G-Obs spatial layer you want to use as the data source.'
     )
     return short_help
    def initAlgorithm(self, config):

        # use parent class to get other parameters
        super(self.__class__, self).initAlgorithm(config)

        connection_name = QgsExpressionContextUtils.globalScope().variable('gobs_connection_name')
        get_data = QgsExpressionContextUtils.globalScope().variable('gobs_get_database_data')

        # Add spatial layer choice
        # 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.SPATIALLAYERS_DICT = {a[0]: a[1] for a in data}
        self.addParameter(
            QgsProcessingParameterEnum(
                self.SPATIALLAYER,
                tr('Spatial layer'),
                options=self.SPATIALLAYERS,
                optional=False
            )
        )

        # Id of spatial layer, to get the layer directly
        # mainly used from other processing algs
        p = QgsProcessingParameterNumber(
            self.SPATIALLAYER_ID,
            tr('Spatial layer ID. If given, it overrides previous choice'),
            optional=True,
            defaultValue=-1
        )
        p.setFlags(QgsProcessingParameterDefinition.FlagHidden)
        self.addParameter(p)
Exemplo n.º 23
0
    def checkParameterValues(self, parameters, context):

        # Check that the connection name has been configured
        connection_name = QgsExpressionContextUtils.globalScope().variable(
            'gobs_connection_name')
        if not connection_name:
            return False, tr(
                'You must use the "Configure G-obs plugin" alg to set the database connection name'
            )

        # Check that it corresponds to an existing connection
        dbpluginclass = createDbPlugin('postgis')
        connections = [c.connectionName() for c in dbpluginclass.connections()]
        if connection_name not in connections:
            return False, tr(
                'The configured connection name does not exists in QGIS')

        return super(GetDataAsLayer,
                     self).checkParameterValues(parameters, context)
    def checkParameterValues(self, parameters, context):

        spatial_layer_id = self.parameterAsInt(parameters, self.SPATIALLAYER_ID, context)

        # Check layyer id is in the list of existing spatial layers
        if spatial_layer_id and spatial_layer_id > 0:
            if spatial_layer_id not in self.SPATIALLAYERS_DICT:
                return False, tr('Spatial layer ID does not exists in the database')

        return super(GetSpatialLayerVectorData, self).checkParameterValues(parameters, context)
    def checkParameterValues(self, parameters, context):
        # Check that the connection name has been configured
        connection_name = parameters[self.CONNECTION_NAME]
        if not connection_name:
            return False, tr(
                'You must use the "Configure G-obs plugin" alg to set the database connection name'
            )

        # Check that it corresponds to an existing connection
        if connection_name not in getPostgisConnectionList():
            return False, tr(
                'The configured connection name does not exists in QGIS')

        # Check database content
        ok, msg = self.checkSchema(parameters, context)
        if not ok:
            return False, msg
        return super(CreateDatabaseStructure,
                     self).checkParameterValues(parameters, context)
Exemplo n.º 26
0
    def checkParameterValues(self, parameters, context):

        serie_id = self.parameterAsInt(parameters, self.SERIE_ID, context)

        # Check series id is in the list of existing series
        if serie_id and serie_id > 0:
            if serie_id not in self.SERIES_DICT.values():
                return False, tr('Series ID does not exists in the database')

        return super(GetSeriesData, self).checkParameterValues(parameters, context)
Exemplo n.º 27
0
 def shortHelpString(self):
     short_help = tr(
         'This algorithms allows to completely delete spatial layer data (objects) for a specific spatial layer'
         '\n'
         '* Spatial layer: choose the G-Obs spatial layer.'
         '\n'
         '* Check this box to delete: this box must be checked in order to proceed. It is mainly here as a security. Please check the chosen spatial layer before proceeding !'
         '\n'
         '* Also delete the spatial layer item: if you want to delete not only the spatial objects of the spatial layers, but also the spatial layer item in the table.'
     )
     return short_help
 def shortHelpString(self):
     short_help = tr(
         'Install the G-Obs database structure with tables and function on the chosen database.'
         '\n'
         '\n'
         'This script will add a gobs schema with needed tables and functions'
         '\n'
         '\n'
         'Beware ! If you check the "override" checkboxes, you will loose all existing data in the existing gobs schema !'
     )
     return short_help
Exemplo n.º 29
0
 def shortHelpString(self):
     short_help = tr(
         'This algorithms allows to completely delete observation data for a specific series'
         '\n'
         '* Series of observations: the G-Obs series containing the observation data.'
         '\n'
         '* Check this box to delete: this box must be checked in order to proceed. It is mainly here as a security. Please check the chosen series before proceeding !'
         '\n'
         '* Also delete the series item: if you want to delete not only the observation data of the series, but also the series item in the table.'
     )
     return short_help
Exemplo n.º 30
0
 def shortHelpString(self):
     short_help = tr(
         'This algorithm will allow to configure G-Obs extension for the current QGIS project'
         '\n'
         '\n'
         'You must run this script before any other script.'
         '\n'
         '\n'
         '* PostgreSQL connection to G-Obs database: name of the database connection you would like to use for the current QGIS project. This connection will be used for the other algorithms.'
     )
     return short_help