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): # Database Connection if qgs_version < 31400: db_param = QgsProcessingParameterString( self.DATABASE, self.tr('Database Connection')) db_param.setMetadata({ 'widget_wrapper': { 'class': 'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'}}) else: db_param = QgsProcessingParameterProviderConnection( self.DATABASE, self.tr('Database Connection'), 'postgres') self.addParameter(db_param) # Schema if qgs_version < 31400: schema_param = QgsProcessingParameterString( self.SCHEMA, self.tr('Schema'), 'bc250_base') schema_param.setMetadata({ 'widget_wrapper': { 'class': 'processing.gui.wrappers_postgis.SchemaWidgetWrapper', 'connection_param': self.DATABASE}}) else: schema_param = QgsProcessingParameterDatabaseSchema( self.SCHEMA, self.tr('Schema'), defaultValue='bc250_base', connectionParameterName=self.DATABASE) self.addParameter(schema_param) # Prefixo (nome do projeto) prefix_param = QgsProcessingParameterString( self.PREFIX, 'Prefixo (nome do projeto)', '', False, True) self.addParameter(prefix_param) # featuretypes URL self.addParameter(QgsProcessingParameterString( self.URL, "URL")) # Geoserver user self.addParameter(QgsProcessingParameterString( self.USER, "User", "admin")) # Geoserver password self.addParameter(QgsProcessingParameterString( self.PASSWORD, "Password", "geoserver"))
def initAlgorithm(self, config=None): # Database Connection if qgs_version < 31400: db_param = QgsProcessingParameterString( self.DATABASE, self.tr('Database Connection')) db_param.setMetadata({ 'widget_wrapper': { 'class': 'processing.gui.wrappers_postgis.ConnectionWidgetWrapper' } }) else: db_param = QgsProcessingParameterProviderConnection( self.DATABASE, self.tr('Database Connection'), 'postgres') self.addParameter(db_param) # Schema if qgs_version < 31400: schema_param = QgsProcessingParameterString( self.SCHEMA, self.tr('Schema'), 'bc250_base') schema_param.setMetadata({ 'widget_wrapper': { 'class': 'processing.gui.wrappers_postgis.SchemaWidgetWrapper', 'connection_param': self.DATABASE } }) else: schema_param = QgsProcessingParameterDatabaseSchema( self.SCHEMA, self.tr('Schema'), defaultValue='bc250_base', connectionParameterName=self.DATABASE) self.addParameter(schema_param) # Shapefile used to clip self.addParameter( QgsProcessingParameterFile(self.SHAPEFILE_CLIP, self.tr('Clip Shapefile'), extension='shp', optional=True)) # Shapefile folder self.addParameter( QgsProcessingParameterFile(self.SHAPEFILE_FOLDER, self.tr('Shapefile Folder'), 1, 'shp', optional=False))
def initAlgorithm(self, config=None): # Database Connection if qgs_version < 31400: db_param = QgsProcessingParameterString( self.DATABASE, self.tr('Database Connection')) db_param.setMetadata({ 'widget_wrapper': { 'class': 'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'}}) else: db_param = QgsProcessingParameterProviderConnection( self.DATABASE, self.tr('Database Connection'), 'postgres') self.addParameter(db_param) # Schema if qgs_version < 31400: schema_param = QgsProcessingParameterString( self.SCHEMA, self.tr('Schema'), 'bc250_reamb') schema_param.setMetadata({ 'widget_wrapper': { 'class': 'processing.gui.wrappers_postgis.SchemaWidgetWrapper', 'connection_param': self.DATABASE}}) else: schema_param = QgsProcessingParameterDatabaseSchema( self.SCHEMA, self.tr('Schema'), defaultValue='bc250_reamb', connectionParameterName=self.DATABASE) self.addParameter(schema_param) # Geopackage self.addParameter(QgsProcessingParameterFile(self.GEOPACKAGE, 'Geopackage', 0, 'gpkg')) # Clean Schema '''
def initAlgorithm(self, config=None): self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Layer to import'), types=[QgsProcessing.TypeVector])) db_param = QgsProcessingParameterProviderConnection( self.DATABASE, self.tr('Database (connection name)'), 'postgres' ) self.addParameter(db_param) schema_param = QgsProcessingParameterDatabaseSchema( self.SCHEMA, self.tr('Schema (schema name)'), connectionParameterName=self.DATABASE, defaultValue='public', optional=True) self.addParameter(schema_param) table_param = QgsProcessingParameterDatabaseTable( self.TABLENAME, self.tr('Table to import to (leave blank to use layer name)'), defaultValue=None, connectionParameterName=self.DATABASE, schemaParameterName=self.SCHEMA, optional=True, allowNewTableNames=True) self.addParameter(table_param) self.addParameter(QgsProcessingParameterField(self.PRIMARY_KEY, self.tr('Primary key field'), None, self.INPUT, QgsProcessingParameterField.Any, False, True)) self.addParameter(QgsProcessingParameterString(self.GEOMETRY_COLUMN, self.tr('Geometry column'), 'geom')) self.addParameter(QgsProcessingParameterString(self.ENCODING, self.tr('Encoding'), 'UTF-8', False, True)) self.addParameter(QgsProcessingParameterBoolean(self.OVERWRITE, self.tr('Overwrite'), True)) self.addParameter(QgsProcessingParameterBoolean(self.CREATEINDEX, self.tr('Create spatial index'), True)) self.addParameter(QgsProcessingParameterBoolean(self.LOWERCASE_NAMES, self.tr('Convert field names to lowercase'), True)) self.addParameter(QgsProcessingParameterBoolean(self.DROP_STRING_LENGTH, self.tr('Drop length constraints on character fields'), False)) self.addParameter(QgsProcessingParameterBoolean(self.FORCE_SINGLEPART, self.tr('Create single-part geometries instead of multi-part'), False))
def initAlgorithm(self, config): """Initialize algorithm with inputs and output parameters.""" if HAS_DB_PROCESSING_PARAMETER: db_param = QgsProcessingParameterProviderConnection( self.DATABASE, self.tr('PostgreSQL database (connection name)'), 'postgres', ) schema_param = QgsProcessingParameterDatabaseSchema( self.SCHEMA, self.tr('PostgreSQL schema name'), connectionParameterName=self.DATABASE, defaultValue='public', ) table_param = QgsProcessingParameterDatabaseTable( self.TABLENAME, self.tr('PostgreSQL original table name'), connectionParameterName=self.DATABASE, schemaParameterName=self.SCHEMA) else: db_param = QgsProcessingParameterString( self.DATABASE, self.tr('PostgreSQL database (connection name)'), ) db_param.setMetadata({ 'widget_wrapper': { 'class': 'processing.gui.wrappers_postgis.ConnectionWidgetWrapper' } }) schema_param = QgsProcessingParameterString( self.SCHEMA, self.tr('PostgreSQL schema name'), 'public', False, True, ) schema_param.setMetadata({ 'widget_wrapper': { 'class': 'processing.gui.wrappers_postgis.SchemaWidgetWrapper', 'connection_param': self.DATABASE, } }) table_param = QgsProcessingParameterString( self.TABLENAME, self.tr('PostgreSQL original table name'), '', False, True, ) table_param.setMetadata({ 'widget_wrapper': { 'class': 'processing.gui.wrappers_postgis.TableWidgetWrapper', 'schema_param': self.SCHEMA, } }) self.addParameter(db_param) self.addParameter(schema_param) self.addParameter(table_param) self.addParameter( QgsProcessingParameterFeatureSource( self.NEW_INPUT, self.tr('New layer'), types=[QgsProcessing.TypeVector], )) self.addParameter( QgsProcessingParameterField( self.FIELDS_TO_COMPARE, self.tr('Fields to compare'), None, self.NEW_INPUT, allowMultiple=True, )) self.addParameter( QgsProcessingParameterEnum( self.HIGHLIGHT_METHOD, self.tr('Highlight method'), options=[ self.tr('Only highlight different lines'), self. tr('Highligt different lines and inta-line character changes (Slower on ' 'large layers)'), ], defaultValue=0, )) self.addParameter( QgsProcessingParameterExpression( self.SORT_EXPRESSION, self.tr('Sort expression (put in ORDER BY clause)'), parentLayerParameterName=self.NEW_INPUT, defaultValue='', )) self.addParameter( QgsProcessingParameterFileDestination( self.OUTPUT_HTML_FILE, self.tr('HTML report'), self.tr('HTML files (*.html)'), None, True))
def initAlgorithm(self, config=None): db_param = QgsProcessingParameterProviderConnection( self.DATABASE, self.tr('Database (connection name)'), 'postgres') 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=True)) 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 = QgsProcessingParameterDatabaseSchema( self.SCHEMA, self.tr('Schema (schema name)'), defaultValue='public', connectionParameterName=self.DATABASE, optional=True) self.addParameter(schema_param) table_param = QgsProcessingParameterDatabaseTable( self.TABLE, self.tr('Table to import to (leave blank to use layer name)'), defaultValue=None, connectionParameterName=self.DATABASE, schemaParameterName=self.SCHEMA, optional=True, allowNewTableNames=True) 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))
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) # Schéma de destination label = tr("Schéma") tooltip = 'Nom du schéma où importer les données' 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) # Table de destination label = tr("Table de destination") tooltip = 'Nom du schéma où importer les données' default = 'portion' if Qgis.QGIS_VERSION_INT >= 31400: param = QgsProcessingParameterDatabaseTable( self.TABLE, label, self.DATABASE, self.SCHEMA, defaultValue=default, optional=False, ) else: param = QgsProcessingParameterString(self.TABLE, label, default, False) param.setMetadata({ "widget_wrapper": { "class": "processing.gui.wrappers_postgis.TableWidgetWrapper", "schema_param": self.SCHEMA } }) if Qgis.QGIS_VERSION_INT >= 31600: param.setHelp(tooltip) else: param.tooltip_3liz = tooltip self.addParameter(param) # Couche à importer couche = QgsProcessingParameterVectorLayer( self.INPUT, 'Couche à importer', types=[QgsProcessing.TypeVector], ) self.addParameter(couche) # Paramètre pour le mapping de champs table = QgsProcessingParameterMatrix( self.MATRIX, 'matrix', headers=['Champs source', 'Champs destination'], defaultValue=[ "TYPE_PORTION_COVADIS", "type_portion", "MONTANT_SUBVENTION", "mont_subv", "ANNE_SUBVENTION", "annee_subv", "fid", "id_import", "LIEN_ITIN", "lien_itin", "LIEN_CYCLO", "lien_segm" ]) self.addParameter(table) # OUTPUTS self.addOutput( QgsProcessingOutputString(self.OUTPUT_MSG, tr("Message de sortie")))
def initAlgorithm(self, config): # Database connection parameters label = tr("Connexion PostgreSQL vers la base de données") tooltip = "Base de données de destination" default = QgsExpressionContextUtils.globalScope().variable( 'veloroutes_connection_name') if Qgis.QGIS_VERSION_INT >= 31400: param = QgsProcessingParameterProviderConnection( self.CONNECTION_NAME, label, "postgres", optional=False, defaultValue=default) else: param = QgsProcessingParameterString(self.CONNECTION_NAME, label, defaultValue=default) 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 des données véloroutes et voies vertes' default = 'veloroutes' if Qgis.QGIS_VERSION_INT >= 31400: param = QgsProcessingParameterDatabaseSchema( self.SCHEMA, label, self.CONNECTION_NAME, 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.CONNECTION_NAME, } }) if Qgis.QGIS_VERSION_INT >= 31600: param.setHelp(tooltip) else: param.tooltip_3liz = tooltip self.addParameter(param) # OUTPUTS # Add output for status (integer) output = QgsProcessingOutputNumber(self.OUTPUT_STATUS, 'Statut de sortie') output.tooltip_3liz = output.description() self.addOutput(output) # Add output for message output = QgsProcessingOutputString(self.OUTPUT_STRING, 'Message de sortie') output.tooltip_3liz = output.description() self.addOutput(output)
def initAlgorithm(self, config): label = tr("Connexion à 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.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) # Schema de destination label = tr("Schéma") tooltip = 'Nom du schéma où importer les données' 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) # Table à exporter table_param = QgsProcessingParameterEnum( self.TABLE, tr("Donnée à exporter"), options=self.EXPORTABLES, defaultValue="", ) table_param.tooltip_3liz = 'Nom de la table à exporter' self.addParameter(table_param) # Nom du département pour le fichier d'export depparam = QgsProcessingParameterString( self.DPT, tr("Département au format XXX"), '066', optional=False ) depparam.tooltip_3liz = 'Pour le département de l\'Ain, mettre 001' self.addParameter(depparam) # Chemin du dossier de destination outparam = QgsProcessingParameterFolderDestination( self.PROJECTS_FOLDER, description=tr("Chemin de destination") ) outparam.tooltip_3liz = 'Chemin de destination pour enregistrer les exports Shapefile' self.addParameter(outparam) param = QgsProcessingParameterBoolean( self.CHARGER, tr("Charger le fichier d'export dans le projet"), defaultValue=False, optional=False, ) param.tooltip_3liz = 'Si le traitement doit charger la couche Shapefile dans le projet' self.addParameter(param) output = QgsProcessingOutputVectorLayer(self.OUTPUT, tr("Couches de sortie")) output.tooltip_3liz = 'Les couches de l\'export' self.addOutput(output)