Beispiel #1
0
    def initAlgorithm(self, config=None):
        self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
                                                              self.tr('Input layer')))

        self.addParameter(QgsProcessingParameterField(self.FIELD,
                                                      self.tr('Unique ID field'), None, self.INPUT))

        self.addParameter(QgsProcessingParameterFolderDestination(self.OUTPUT,
                                                                  self.tr('Output directory')))
        self.addOutput(QgsProcessingOutputMultipleLayers(self.OUTPUT_LAYERS, self.tr('Output layers')))
Beispiel #2
0
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('outputboolean'):
                out = QgsProcessingOutputBoolean(name, description)
#            elif token.lower().strip().startswith('extent'):
#                out = OutputExtent()

            return out
    except:
        return None
Beispiel #3
0
    def initAlgorithm(self, config=None):
        """
        Parameter setting.
        """
        self.addParameter(
            QgsProcessingParameterString(
                self.INPUTLAYERS,
                self.tr('Comma separated Input Layer Names')))

        self.addOutput(
            QgsProcessingOutputMultipleLayers(self.OUTPUT,
                                              self.tr('Multiple layer list')))
    def initAlgorithm(self, config):
        """
        Parameter setting.
        """
        self.addParameter(
            QgsProcessingParameterMultipleLayers(
                self.INPUT_LAYERS, self.tr('Input Layers'),
                QgsProcessing.TypeVectorAnyGeometry))

        self.addOutput(
            QgsProcessingOutputMultipleLayers(
                self.OUTPUT, self.tr('Original layers with measure column')))
 def initAlgorithm(self, config=None):
     self.addParameter(QgsProcessingParameterMultipleLayers('INPUT', 'Raster layers to include in VRT', layerType= QgsProcessing.TypeFile))
     self.addParameter(QgsProcessingParameterString('MASK', 'Name parts to use as filename and band (regexp)', multiLine=False,
                                                    defaultValue=r".+\/([0-9]{8})_(B[0-9]{1}[0-9,A]{1})\.tif$"))
     self.addParameter(
         QgsProcessingParameterString('BANDS', 'List of bands', multiLine=False,
                                      defaultValue="B01,B02,B03,B04,B05,B06,B07,B08,B09,B10,B11,B12,B8A"))
     self.addParameter(
         QgsProcessingParameterFolderDestination('OUTFOLDER', 'Virtual raster output folder',
                                    defaultValue='/AdatSSD/PREGA/Szakdolgozat/V2/2021'),
         createOutput = True
     )
     self.addOutput(QgsProcessingOutputMultipleLayers('OUTPUT', 'Virtual rasters'))
    def initAlgorithm(self, config):
        labels = [f.name for f in self.options]
        self.addParameter(
            QgsProcessingParameterEnum(
                self.FILES,
                'Requêtes',
                optional=False,
                options=labels,
                allowMultiple=True,
            ))

        self.addOutput(QgsProcessingOutputMultipleLayers(
            self.OUTPUT, 'Sortie'))
Beispiel #7
0
    def initAlgorithm(self, config):
        self.addParameter(
            QgsProcessingParameterFile(
                self.FOLDER_SHAPEFILES,
                self.tr('Pasta com Shapefiles'),
                behavior = QgsProcessingParameterFile.Folder,
            )
        )

        self.addOutput(
            QgsProcessingOutputMultipleLayers(
                self.OUTPUT,
                self.tr('Loaded layers')
            )
        )
