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=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=None): # pylint: disable=missing-docstring,unused-argument self.addParameter( QgsProcessingParameterFile(self.INPUT, 'Style database', extension='style')) self.addParameter( QgsProcessingParameterFileDestination( self.OUTPUT, 'Destination XML file', fileFilter="XML files (*.xml)")) self.addOutput( QgsProcessingOutputNumber(self.FILL_SYMBOL_COUNT, 'Fill Symbol Count')) self.addOutput( QgsProcessingOutputNumber(self.LINE_SYMBOL_COUNT, 'Line Symbol Count')) self.addOutput( QgsProcessingOutputNumber(self.MARKER_SYMBOL_COUNT, 'Marker Symbol Count')) self.addOutput( QgsProcessingOutputNumber(self.UNREADABLE_FILL_SYMBOLS, 'Unreadable Fill Symbol Count')) self.addOutput( QgsProcessingOutputNumber(self.UNREADABLE_LINE_SYMBOLS, 'Unreadable Line Symbol Count')) self.addOutput( QgsProcessingOutputNumber(self.UNREADABLE_MARKER_SYMBOLS, 'Unreadable Marker Symbol Count'))
def initAlgorithm(self, config=None): self.addParameter( QgsProcessingParameterFeatureSource( self.INPUT, self.tr("Input layer"), [QgsProcessing.TypeVectorPolygon])) self.addParameter( QgsProcessingParameterField( self.FIELD, self.tr("Field"), type=QgsProcessingParameterField.Numeric, parentLayerParameterName=self.INPUT)) self.addParameter( QgsProcessingParameterNumber( self.MAX_ITERATIONS, self.tr("max. number of iterations"), type=QgsProcessingParameterNumber.Integer, defaultValue=10)) self.addParameter( QgsProcessingParameterNumber( self.MAX_AVERAGE_ERROR, self.tr("max. average error (%)"), type=QgsProcessingParameterNumber.Double, # metadata={"widget_wrapper": {"decimals": 2}}, minValue=0.1, defaultValue=10.0, maxValue=100.0)) self.addParameter( QgsProcessingParameterFeatureSink( self.OUTPUT, self.tr("Output layer"), type=QgsProcessing.TypeVectorPolygon)) self.addOutput(QgsProcessingOutputString(self.FIELD, self.tr("Field"))) self.addOutput( QgsProcessingOutputNumber( self.ITERATIONS, self.tr( "Iterations needed to meet residual error threshold."))) self.addOutput( QgsProcessingOutputNumber(self.RESIDUAL_AVERAGE_ERROR, self.tr("Residual average error.")))
def __init__(self): super().__init__() self.methods = [self.tr('The one selected in digitizing settings'), 'QGIS', 'GEOS'] self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT_LAYER, self.tr('Input layer'))) self.addParameter(QgsProcessingParameterEnum(self.METHOD, self.tr('Method'), self.methods)) self.addParameter(QgsProcessingParameterFeatureSink(self.VALID_OUTPUT, self.tr('Valid output'), QgsProcessingParameterDefinition.TypeVectorAny, '', True)) self.addOutput(QgsProcessingOutputVectorLayer(self.VALID_OUTPUT, self.tr('Valid output'))) self.addOutput(QgsProcessingOutputNumber(self.VALID_COUNT, self.tr('Count of valid features'))) self.addParameter(QgsProcessingParameterFeatureSink(self.INVALID_OUTPUT, self.tr('Invalid output'), QgsProcessingParameterDefinition.TypeVectorAny, '', True)) self.addOutput(QgsProcessingOutputVectorLayer(self.INVALID_OUTPUT, self.tr('Invalid output'))) self.addOutput(QgsProcessingOutputNumber(self.INVALID_COUNT, self.tr('Count of invalid features'))) self.addParameter(QgsProcessingParameterFeatureSink(self.ERROR_OUTPUT, self.tr('Error output'), QgsProcessingParameterDefinition.TypeVectorAny, '', True)) self.addOutput(QgsProcessingOutputVectorLayer(self.ERROR_OUTPUT, self.tr('Error output'))) self.addOutput(QgsProcessingOutputNumber(self.ERROR_COUNT, self.tr('Count of errors')))
def initAlgorithm(self, config=None): self.methods = [self.tr('The one selected in digitizing settings'), 'QGIS', 'GEOS'] self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT_LAYER, self.tr('Input layer'))) self.addParameter(QgsProcessingParameterEnum(self.METHOD, self.tr('Method'), self.methods, defaultValue=2)) self.parameterDefinition(self.METHOD).setMetadata({ 'widget_wrapper': { 'class': 'processing.gui.wrappers.EnumWidgetWrapper', 'useCheckBoxes': True, 'columns': 3}}) self.addParameter(QgsProcessingParameterFeatureSink(self.VALID_OUTPUT, self.tr('Valid output'), QgsProcessing.TypeVectorAnyGeometry, '', True)) self.addOutput(QgsProcessingOutputNumber(self.VALID_COUNT, self.tr('Count of valid features'))) self.addParameter(QgsProcessingParameterFeatureSink(self.INVALID_OUTPUT, self.tr('Invalid output'), QgsProcessing.TypeVectorAnyGeometry, '', True)) self.addOutput(QgsProcessingOutputNumber(self.INVALID_COUNT, self.tr('Count of invalid features'))) self.addParameter(QgsProcessingParameterFeatureSink(self.ERROR_OUTPUT, self.tr('Error output'), QgsProcessing.TypeVectorAnyGeometry, '', True)) self.addOutput(QgsProcessingOutputNumber(self.ERROR_COUNT, self.tr('Count of errors')))
def initAlgorithm(self, config): self.addParameter( QgsProcessingParameterFile( self.INPUT, tr('Fichier d\'ITV') ) ) self.addParameter( QgsProcessingParameterVectorLayer( self.FILE_TABLE, tr('Tableau des fichiers d\'ITV importés'), [QgsProcessing.TypeVector], defaultValue='file' ) ) self.addParameter( QgsProcessingParameterVectorLayer( self.SEGMENT_TABLE, tr('Tableau des tronçons d\'ITV'), [QgsProcessing.TypeVector], defaultValue='troncon' ) ) self.addParameter( QgsProcessingParameterVectorLayer( self.OBSERVATIONS_TABLE, tr('Tableau des observations d\'ITV'), [QgsProcessing.TypeVector], defaultValue='obs' ) ) self.addParameter( QgsProcessingParameterVectorLayer( self.MANHOLES_TABLE, tr('Tableau des regards d\'ITV'), [QgsProcessing.TypeVector], defaultValue='regard' ) ) self.addOutput( QgsProcessingOutputNumber( self.SUCCESS, tr('Succès') ) )
def initAlgorithm(self, config=None): self.addParameter( QgsProcessingParameterFile(self.INPUT, 'GPL palette', extension='gpl')) self.addParameter( QgsProcessingParameterFileDestination( self.OUTPUT, 'Destination stylx database', fileFilter="STYLX files (*.stylx)")) self.addOutput( QgsProcessingOutputNumber(self.COLOR_COUNT, 'Color Count'))
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') ) )
def initAlgorithm(self, config=None): """ Definition of inputs and outputs of the algorithm, along with some other properties. """ self.addParameter( QgsProcessingParameterFeatureSource( self.INPUT, self.tr('Input point layer'), [QgsProcessing.TypeVectorPoint], None, False)) self.addParameter( QgsProcessingParameterNumber(self.TRACK_ID, self.tr('Track ID'), QgsProcessingParameterNumber.Integer, 0, False)) self.addParameter( QgsProcessingParameterString( self.TRACK_TAGS, self.tr('Track Metadata Tags as JSON'), optional=True)) self.addParameter( QgsProcessingParameterField( self.TIMESTAMP_FIELD, self.tr('Timestamp field'), parentLayerParameterName=self.INPUT, type=QgsProcessingParameterField.DateTime)) self.addParameter( QgsProcessingParameterBoolean( self.ADD_MOTION_ATTRIBUTES, self.tr('Add motion attributes to track points'), False, True)) self.addParameter( QgsProcessingParameterField( self.FIELDS_AS_TAGS, self.tr('Select fields for track point tags'), parentLayerParameterName=self.INPUT, allowMultiple=True, optional=True)) self.addParameter( QgsProcessingParameterFileDestination( self.OUTPUT, self.tr('JSON trajectory file'), 'JSON files (*.json)')) self.addOutput( QgsProcessingOutputNumber(self.NUMBER_TRACK_POINTS, self.tr('Number of track points')))
def initAlgorithm(self, config): """ Here we define the inputs and output of the algorithm, along with some other properties. """ self.addParameter( QgsProcessingParameterVectorLayer( self.COMMUNE_LAYER, self.tr('La couche communes'), [QgsProcessing.TypeVectorPolygon], defaultValue='Communes')) self.addParameter( QgsProcessingParameterField( self.COMMUNE_UNIQUE_FIELD, self.tr('Champs identifiant les communes'), parentLayerParameterName=self.COMMUNE_LAYER, defaultValue='geo_commune', type=QgsProcessingParameterField.String)) self.addParameter( QgsProcessingParameterVectorLayer( self.SECTION_LAYER, self.tr('La couche sections'), [QgsProcessing.TypeVectorPolygon])) self.addParameter( QgsProcessingParameterField( self.SECTION_UNIQUE_FIELD, self.tr('Champs identifiant les sections'), parentLayerParameterName=self.SECTION_LAYER, defaultValue='geo_section', type=QgsProcessingParameterField.String)) self.addParameter( QgsProcessingParameterVectorLayer( self.PARCELLE_LAYER, self.tr('La couche parcelles'), [QgsProcessing.TypeVectorPolygon])) self.addParameter( QgsProcessingParameterField( self.PARCELLE_UNIQUE_FIELD, self.tr('Champs identifiant les parcelles'), parentLayerParameterName=self.PARCELLE_LAYER, defaultValue='geo_parcelle', type=QgsProcessingParameterField.String)) self.addOutput( QgsProcessingOutputNumber(self.SUCCESS, self.tr('Succès')))
def initAlgorithm(self, config=None): self.addParameter( QgsProcessingParameterString('INPUT', self.tr('GeoJSON specifying mask'))) self.addParameter( QgsProcessingParameterFile( 'MODEL_FILE', self.tr( 'Geotiff used as model for output bounds and resolution'))) self.addParameter( QgsProcessingParameterFileDestination( 'OUTPUT', self.tr('Output geotiff file'))) self.addOutput( QgsProcessingOutputNumber( 'SUCCESS', self.tr('Did operation complete successfully?')))
def initAlgorithm(self, config=None): self.addParameter( QgsProcessingParameterFeatureSource( self.INPUT, self.tr('Line layer'), [QgsProcessing.TypeVectorLine])) self.addParameter( QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Climb layer'))) self.addOutput( QgsProcessingOutputNumber(self.TOTALCLIMB, self.tr('Total climb'))) self.addOutput( QgsProcessingOutputNumber(self.TOTALDESCENT, self.tr('Total descent'))) self.addOutput( QgsProcessingOutputNumber(self.MINELEVATION, self.tr('Minimum elevation'))) self.addOutput( QgsProcessingOutputNumber(self.MAXELEVATION, self.tr('Maximum elevation')))
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")) )
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): """ 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'))
def initAlgorithm(self, config=None): # pylint: disable=missing-docstring,unused-argument self.addParameter(QgsProcessingParameterFile( self.INPUT, 'Style database', extension='style')) self.addParameter(QgsProcessingParameterFileDestination(self.OUTPUT, 'Destination XML file', fileFilter="XML files (*.xml)")) self.addParameter(QgsProcessingParameterFolderDestination(self.PICTURE_FOLDER, 'Store extracted pictures in', optional=True)) self.addParameter(QgsProcessingParameterBoolean(self.EMBED_PICTURES, 'Embed pictures where possible', defaultValue=False)) self.addParameter(QgsProcessingParameterBoolean(self.CONVERT_FONTS, 'Convert font markers to SVG files', defaultValue=False)) self.addParameter(QgsProcessingParameterBoolean(self.PARAMETERIZE, 'Create parameterized SVG files where possible', defaultValue=False)) self.addParameter(QgsProcessingParameterFeatureSink(self.REPORT, 'Unconvertable symbols report', QgsProcessing.TypeVector, None, True, False)) unit_param = QgsProcessingParameterEnum(self.UNITS, 'Units for symbols', ['Points', 'Millimeters'], defaultValue=0) unit_param.setFlags(unit_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced) self.addParameter(unit_param) force_svg = QgsProcessingParameterBoolean(self.FORCE_SVG, 'Force use of SVG fill instead of raster fill', defaultValue=False) force_svg.setFlags(force_svg.flags() | QgsProcessingParameterDefinition.FlagAdvanced) self.addParameter(force_svg) relative_paths = QgsProcessingParameterBoolean(self.RELATIVE_PATHS, 'Use relative paths for images', defaultValue=False) relative_paths.setFlags(relative_paths.flags() | QgsProcessingParameterDefinition.FlagAdvanced) self.addParameter(relative_paths) self.addOutput(QgsProcessingOutputNumber(self.FILL_SYMBOL_COUNT, 'Fill Symbol Count')) self.addOutput(QgsProcessingOutputNumber(self.LINE_SYMBOL_COUNT, 'Line Symbol Count')) self.addOutput(QgsProcessingOutputNumber(self.MARKER_SYMBOL_COUNT, 'Marker Symbol Count')) self.addOutput(QgsProcessingOutputNumber(self.COLOR_RAMP_COUNT, 'Color Ramp Count')) self.addOutput(QgsProcessingOutputNumber(self.UNREADABLE_FILL_SYMBOLS, 'Unreadable Fill Symbol Count')) self.addOutput(QgsProcessingOutputNumber(self.UNREADABLE_LINE_SYMBOLS, 'Unreadable Line Symbol Count')) self.addOutput(QgsProcessingOutputNumber(self.UNREADABLE_MARKER_SYMBOLS, 'Unreadable Marker Symbol Count')) self.addOutput(QgsProcessingOutputNumber(self.UNREADABLE_COLOR_RAMPS, 'Unreadable Color Ramps'))
def initAlgorithm(self, config=None): self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT, self.tr('Input layer'))) self.addParameter(QgsProcessingParameterBand(self.BAND, self.tr('Band number'), 1, self.INPUT)) self.addParameter(QgsProcessingParameterFileDestination(self.OUTPUT_HTML_FILE, self.tr('Statistics'), self.tr('HTML files (*.html)'), None, True)) self.addOutput(QgsProcessingOutputNumber(self.MIN, self.tr('Minimum value'))) self.addOutput(QgsProcessingOutputNumber(self.MAX, self.tr('Maximum value'))) self.addOutput(QgsProcessingOutputNumber(self.RANGE, self.tr('Range'))) self.addOutput(QgsProcessingOutputNumber(self.SUM, self.tr('Sum'))) self.addOutput(QgsProcessingOutputNumber(self.MEAN, self.tr('Mean value'))) self.addOutput(QgsProcessingOutputNumber(self.STD_DEV, self.tr('Standard deviation'))) self.addOutput(QgsProcessingOutputNumber(self.SUM_OF_SQUARES, self.tr('Sum of the squares')))
def initAlgorithm(self, config=None): self.addParameter( QgsProcessingParameterFile('INPUT', self.tr('Input file'))) self.addParameter( QgsProcessingParameterString( 'GEOJSON', self.tr('GeoJSON specifying area to clip to'))) self.addParameter( QgsProcessingParameterString( 'OUTPUT_BOUNDS', self.tr( 'Output bounds (as a string readable by numpy.fromstring)') )) self.addParameter( QgsProcessingParameterFileDestination('OUTPUT', self.tr('Output file'))) self.addOutput( QgsProcessingOutputNumber( 'SUCCESS', self.tr('Did operation complete successfully?')))
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')))
def initAlgorithm(self, config=None): """ Definition of inputs and outputs of the algorithm, along with some other properties. """ # We add the input vector layer. It can have any kind of geometry # It is a mandatory (not optional) one, hence the False argument # self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input gpx file'), # [QgsProcessing.TypeVectorLine])) self.addParameter(QgsProcessingParameterFile(self.INPUT, self.tr('Input GPX file'), # QgsProcessingParameterFile.Behavior.File, '*.gpx', # >1 extension not possible (QGIS Dev Vol 154 Issue 49 Message 3) 0, 'gpx', None, False)) # fileFilter="*.gpx;*.json")) self.addParameter(QgsProcessingParameterFileDestination(self.OUTPUT, self.tr('Output JSON file'), 'JSON files (*.json)', optional=True)) self.addOutput(QgsProcessingOutputNumber(self.NUMBER_TRACK_POINTS, self.tr('Number of track points')))
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' 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, optional=False, 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) self.addParameter( QgsProcessingParameterBoolean( self.RUN_MIGRATIONS, tr("Cocher cette option pour lancer la mise-à-jour."), defaultValue=False, optional=False, )) # OUTPUTS self.addOutput( QgsProcessingOutputNumber(self.OUTPUT_STATUS, tr("Output status"))) self.addOutput( QgsProcessingOutputString(self.OUTPUT_STRING, tr("Output message")))
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() default_graph_name = '' if isinstance(s, str): default_graph_name = s self.addParameter(QgsProcessingParameterString(self.GRAPH_NAME, self.tr('Graph name'), default_graph_name, False, True)) s = Settings.get_selected_graph_version() default_graph_version = '' if isinstance(s, str): default_graph_version = s self.addParameter(QgsProcessingParameterString(self.GRAPH_VERSION, self.tr('Graph version'), default_graph_version, False, True)) self.addParameter(QgsProcessingParameterBoolean(self.SAVE_JSON_FILE, self.tr('Save JSON file'), 'False', True)) # We add a vector layer as output self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT_SEGMENTS, self.tr('Segments'), QgsProcessing.TypeVectorLine)) self.addParameter(QgsProcessingParameterFileDestination(self.OUTPUT_JSON, self.tr('JSON graph file'), 'JSON files (*.json)', optional=True)) self.addOutput(QgsProcessingOutputNumber(self.OUTPUT_SEGMENT_COUNT, self.tr('Number of segments')))
def initAlgorithm(self, config): # Database connection parameters label = "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) # 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): """ Here we define the inputs and output of the algorithm, along with some other properties. """ self.layoutList = [ cView.name() for cView in QgsProject.instance().layoutManager().printLayouts() ] self.addParameter( QgsProcessingParameterEnum(self.LAYOUTS, self.tr('Layouts to export'), options=self.layoutList, allowMultiple=True)) self.addParameter( QgsProcessingParameterEnum( self.EXTENSION, self.tr('Extension for exported maps'), options=self.listFormats, defaultValue=ProcessingConfig.getSetting( 'DEFAULT_EXPORT_EXTENSION'))) self.addParameter( QgsProcessingParameterNumber( self.RESOLUTION, self. tr('Export resolution (if not set, the layout resolution is used)' ), optional=True, minValue=1)) self.addParameter( QgsProcessingParameterFolderDestination( self.OUTPUT, self.tr('Output folder where to save maps'))) self.addOutput( QgsProcessingOutputNumber(self.EXPORTEDLAYOUTS, self.tr('Number of layouts exported')))
def initAlgorithm(self, config=None): """ Definition of inputs and outputs of the algorithm, along with some other properties. """ self.addParameter( QgsProcessingParameterFile(self.INPUT, self.tr('Input track file'), 0, 'json', None, False)) self.addParameter( QgsProcessingParameterBoolean( self.ADD_HEADER_ATTRIBUTES, self.tr('Add header attributes to points'), False, True)) self.addParameter( QgsProcessingParameterFeatureSink(self.OUTPUT_POINT_LAYER, self.tr('Track point layer'), QgsProcessing.TypeVectorPoint)) self.addOutput( QgsProcessingOutputNumber(self.NUMBER_TRACK_POINTS, self.tr('Number of track points')))
def initAlgorithm(self, config): # INPUTS self.addParameter( QgsProcessingParameterBoolean( self.OVERRIDE, tr('Overwrite schema gobs and all data ? ** CAUTION ** It will remove all existing data !' ), defaultValue=False, )) self.addParameter( QgsProcessingParameterBoolean( self.ADD_TEST_DATA, tr('Add test data ?'), 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 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.OVERRIDE, tr('Overwrite schema gobs and all data ? ** CAUTION ** It will remove all existing data !' ), defaultValue=False, )) self.addParameter( QgsProcessingParameterBoolean( self.ADD_TEST_DATA, tr('Add test data ?'), 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 initAlgorithm(self, config=None): self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), [QgsProcessing.TypeVectorLine])) self.addParameter(QgsProcessingParameterNumber(self.POINTS_NUMBER, self.tr('Number of points on each line'), QgsProcessingParameterNumber.Integer, 1, False, 1, 1000000000)) self.addParameter(QgsProcessingParameterDistance(self.MIN_DISTANCE, self.tr('Minimum distance between points'), 0, self.INPUT, False, 0, 1000000000)) self.addParameter(QgsProcessingParameterNumber(self.MAXTRIESPERPOINT, self.tr('Maximum number of attempts per point'), QgsProcessingParameterNumber.Integer, 10, False, 1, 1000)) self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Random points'), type=QgsProcessing.TypeVectorPoint)) self.addOutput(QgsProcessingOutputNumber( self.OUTPUT_POINTS, self.tr('Number of point generated') ))
def initAlgorithm(self, config): # INPUTS connection_name = QgsExpressionContextUtils.globalScope().variable( "adresse_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.RUN_MIGRATIONS, tr("Cocher cette option pour lancer la mise-à-jour."), defaultValue=False, optional=False, )) self.addParameter( QgsProcessingParameterCrs(self.SRID, 'Projection des géométries', defaultValue='EPSG:2154', optional=False)) # OUTPUTS self.addOutput( QgsProcessingOutputNumber(self.OUTPUT_STATUS, tr("Output status"))) self.addOutput( QgsProcessingOutputString(self.OUTPUT_STRING, tr("Output message")))