Beispiel #8
0
 def initAlgorithm(self, config=None):
     """
     Here we define the inputs and output of the algorithm, along
     with some other properties.
     """
     self.addParameter(
         QgsProcessingParameterFeatureSource(
             self.INPUT_POINTS,
             self.tr('Input points layer'),
             [QgsProcessing.TypeVectorPoint],
         ))
     self.addParameter(
         QgsProcessingParameterField(
             self.INPUT_FIELD,
             self.tr('Unique field'),
             None,
             self.INPUT_POINTS,
             QgsProcessingParameterField.Any,
             False,  # allow multiple
             True,  # optional
         ))
     self.addParameter(
         QgsProcessingParameterRasterLayer(
             self.INPUT_DEM,
             self.tr('Input DEM'),
         ))
     self.addParameter(
         QgsProcessingParameterFolderDestination(
             self.OUTPUT_DIR,
             self.tr('Output directory'),
         ))
     self.addParameter(
         QgsProcessingParameterEnum(
             self.OUTPUT_TYPE,
             self.tr('Output type'),
             QgsVectorFileWriter.supportedFormatExtensions()[:2],
             False,
             'gpkg',
             False,
         ))
     self.addParameter(
         QgsProcessingParameterBoolean(self.LOAD_RESULTS,
                                       self.tr('Load result catchments'),
                                       True))
     self.addOutput(
         QgsProcessingOutputMultipleLayers(self.OUTPUT_LAYERS,
                                           self.tr('Output layers')))
    def initAlgorithm(self, config):
        """
        Parameter setting.
        """
        self.addParameter(
            QgsProcessingParameterMultipleLayers(
                self.INPUT_LAYERS, self.tr('Input Layers'),
                QgsProcessing.TypeVectorAnyGeometry))

        self.addParameter(
            QgsProcessingParameterString(self.STYLE_NAME,
                                         self.tr('Style Name')))

        self.addOutput(
            QgsProcessingOutputMultipleLayers(
                self.OUTPUT,
                self.tr('Original layers with styles applied column')))
 def initAlgorithm(self, config=None):
     self.addParameter(
         QgsProcessingParameterMultipleLayers(
             self.INPUT_LAYERS, self.tr('Input Layers'),
             QgsProcessing.TypeVectorAnyGeometry))
     self.addParameter(
         QgsProcessingParameterFile(
             self.VALUE_MAP_FILE,
             description=self.tr('Json file with value maps'),
             defaultValue='.json'))
     self.addParameter(
         QgsProcessingParameterString(self.VALUE_MAP,
                                      description=self.tr('Json data'),
                                      multiLine=True,
                                      defaultValue='{}'))
     self.addOutput(
         QgsProcessingOutputMultipleLayers(
             self.OUTPUT, self.tr('Original layers with values mapped')))
    def initAlgorithm(self, config):
        """
        Parameter setting.
        """
        self.addParameter(
            QgsProcessingParameterVectorLayer(
                self.INPUT, self.tr('Input layer'),
                [QgsProcessing.TypeVectorPolygon]))

        self.addParameter(
            QgsProcessingParameterBoolean(
                self.SELECTED, self.tr('Process only selected features')))
        self.addParameter(
            QgsProcessingParameterExtent(self.EXTENT,
                                         self.tr('Extent'),
                                         optional=True))
        self.addParameter(
            QgsProcessingParameterField(self.IMAGE_ATTRIBUTE,
                                        self.tr('Image attribute'), None,
                                        'INPUT',
                                        QgsProcessingParameterField.String))
        self.addParameter(
            QgsProcessingParameterBoolean(self.ADD_TO_CANVAS,
                                          self.tr('Add to canvas'),
                                          defaultValue=True))
        self.addParameter(
            QgsProcessingParameterBoolean(self.UNIQUE_LOAD,
                                          self.tr('Unique load'),
                                          defaultValue=True))
        self.addParameter(
            QgsProcessingParameterExpression(self.GROUP_EXPRESSION,
                                             self.tr('Group expression'),
                                             defaultValue="",
                                             optional=True))
        self.addParameter(
            QgsProcessingParameterString(
                self.NAME_TAG,
                self.tr('String used as prefix in images'),
                defaultValue="",
                optional=True))
        self.addOutput(
            QgsProcessingOutputMultipleLayers(self.OUTPUT,
                                              self.tr('Loaded raster layers')))
Beispiel #12
0
 def initAlgorithm(self, config=None):
     """
     Here we define the inputs and output of the algorithm, along
     with some other properties.
     """
     self.addParameter(
         QgsProcessingParameterVectorLayer(
             self.INPUT,
             self.tr('Fichier vectoriel'),
             [QgsProcessing.TypeVectorAnyGeometry]
         )
     )
     self.addParameter(
         QgsProcessingParameterField(
             self.INSEE_CODE,
             'Code INSEE',
             '',
             self.INPUT
             )
     )
     self.addParameter(
         QgsProcessingParameterField(
             self.COMMUNE_NAME,
             'Nom',
             '',
             self.INPUT
             )
     )
     self.addParameter(
         QgsProcessingParameterNumber(
             name=self.EPSG_CODE,
             description=self.tr('Code EPSG'),
             type=QgsProcessingParameterNumber.Integer,
             defaultValue=2154
         )
     )
     self.addOutput(
         QgsProcessingOutputMultipleLayers(
             self.OUTPUT_LAYERS,
             self.tr('Output layers')
         )
     )
Beispiel #13
0
 def initAlgorithm(self, config=None):
     self.addParameter(
         QgsProcessingParameterFile(
             self.FOLDER,
             self.tr("Output folder"),
             behavior=QgsProcessingParameterFile.Folder))
     self.addParameter(
         QgsProcessingParameterFile(
             self.ALLCYCLESHAPE,
             self.tr("shapefile for all flows"),
             behavior=QgsProcessingParameterFile.File))
     self.addParameter(
         QgsProcessingParameterFile(
             self.PCTSHAPE,
             self.tr("shapefile for PCT"),
             behavior=QgsProcessingParameterFile.File))
     self.addParameter(
         QgsProcessingParameterField(self.PCTFIELD, self.tr("PCT field")))
     self.addParameter(
         QgsProcessingParameterField(self.ALLFLOWSFIELD,
                                     self.tr("All flows field")))
     self.addOutput(QgsProcessingOutputMultipleLayers(self.OUTPUT))
Beispiel #14
0
    def initAlgorithm(self, config):
        # INPUTS
        db_param = QgsProcessingParameterString(
            self.DATABASE, tr("Connexion à la base de données"))
        db_param.setMetadata({
            "widget_wrapper": {
                "class":
                "processing.gui.wrappers_postgis.ConnectionWidgetWrapper"
            }
        })
        self.addParameter(db_param)

        schema_param = QgsProcessingParameterString(
            self.SCHEMA,
            tr("Schéma du cadastre contenant les données des parcelles est propriétaires"
               ), "cadastre", False, True)
        schema_param.setMetadata({
            "widget_wrapper": {
                "class": "processing.gui.wrappers_postgis.SchemaWidgetWrapper",
                "connection_param": self.DATABASE,
            }
        })
        self.addParameter(schema_param)

        self.addParameter(
            QgsProcessingParameterBoolean(
                self.TRUNCATE_PARCELLE,
                tr("Mise à jour de la table parcelle")))

        # OUTPUTS
        self.addOutput(
            QgsProcessingOutputMultipleLayers(self.OUTPUT,
                                              tr("Couches de sortie")))

        self.addOutput(
            QgsProcessingOutputString(self.OUTPUT_MSG,
                                      tr("Message de sortie")))
Beispiel #15
0
def test_output_multiple_layers(outputdir, data):
    """ Test QgsProcessingOutputMultipleLayers
    """
    outdef = QgsProcessingOutputMultipleLayers("LAYERS")

    # Load source project
    layer1 = str(data / 'france_parts' / 'france_parts.shp')
    layer2 = str(data / 'raster_layer.tiff')

    context = QgsProcessingContext()
    context.wms_url = 'test:multilayer?service=WMS'

    outp = parse_output_definition(outdef)
    output = processing_to_output([layer1, layer2],
                                  outdef,
                                  outp,
                                  context=context)

    assert isinstance(output, ComplexOutput)
    assert output.as_reference
    assert output.data_format.mime_type == 'application/x-ogc-wms'

    query = parse_qs(urlparse(output.url).query)
    assert query['layers'][0] == 'france_parts,raster_layer'
Beispiel #16
0
 def initAlgorithm(self, config):
     """
     Parameter setting.
     """
     self.addParameter(
         QgsProcessingParameterMultipleLayers(
             self.INPUT_LAYERS,
             self.tr('Input Layers'),
             QgsProcessing.TypeVector
         )
     )
     self.addParameter(
         QgsProcessingParameterExpression(
             self.CATEGORY_EXPRESSION,
             self.tr('Expression used to find out the category'),
             defaultValue="regexp_substr(@layer_name ,'([^_]+)')"
         )
     )
     self.addOutput(
         QgsProcessingOutputMultipleLayers(
             self.OUTPUT,
             self.tr('Original reorganized layers')
         )
     )
Beispiel #17
0
 def initAlgorithm(self, config=None):
     self.addParameter(
         QgsProcessingParameterMultipleLayers(
             'INPUT',
             'Input rasters',
             layerType=QgsProcessing.TypeRaster,
             defaultValue=None))
     self.addParameter(
         QgsProcessingParameterVectorLayer(
             'Masklayer',
             'Mask layer',
             types=[QgsProcessing.TypeVectorPolygon],
             defaultValue=None))
     param = QgsProcessingParameterFile(
         'OUTFOLDER',
         'Folder to store clipped rasters',
         behavior=QgsProcessingParameterFile.Folder,
         defaultValue=None,
         optional=True)
     param.setFlags(param.flags()
                    | QgsProcessingParameterDefinition.FlagAdvanced)
     self.addParameter(param, createOutput=True)
     self.addOutput(
         QgsProcessingOutputMultipleLayers('OUTPUT', 'Clipped rasters'))
 def initAlgorithm(self, config):
     """
     Parameter setting.
     """
     self.addParameter(
         QgsProcessingParameterMultipleLayers(
             self.INPUT_LAYERS,
             self.tr('Input Layers'),
             QgsProcessing.TypeVector
         )
     )
     self.addParameter(
         QgsProcessingParameterBoolean(
                 self.START_EDITING,
                 self.tr('Start Editing'),
                 defaultValue=True
             )
         )
     self.addOutput(
         QgsProcessingOutputMultipleLayers(
             self.OUTPUT,
             self.tr('Original reorganized layers')
         )
     )
    def initAlgorithm(self, config):
        # INPUTS
        db_param = QgsProcessingParameterString(
            self.DATABASE, tr("Connexion à la base de données"))
        db_param.setMetadata({
            "widget_wrapper": {
                "class":
                "processing.gui.wrappers_postgis.ConnectionWidgetWrapper"
            }
        })
        db_param.tooltip_3liz = 'Nom de la connexion dans QGIS pour se connecter à la base de données'
        self.addParameter(db_param)

        schema_param = QgsProcessingParameterString(self.SCHEMA, tr("Schéma"),
                                                    "veloroutes", False, True)
        schema_param.setMetadata({
            "widget_wrapper": {
                "class": "processing.gui.wrappers_postgis.SchemaWidgetWrapper",
                "connection_param": self.DATABASE,
            }
        })
        schema_param.tooltip_3liz = 'Nom du schéma pour chercher les couches dans la base de données'
        self.addParameter(schema_param)

        self.addParameter(
            QgsProcessingParameterBoolean(
                self.RASTER,
                tr("Ajouter un fond raster OpenStreetMap?"),
                defaultValue=False,
                optional=False,
            ))

        # OUTPUTS
        output = QgsProcessingOutputMultipleLayers(self.OUTPUT,
                                                   tr("Couches de sortie"))
        output.tooltip_3liz = 'Les différentes couches de l\'extention véloroutes et voies vertes'
        self.addOutput(output)

        output = QgsProcessingOutputString(self.OUTPUT_MSG,
                                           tr("Message de sortie"))
        output.tooltip_3liz = output.description()
        self.addOutput(output)
Beispiel #20
0
    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)

        label = tr("Schéma")
        tooltip = 'Nom du schéma pour importer 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)

        self.addParameter(
            QgsProcessingParameterBoolean(
                self.RASTER,
                tr("Ajouter un fond raster OpenStreetMap ?"),
                defaultValue=False,
                optional=False,
            ))

        # OUTPUTS
        output = QgsProcessingOutputMultipleLayers(self.OUTPUT,
                                                   tr("Couches de sortie"))
        output.tooltip_3liz = 'Les différentes couches de l\'extension véloroutes et voies vertes'
        self.addOutput(output)

        output = QgsProcessingOutputString(self.OUTPUT_MSG,
                                           tr("Message de sortie"))
        output.tooltip_3liz = output.description()
        self.addOutput(output)
Beispiel #21
0
    def initAlgorithm(self, config):
        """
        Parameter setting.
        """
        self.addParameter(
            QgsProcessingParameterString(
                self.HOST,
                self.tr('Host')
            )
        )
        self.addParameter(
            QgsProcessingParameterString(
                self.PORT,
                self.tr('Port')
            )
        )
        self.addParameter(
            QgsProcessingParameterString(
                self.DATABASE,
                self.tr('Database')
            )
        )
        self.addParameter(
            QgsProcessingParameterString(
                self.USER,
                self.tr('User')
            )
        )
        self.addParameter(
            QgsProcessingParameterString(
                self.PASSWORD,
                self.tr('Password')
            )
        )
        self.addParameter(
            QgsProcessingParameterString(
                self.LAYER_LIST,
                self.tr('Layer List')
            )
        )
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.LOAD_TO_CANVAS,
                self.tr('Load layers to canvas'),
                defaultValue=True
            )
        )
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.UNIQUE_LOAD,
                self.tr('Unique load'),
                defaultValue=True
            )
        )

        self.addOutput(
            QgsProcessingOutputMultipleLayers(
                self.OUTPUT,
                self.tr('Loaded layers')
            )
        )