예제 #1
0
    def initAlgorithm(self, config=None):
        self.STATS = OrderedDict([(self.tr('Count'), QgsZonalStatistics.Count),
                                  (self.tr('Sum'), QgsZonalStatistics.Sum),
                                  (self.tr('Mean'), QgsZonalStatistics.Mean),
                                  (self.tr('Median'), QgsZonalStatistics.Median),
                                  (self.tr('Std. dev.'), QgsZonalStatistics.StDev),
                                  (self.tr('Min'), QgsZonalStatistics.Min),
                                  (self.tr('Max'), QgsZonalStatistics.Max),
                                  (self.tr('Range'), QgsZonalStatistics.Range),
                                  (self.tr('Minority'), QgsZonalStatistics.Minority),
                                  (self.tr('Majority (mode)'), QgsZonalStatistics.Majority),
                                  (self.tr('Variety'), QgsZonalStatistics.Variety),
                                  (self.tr('Variance'), QgsZonalStatistics.Variance),
                                  (self.tr('All'), QgsZonalStatistics.All)])

        self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT_RASTER,
                                                            self.tr('Raster layer')))
        self.addParameter(QgsProcessingParameterBand(self.RASTER_BAND,
                                                     self.tr('Raster band'),
                                                     1,
                                                     self.INPUT_RASTER))
        self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT_VECTOR,
                                                            self.tr('Vector layer containing zones'),
                                                            [QgsProcessing.TypeVectorPolygon]))
        self.addParameter(QgsProcessingParameterString(self.COLUMN_PREFIX,
                                                       self.tr('Output column prefix'), '_'))
        keys = list(self.STATS.keys())
        self.addParameter(QgsProcessingParameterEnum(self.STATISTICS,
                                                     self.tr('Statistics to calculate'),
                                                     keys,
                                                     allowMultiple=True, defaultValue=[0, 1, 2]))
        self.addOutput(QgsProcessingOutputVectorLayer(self.INPUT_VECTOR,
                                                      self.tr('Zonal statistics'),
                                                      QgsProcessing.TypeVectorPolygon))

        self.bandNumber = None
        self.columnPrefix = None
        self.selectedStats = None
        self.vectorLayer = None
        self.rasterLayer = None
예제 #2
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('Input layer'),
                                           [QgsProcessing.TypeVector]))
     self.addParameter(
         QgsProcessingParameterField(
             self.INPUT_FIELD,
             self.tr('Input field name'),
             parentLayerParameterName='INPUT',
             type=QgsProcessingParameterField.Numeric))
     self.addParameter(
         QgsProcessingParameterString(self.NEW_FIELD_NAME,
                                      self.tr('New field name'),
                                      defaultValue='new_field'))
     self.addOutput(
         QgsProcessingOutputVectorLayer(self.OUTPUT,
                                        self.tr('Output layer')))
예제 #3
0
    def initAlgorithm(self, config=None):
        self.operators = [
            '=', '≠', '>', '>=', '<', '<=',
            self.tr('begins with'),
            self.tr('contains'),
            self.tr('is null'),
            self.tr('is not null'),
            self.tr('does not contain')
        ]

        self.methods = [
            self.tr('creating new selection'),
            self.tr('adding to current selection'),
            self.tr('removing from current selection'),
            self.tr('selecting within current selection')
        ]

        self.addParameter(
            QgsProcessingParameterVectorLayer(self.INPUT,
                                              self.tr('Input layer'),
                                              types=[QgsProcessing.TypeVector
                                                     ]))
        self.addParameter(
            QgsProcessingParameterField(self.FIELD,
                                        self.tr('Selection attribute'),
                                        parentLayerParameterName=self.INPUT))
        self.addParameter(
            QgsProcessingParameterEnum(self.OPERATOR, self.tr('Operator'),
                                       self.operators))
        self.addParameter(
            QgsProcessingParameterString(self.VALUE, self.tr('Value')))
        self.addParameter(
            QgsProcessingParameterEnum(self.METHOD,
                                       self.tr('Modify current selection by'),
                                       self.methods, 0))

        self.addOutput(
            QgsProcessingOutputVectorLayer(self.OUTPUT,
                                           self.tr('Selected (attribute)')))
예제 #4
0
    def initAlgorithm(self, config=None):
        self.methods = [
            self.tr('Number of selected features'),
            self.tr('Percentage of selected features')
        ]

        self.addParameter(
            QgsProcessingParameterVectorLayer(self.INPUT,
                                              self.tr('Input layer')))
        self.addParameter(
            QgsProcessingParameterField(self.FIELD, self.tr('ID field'), None,
                                        self.INPUT))
        self.addParameter(
            QgsProcessingParameterEnum(self.METHOD, self.tr('Method'),
                                       self.methods, False, 0))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.NUMBER, self.tr('Number/percentage of selected features'),
                QgsProcessingParameterNumber.Integer, 10, False, 0.0))
        self.addOutput(
            QgsProcessingOutputVectorLayer(
                self.OUTPUT, self.tr('Selected (stratified random)')))
예제 #5
0
 def initAlgorithm(self, config=None):
     db_param = QgsProcessingParameterProviderConnection(
         self.DATABASE,
         self.tr('Database (connection name)'), 'postgres')
     self.addParameter(db_param)
     self.addParameter(QgsProcessingParameterString(
         self.SQL,
         self.tr('SQL query'),
         multiLine=True))
     self.addParameter(QgsProcessingParameterString(
         self.ID_FIELD,
         self.tr('Unique ID field name'),
         defaultValue='id'))
     self.addParameter(QgsProcessingParameterString(
         self.GEOMETRY_FIELD,
         self.tr('Geometry field name'),
         defaultValue='geom',
         optional=True))
     self.addOutput(QgsProcessingOutputVectorLayer(
         self.OUTPUT,
         self.tr("Output layer"),
         QgsProcessing.TypeVectorAnyGeometry))
    def initAlgorithm(self, config):
        """
        Parameter setting.
        """
        self.addParameter(
            QgsProcessingParameterVectorLayer(
                self.INPUT, self.tr('Input layer'),
                [QgsProcessing.TypeVectorAnyGeometry]))

        self.addParameter(
            QgsProcessingParameterBoolean(
                self.SELECTED, self.tr('Process only selected features')))

        self.addParameter(
            QgsProcessingParameterNumber(self.TOLERANCE,
                                         self.tr('Area tolerance'),
                                         minValue=0,
                                         defaultValue=625))

        self.addOutput(
            QgsProcessingOutputVectorLayer(
                self.OUTPUT, self.tr('Original layer without small polygons')))
예제 #7
0
파일: ConcaveHull.py 프로젝트: mkhoin/QGIS
    def __init__(self):
        super().__init__()

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.INPUT, self.tr('Input point layer'),
                [QgsProcessing.TypeVectorPoint]))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.ALPHA,
                self.tr(
                    'Threshold (0-1, where 1 is equivalent with Convex Hull)'),
                minValue=0,
                maxValue=1,
                defaultValue=0.3,
                type=QgsProcessingParameterNumber.Double))

        self.addParameter(
            QgsProcessingParameterBoolean(self.HOLES,
                                          self.tr('Allow holes'),
                                          defaultValue=True))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.NO_MULTIGEOMETRY,
                self.tr(
                    'Split multipart geometry into singleparts geometries'),
                defaultValue=False))

        self.addParameter(
            QgsProcessingParameterFeatureSink(
                self.OUTPUT,
                self.tr('Concave hull'),
                type=QgsProcessing.TypeVectorPolygon))
        self.addOutput(
            QgsProcessingOutputVectorLayer(
                self.OUTPUT,
                self.tr("Concave hull"),
                type=QgsProcessing.TypeVectorPolygon))
예제 #8
0
    def initAlgorithm(self, config=None):
        self.i18n_operators = ['=',
                               '!=',
                               '>',
                               '>=',
                               '<',
                               '<=',
                               self.tr('begins with'),
                               self.tr('contains'),
                               self.tr('is null'),
                               self.tr('is not null'),
                               self.tr('does not contain')
                               ]

        self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT, self.tr('Input layer'), types=[QgsProcessing.TypeVector]))

        self.addParameter(QgsProcessingParameterField(self.FIELD,
                                                      self.tr('Selection attribute'), parentLayerParameterName=self.INPUT))
        self.addParameter(QgsProcessingParameterEnum(self.OPERATOR,
                                                     self.tr('Operator'), self.i18n_operators))
        self.addParameter(QgsProcessingParameterString(self.VALUE, self.tr('Value')))

        self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Selected (attribute)')))
 def initAlgorithm(self, config):
     """
     Parameter setting.
     """
     self.addParameter(
         QgsProcessingParameterVectorLayer(
             self.INPUT,
             self.tr('Input layer'),
             [QgsProcessing.TypeVectorAnyGeometry]
         )
     )
     self.addParameter(
         QgsProcessingParameterBoolean(
             self.SELECTED,
             self.tr('Process only selected features')
         )
     )
     self.addParameter(
         QgsProcessingParameterBoolean(
             self.TYPE,
             self.tr('Fix input geometries'),
             defaultValue=False
         )
     )
     self.addParameter(
         QgsProcessingParameterFeatureSink(
             self.FLAGS,
             self.tr('{0} Flags').format(self.displayName())
         )
     )
     self.addOutput(
         QgsProcessingOutputVectorLayer(
             self.OUTPUT,
             self.tr('Original layer (has fixed geometries if fix mode is chosen)')
         )
     )
 def initAlgorithm(self, config=None):
     self.addParameter(
         QgsProcessingParameterFeatureSource(
             self.INPUT_POLYGONS, self.tr("Input polygon layer"),
             [QgsProcessing.TypeVectorPolygon]))
     self.addParameter(
         QgsProcessingParameterVectorLayer(
             self.INPUT_ADDITIONAL, self.tr("Additional input layer"),
             [QgsProcessing.TypeVectorAnyGeometry]))
     self.addParameter(
         QgsProcessingParameterField(
             self.VALUE_FIELD,
             self.tr("Attribute field"),
             parentLayerParameterName=self.INPUT_ADDITIONAL,
             type=0,
             optional=False))
     self.vals = [self.tr("Maximum"), self.tr("Minimum")]
     self.addParameter(
         QgsProcessingParameterEnum(self.M_VAL,
                                    self.tr("Select Value"),
                                    options=self.vals,
                                    defaultValue=0))
     self.methods = [
         self.tr('creating new selection'),
         self.tr('adding to current selection'),
         self.tr('removing from current selection'),
         self.tr('selecting within current selection')
     ]
     self.addParameter(
         QgsProcessingParameterEnum(self.METHOD,
                                    self.tr('Modify current selection by'),
                                    options=self.methods,
                                    defaultValue=0))
     self.addOutput(
         QgsProcessingOutputVectorLayer(self.OUTPUT,
                                        self.tr('Selected (attribute)')))
예제 #11
0
 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(
         QgsProcessingParameterNumber(self.MIN_AREA,
                                      self.tr('Max dissolve area'),
                                      minValue=0,
                                      optional=True))
     self.addParameter(
         QgsProcessingParameterField(self.ATTRIBUTE_BLACK_LIST,
                                     self.tr('Fields to ignore'),
                                     None,
                                     'INPUT',
                                     QgsProcessingParameterField.Any,
                                     allowMultiple=True,
                                     optional=True))
     self.addParameter(
         QgsProcessingParameterBoolean(self.IGNORE_VIRTUAL_FIELDS,
                                       self.tr('Ignore virtual fields'),
                                       defaultValue=True))
     self.addParameter(
         QgsProcessingParameterBoolean(self.IGNORE_PK_FIELDS,
                                       self.tr('Ignore primary key fields'),
                                       defaultValue=True))
     self.addOutput(
         QgsProcessingOutputVectorLayer(
             self.OUTPUT,
             self.tr('Original layer with dissolved polygons')))
예제 #12
0
    def __init__(self):
        super().__init__()
        self.addParameter(
            QgsProcessingParameterExtent(self.EXTENT,
                                         self.tr('Input extent'),
                                         optional=False))
        self.addParameter(
            QgsProcessingParameterNumber(self.SPACING,
                                         self.tr('Point spacing/count'),
                                         QgsProcessingParameterNumber.Double,
                                         100, False, 0.000001,
                                         999999999.999999999))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.INSET, self.tr('Initial inset from corner (LH side)'),
                QgsProcessingParameterNumber.Double, 0.0, False, 0.0,
                9999.9999))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.RANDOMIZE,
                self.tr('Apply random offset to point spacing'), False))
        self.addParameter(
            QgsProcessingParameterBoolean(self.IS_SPACING,
                                          self.tr('Use point spacing'), True))
        self.addParameter(
            QgsProcessingParameterCrs(self.CRS, self.tr('Output layer CRS'),
                                      'ProjectCrs'))

        self.addParameter(
            QgsProcessingParameterFeatureSink(self.OUTPUT,
                                              self.tr('Regular points'),
                                              QgsProcessing.TypeVectorPoint))
        self.addOutput(
            QgsProcessingOutputVectorLayer(self.OUTPUT,
                                           self.tr('Regular points'),
                                           QgsProcessing.TypeVectorPoint))
예제 #13
0
    def initAlgorithm(self, config):
        """
        Parameter setting.
        """
        self.addParameter(
            QgsProcessingParameterVectorLayer(
                self.INPUT,
                self.tr('Input layer'),
                [QgsProcessing.TypeVectorAnyGeometry]
            )
        )

        self.addParameter(
            QgsProcessingParameterBoolean(
                self.SELECTED,
                self.tr('Process only selected features')
            )
        )

        self.addOutput(QgsProcessingOutputVectorLayer(
            self.INPUT,
            self.tr('Original layer updated')
            )
        )
    def initAlgorithm(self,
                      configuration,
                      p_str=None,
                      Any=None,
                      *args,
                      **kwargs):
        providers = [provider['name'] for provider in self.providers]
        self.addParameter(
            QgsProcessingParameterEnum(self.IN_PROVIDER,
                                       "Provider",
                                       providers,
                                       defaultValue=providers[0]))

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                name=self.IN_POINTS,
                description="Input Point layer",
                types=[QgsProcessing.TypeVectorPoint]))

        self.addParameter(
            QgsProcessingParameterField(
                name=self.IN_FIELD,
                description="Input layer ID Field",
                parentLayerParameterName=self.IN_POINTS))
        self.addParameter(
            QgsProcessingParameterEnum(self.IN_MODE,
                                       'Mode',
                                       options=self.MODE_TYPES,
                                       defaultValue=self.MODE_TYPES[0]))

        self.addParameter(
            QgsProcessingParameterString(
                name=self.IN_INTERVALS_TIME,
                description="Comma-separated time intervals [mins]",
                defaultValue="5,10",
                optional=True))

        self.addParameter(
            QgsProcessingParameterString(
                name=self.IN_INTERVALS_DISTANCE,
                description="Comma-separated distance intervals [km]",
                defaultValue="5,10",
                optional=True))

        self.addParameter(
            QgsProcessingParameterBoolean(
                name=self.IN_SHOW_LOCATIONS,
                description="Return input locations as (Multi)Point",
                defaultValue=False))

        self.addParameter(
            QgsProcessingParameterString(
                name=self.IN_DENOISE,
                description="Denoise parameter (0.0-1.0)",
                optional=True))

        self.addParameter(
            QgsProcessingParameterString(
                name=self.IN_GENERALIZE,
                description="Generalize parameter for Douglas-Peucker",
                optional=True))

        self.addParameter(
            QgsProcessingParameterEnum(name=self.IN_GEOMETRY,
                                       options=self.GEOMETRY_TYPES,
                                       defaultValue=self.GEOMETRY_TYPES[0],
                                       description="Output geometry type",
                                       optional=True))

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                name=self.IN_AVOID,
                description="Point layer with locations to avoid",
                types=[QgsProcessing.TypeVectorPoint],
                optional=True))

        advanced = self.costing_options.get_costing_params()

        for p in advanced:
            p.setFlags(p.flags()
                       | QgsProcessingParameterDefinition.FlagAdvanced)
            self.addParameter(p)

        self.addOutput(
            QgsProcessingOutputVectorLayer(
                name=self.OUT_TIME,
                description="Isochrones " + self.PROFILE,
                type=QgsProcessing.TypeVectorAnyGeometry))

        self.addOutput(
            QgsProcessingOutputVectorLayer(
                name=self.OUT_DISTANCE,
                description="Isodistances " + self.PROFILE,
                type=QgsProcessing.TypeVectorAnyGeometry))

        self.addOutput(
            QgsProcessingOutputVectorLayer(
                name=self.POINTS_SNAPPED,
                description="",
                type=QgsProcessing.TypeVectorAnyGeometry))

        self.addOutput(
            QgsProcessingOutputVectorLayer(
                name=self.POINTS_INPUT,
                description="",
                type=QgsProcessing.TypeVectorAnyGeometry))
예제 #15
0
    def initAlgorithm(self, config):

        # Base contenant la table
        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 contenant la table
        schema_param = QgsProcessingParameterString(self.SCHEMA, tr("Schéma"),
                                                    "veloroutes", False, False)
        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)

        # 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)
 def initAlgorithm(self, config=None):
     self.addParameter(
         QgsProcessingParameterFeatureSource(
             self.INPUT,
             QCoreApplication.translate("AppendFeaturesToLayer",
                                        'Source layer'),
             [QgsProcessing.TypeVector]))
     self.addParameter(
         QgsProcessingParameterField(self.INPUT_FIELD,
                                     QCoreApplication.translate(
                                         "AppendFeaturesToLayer",
                                         'Source field to compare'),
                                     None,
                                     self.INPUT,
                                     optional=True))
     self.addParameter(
         QgsProcessingParameterVectorLayer(
             self.OUTPUT,
             QCoreApplication.translate("AppendFeaturesToLayer",
                                        'Target layer'),
             [QgsProcessing.TypeVector]))
     self.addParameter(
         QgsProcessingParameterField(self.OUTPUT_FIELD,
                                     QCoreApplication.translate(
                                         "AppendFeaturesToLayer",
                                         'Target field to compare'),
                                     None,
                                     self.OUTPUT,
                                     optional=True))
     self.addParameter(
         QgsProcessingParameterEnum(
             self.ACTION_ON_DUPLICATE,
             QCoreApplication.translate("AppendFeaturesToLayer",
                                        'Action for duplicate features'),
             [
                 self.NO_ACTION_TEXT, self.SKIP_FEATURE_TEXT,
                 self.UPDATE_EXISTING_FEATURE_TEXT
             ],
             False,
             self.NO_ACTION_TEXT,
             optional=False))
     self.addOutput(
         QgsProcessingOutputVectorLayer(
             self.OUTPUT,
             QCoreApplication.translate(
                 "AppendFeaturesToLayer",
                 "Target layer to paste new features")))
     self.addOutput(
         QgsProcessingOutputNumber(
             self.APPENDED_COUNT,
             QCoreApplication.translate("AppendFeaturesToLayer",
                                        "Number of features appended")))
     self.addOutput(
         QgsProcessingOutputNumber(
             self.UPDATED_COUNT,
             QCoreApplication.translate("AppendFeaturesToLayer",
                                        "Number of features updated")))
     self.addOutput(
         QgsProcessingOutputNumber(
             self.SKIPPED_COUNT,
             QCoreApplication.translate("AppendFeaturesToLayer",
                                        "Number of features skipped")))
예제 #17
0
def create_output_from_token(name: str, description: str, token: str):  # pylint: disable=too-many-branches
    """
    Creates an output (or destination parameter) definition from a token string
    """
    no_prompt = False
    if 'noprompt' in token:
        no_prompt = True
        token = token.replace(' noprompt', '')

    output_type = token.lower().strip()

    out = None
    if output_type.startswith('vector'):
        vector_type = QgsProcessing.TypeVectorAnyGeometry
        if output_type == 'vector point':
            vector_type = QgsProcessing.TypeVectorPoint
        elif output_type == 'vector line':
            vector_type = QgsProcessing.TypeVectorLine
        elif output_type == 'vector polygon':
            vector_type = QgsProcessing.TypeVectorPolygon
        if no_prompt:
            out = QgsProcessingOutputVectorLayer(name, description,
                                                 vector_type)
        else:
            out = QgsProcessingParameterVectorDestination(name,
                                                          description,
                                                          type=vector_type)
    elif output_type.startswith('table'):
        if no_prompt:
            out = QgsProcessingOutputVectorLayer(name, description,
                                                 QgsProcessing.TypeVector)
        else:
            out = QgsProcessingParameterVectorDestination(
                name, description, type=QgsProcessing.TypeVector)
    elif output_type == 'multilayers':
        # 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('file'):
        #                out = OutputFile()
        #                ext = token.strip()[len('file') + 1:]
        #                if ext:
        #                    out.ext = ext
        #            elif token.lower().strip().startswith('extent'):
        #                out = OutputExtent()
        pass
    elif not no_prompt:
        if output_type.startswith('raster'):
            out = QgsProcessingParameterRasterDestination(name, description)
        elif output_type.startswith('folder'):
            out = QgsProcessingParameterFolderDestination(name, description)
        elif output_type.startswith('html'):
            out = QgsProcessingParameterFileDestination(
                name, description, 'HTML Files (*.html)')
    if not out and output_type in OUTPUT_FACTORY:
        return OUTPUT_FACTORY[output_type](name, description)

    return out
예제 #18
0
파일: DropGeometry.py 프로젝트: arx-it/QGIS
    def __init__(self):
        super().__init__()

        self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT_LAYER, self.tr('Input layer'), [QgsProcessingParameterDefinition.TypeVectorPoint, QgsProcessingParameterDefinition.TypeVectorLine, QgsProcessingParameterDefinition.TypeVectorPolygon]))
        self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT_TABLE, self.tr('Dropped geometry')))
        self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT_TABLE, self.tr("Dropped geometry")))
예제 #19
0
    def initAlgorithm(self, config=None):
        param = QgsProcessingParameterFile(self.FILE, self.tr('OSM file'))
        help_string = tr('The extension can be a OSM or PBF file.')
        if Qgis.QGIS_VERSION_INT >= 31500:
            param.setHelp(help_string)
        else:
            param.tooltip_3liz = help_string
        self.addParameter(param)

        param = QgsProcessingParameterFile(self.OSM_CONF,
                                           self.tr('OSM configuration'),
                                           optional=True)
        help_string = tr(
            'The OGR OSM configuration file. This file is used to customize the import process about OSM '
            'tags. You should read the OGR documentation {url}').format(
                url='https://gdal.org/drivers/vector/osm.html')
        if Qgis.QGIS_VERSION_INT >= 31500:
            param.setHelp(help_string)
        else:
            param.tooltip_3liz = help_string
        self.addParameter(param)

        output = QgsProcessingOutputVectorLayer(self.OUTPUT_POINTS,
                                                self.tr('Output points'),
                                                QgsProcessing.TypeVectorPoint)
        help_string = tr('The point layer from the OGR OSM driver.')
        if Qgis.QGIS_VERSION_INT >= 31500:
            pass
            # output.setHelp(help_string)
        else:
            output.tooltip_3liz = help_string
        self.addOutput(output)

        output = QgsProcessingOutputVectorLayer(self.OUTPUT_LINES,
                                                self.tr('Output lines'),
                                                QgsProcessing.TypeVectorLine)
        help_string = tr('The line layer from the OGR OSM driver.')
        if Qgis.QGIS_VERSION_INT >= 31500:
            pass
            # output.setHelp(help_string)
        else:
            output.tooltip_3liz = help_string
        self.addOutput(output)

        output = QgsProcessingOutputVectorLayer(
            self.OUTPUT_MULTILINESTRINGS, self.tr('Output multilinestrings'),
            QgsProcessing.TypeVectorLine)
        help_string = tr('The multilinestrings layer from the OGR OSM driver.')
        if Qgis.QGIS_VERSION_INT >= 31500:
            pass
            # output.setHelp(help_string)
        else:
            output.tooltip_3liz = help_string
        self.addOutput(output)

        output = QgsProcessingOutputVectorLayer(
            self.OUTPUT_MULTIPOLYGONS, self.tr('Output multipolygons'),
            QgsProcessing.TypeVectorPolygon)
        help_string = tr('The multipolygon layer from the OGR OSM driver.')
        if Qgis.QGIS_VERSION_INT >= 31500:
            pass
            # output.setHelp(help_string)
        else:
            output.tooltip_3liz = help_string
        self.addOutput(output)

        output = QgsProcessingOutputVectorLayer(
            self.OUTPUT_OTHER_RELATIONS, self.tr('Output other relations'),
            QgsProcessing.TypeVector)
        help_string = tr('The relation layer from the OGR OSM driver.')
        if Qgis.QGIS_VERSION_INT >= 31500:
            pass
            # output.setHelp(help_string)
        else:
            output.tooltip_3liz = help_string
        self.addOutput(output)
예제 #20
0
class FixNetworkAlgorithm(ValidationAlgorithm):
    INPUT = 'INPUT'
    SELECTED = 'SELECTED'
    TOLERANCE = 'TOLERANCE'
    ATTRIBUTE_BLACK_LIST = 'ATTRIBUTE_BLACK_LIST'
    IGNORE_VIRTUAL_FIELDS = 'IGNORE_VIRTUAL_FIELDS'
    IGNORE_PK_FIELDS = 'IGNORE_PK_FIELDS'
    OUTPUT = 'OUTPUT'

    def initAlgorithm(self, config):
        """
        Parameter setting.
        """
         self.addParameter(
            QgsProcessingParameterVectorLayer(
                self.INPUT,
                self.tr('Input layer'),
                [QgsProcessing.TypeVectorLine ]
            )
        )
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.SELECTED,
                self.tr('Process only selected features')
            )
        )
        self.addParameter(
            QgsProcessingParameterDistance(
                self.TOLERANCE,
                self.tr('Topology radius'),
                parentParameterName=self.INPUT,
                minValue=0,
                defaultValue=1.0
            )
        )
        self.addParameter(
            QgsProcessingParameterField(
                self.ATTRIBUTE_BLACK_LIST, 
                self.tr('Fields to ignore'),
                None, 
                'INPUT', 
                QgsProcessingParameterField.Any,
                allowMultiple=True,
                optional = True
            )
        )
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.IGNORE_VIRTUAL_FIELDS,
                self.tr('Ignore virtual fields'),
                defaultValue=True
            )
        )
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.IGNORE_PK_FIELDS,
                self.tr('Ignore primary key fields'),
                defaultValue=True
            )
        )
        self.addOutput(
            QgsProcessingOutputVectorLayer(
                self.OUTPUT,
                self.tr('Original layer with merged lines')
            )
        )
예제 #21
0
 def __init__(self):
     super().__init__()
     self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), [QgsProcessingParameterDefinition.TypeVectorLine, QgsProcessingParameterDefinition.TypeVectorPolygon]))
     self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Fixed geometries')))
     self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr("Fixed geometries")))
예제 #22
0
    def __init__(self):
        super().__init__()

        self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT_LAYER, self.tr('Input layer')))
        self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT_LAYER, self.tr('Bounds'), QgsProcessingParameterDefinition.TypeVectorPolygon))
        self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT_LAYER, self.tr("Bounds")))
예제 #23
0
 def initAlgorithm(self, config=None):
     self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT,
                                                         self.tr('Input Layer')))
     self.addParameter(QgsProcessingParameterField(self.FIELD,
                                                   self.tr('Attribute to index'), None, self.INPUT))
     self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Indexed layer')))
예제 #24
0
    def __init__(self):
        super().__init__()

        self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), [QgsProcessing.TypeVectorPoint]))
        self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Delaunay triangulation'), type=QgsProcessing.TypeVectorPolygon))
        self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr("Delaunay triangulation"), type=QgsProcessing.TypeVectorPolygon))
예제 #25
0
 def initAlgorithm(self, config=None):
     self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT,
                                                         self.tr('Input Layer'), types=[QgsProcessing.TypeVectorAnyGeometry]))
     self.addParameter(QgsProcessingParameterCrs(self.CRS, 'Output CRS'))
     self.addOutput(QgsProcessingOutputVectorLayer(self.INPUT,
                                                   self.tr('Layer with projection')))
예제 #26
0
    def initAlgorithm(self, config=None):
        """
        Here we define the inputs and output of the algorithm, along
        with some other properties.
        """

        self.db_variables = QgsSettings()
        self.period_variables = ["Pas de filtre temporel", "5 dernières années", "10 dernières années", "Date de début - Date de fin (à définir ci-dessous)"]

        # Data base connection
        db_param = QgsProcessingParameterString(
            self.DATABASE,
            self.tr("""<b style="color:#0a84db">CONNEXION À LA BASE DE DONNÉES</b><br/>
                <b>*1/</b> Sélectionnez votre <u>connexion</u> à la base de données LPO AuRA (<i>gnlpoaura</i>)"""),
            defaultValue='gnlpoaura'
        )
        db_param.setMetadata(
            {
                'widget_wrapper': {'class': 'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'}
            }
        )
        self.addParameter(db_param)

        # Input vector layer = study area
        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.STUDY_AREA,
                self.tr("""<b style="color:#0a84db">ZONE D'ÉTUDE</b><br/>
                    <b>*2/</b> Sélectionnez votre <u>zone d'étude</u>, à partir de laquelle seront extraits les résultats"""),
                [QgsProcessing.TypeVectorPolygon]
            )
        )

        ### Taxons filters ###
        self.addParameter(
            QgsProcessingParameterEnum(
                self.GROUPE_TAXO,
                self.tr("""<b style="color:#0a84db">FILTRES DE REQUÊTAGE</b><br/>
                    <b>3/</b> Si cela vous intéresse, vous pouvez sélectionner un/plusieurs <u>taxon(s)</u> dans la liste déroulante suivante (à choix multiples)<br/> pour filtrer vos données d'observations. <u>Sinon</u>, vous pouvez ignorer cette étape.<br/>
                    <i style="color:#952132"><b>N.B.</b> : D'autres filtres taxonomiques sont disponibles dans les paramètres avancés (tout en bas).</i><br/>
                    - Groupes taxonomiques :"""),
                self.db_variables.value("groupe_taxo"),
                allowMultiple=True,
                optional=True
            )
        )

        regne = QgsProcessingParameterEnum(
            self.REGNE,
            self.tr("- Règnes :"),
            self.db_variables.value("regne"),
            allowMultiple=True,
            optional=True
        )
        regne.setFlags(regne.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(regne)

        phylum = QgsProcessingParameterEnum(
            self.PHYLUM,
            self.tr("- Phylum :"),
            self.db_variables.value("phylum"),
            allowMultiple=True,
            optional=True
        )
        phylum.setFlags(phylum.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(phylum)

        classe = QgsProcessingParameterEnum(
            self.CLASSE,
            self.tr("- Classe :"),
            self.db_variables.value("classe"),
            allowMultiple=True,
            optional=True
        )
        classe.setFlags(classe.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(classe)

        ordre = QgsProcessingParameterEnum(
            self.ORDRE,
            self.tr("- Ordre :"),
            self.db_variables.value("ordre"),
            allowMultiple=True,
            optional=True
        )
        ordre.setFlags(ordre.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(ordre)

        famille = QgsProcessingParameterEnum(
            self.FAMILLE,
            self.tr("- Famille :"),
            self.db_variables.value("famille"),
            allowMultiple=True,
            optional=True
        )
        famille.setFlags(famille.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(famille)

        group1_inpn = QgsProcessingParameterEnum(
            self.GROUP1_INPN,
            self.tr("- Groupe 1 INPN (regroupement vernaculaire du référentiel national - niveau 1) :"),
            self.db_variables.value("group1_inpn"),
            allowMultiple=True,
            optional=True
        )
        group1_inpn.setFlags(group1_inpn.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(group1_inpn)

        group2_inpn = QgsProcessingParameterEnum(
            self.GROUP2_INPN,
            self.tr("- Groupe 2 INPN (regroupement vernaculaire du référentiel national - niveau 2) :"),
            self.db_variables.value("group2_inpn"),
            allowMultiple=True,
            optional=True
        )
        group2_inpn.setFlags(group2_inpn.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(group2_inpn)

        ### Datetime filter ###
        period_type = QgsProcessingParameterEnum(
            self.PERIOD,
            self.tr("<b>*4/</b> Sélectionnez une <u>période</u> pour filtrer vos données d'observations"),
            self.period_variables,
            allowMultiple=False,
            optional=False
        )
        period_type.setMetadata(
            {
                'widget_wrapper': {
                    'useCheckBoxes': True,
                    'columns': len(self.period_variables)/2
                }
            }
        )
        self.addParameter(period_type)

        start_date = QgsProcessingParameterString(
            self.START_DATE,
            """- Date de début <i style="color:#952132">(nécessaire seulement si vous avez sélectionné l'option <b>Date de début - Date de fin</b>)</i> :""",
            defaultValue="",
            optional=True
        )
        start_date.setMetadata(
            {'widget_wrapper': {'class': DateTimeWidget}}
        )
        self.addParameter(start_date)

        end_date = QgsProcessingParameterString(
            self.END_DATE,
            """- Date de fin <i style="color:#952132">(nécessaire seulement si vous avez sélectionné l'option <b>Date de début - Date de fin</b>)</i> :""",
            optional=True
        )
        end_date.setMetadata(
            {'widget_wrapper': {'class': DateTimeWidget}}
        )
        self.addParameter(end_date)

        # Extra "where" conditions
        extra_where = QgsProcessingParameterString(
            self.EXTRA_WHERE,
            self.tr("""Vous pouvez ajouter des <u>conditions "where"</u> supplémentaires dans l'encadré suivant, en langage SQL <b style="color:#952132">(commencez par <i>and</i>)</b>"""),
            multiLine=True,
            optional=True
        )
        extra_where.setFlags(extra_where.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(extra_where)

        # Output PostGIS layer = summary table
        self.addOutput(
            QgsProcessingOutputVectorLayer(
                self.OUTPUT,
                self.tr('Couche en sortie'),
                QgsProcessing.TypeVectorAnyGeometry
            )
        )

        # Output PostGIS layer name
        self.addParameter(
            QgsProcessingParameterString(
                self.OUTPUT_NAME,
                self.tr("""<b style="color:#0a84db">PARAMÉTRAGE DES RESULTATS EN SORTIE</b><br/>
                    <b>*5/</b> Définissez un <u>nom</u> pour votre nouvelle couche PostGIS"""),
                self.tr("Tableau synthèse espèces")
            )
        )

        # Boolean : True = add the summary table in the DB ; False = don't
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.ADD_TABLE,
                self.tr("Enregistrer les résultats en sortie dans une nouvelle table PostgreSQL"),
                False
            )
        )
예제 #27
0
 def initAlgorithm(self, config=None):
     self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT,
                                                         self.tr('Input Layer')))
     self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Truncated layer')))
    def initAlgorithm(self, config):
        """
        Parameter setting.
        """
        self.addParameter(
            QgsProcessingParameterVectorLayer(
                self.INPUT, self.tr('Input Layer'),
                [QgsProcessing.TypeVectorPolygon]))

        self.addParameter(
            QgsProcessingParameterField(self.ATTRIBUTE_INDEX,
                                        self.tr('INOM Field'), None, 'INPUT',
                                        QgsProcessingParameterField.Any))

        self.addParameter(
            QgsProcessingParameterField(self.ATTRIBUTE_ID, self.tr('ID Field'),
                                        None, 'INPUT',
                                        QgsProcessingParameterField.Any))

        self.addParameter(
            QgsProcessingParameterNumber(
                self.ID_VALUE,
                self.tr('ID Field Value'),
                minValue=0,
                type=QgsProcessingParameterNumber.Integer,
                defaultValue=1))

        self.addParameter(
            QgsProcessingParameterNumber(
                self.CROSSES_X,
                self.tr('Number of horizontal crosses'),
                minValue=0,
                type=QgsProcessingParameterNumber.Integer,
                defaultValue=4))

        self.addParameter(
            QgsProcessingParameterNumber(
                self.CROSSES_Y,
                self.tr('Number of vertical crosses'),
                minValue=0,
                type=QgsProcessingParameterNumber.Integer,
                defaultValue=4))

        self.addParameter(
            QgsProcessingParameterNumber(
                self.SPACING,
                self.tr('UTM Grid Spacing'),
                minValue=0,
                type=QgsProcessingParameterNumber.Integer,
                defaultValue=4000))

        self.addParameter(
            QgsProcessingParameterNumber(
                self.MAP_SCALE,
                self.tr('Map scale (in thousands)'),
                minValue=0,
                type=QgsProcessingParameterNumber.Double,
                defaultValue=25))

        colorParameter = ParameterColor(self.COLOR,
                                        description=self.tr('Color'))
        colorParameter.setMetadata({
            'widget_wrapper':
            'DsgTools.gui.ProcessingUI.colorWidgetWrapper.ColorWidgetWrapper'
        })
        self.addParameter(colorParameter)

        fontParameter = ParameterFont(self.FONT,
                                      description=self.tr('Font of the label'))
        fontParameter.setMetadata({
            'widget_wrapper':
            'DsgTools.gui.ProcessingUI.fontWidgetWrapper.FontWidgetWrapper'
        })
        self.addParameter(fontParameter)

        self.addParameter(
            QgsProcessingParameterNumber(
                self.FONT_SIZE,
                self.tr('Font Size'),
                minValue=0,
                type=QgsProcessingParameterNumber.Double,
                defaultValue=1.5))

        fontParameter = ParameterFont(
            self.FONT_LL, description=self.tr('Font of the LatLong label'))
        fontParameter.setMetadata({
            'widget_wrapper':
            'DsgTools.gui.ProcessingUI.fontWidgetWrapper.FontWidgetWrapper'
        })
        self.addParameter(fontParameter)

        colorParameter = ParameterColor(self.COLOR_LL,
                                        description=self.tr('Lat Long Color'))
        colorParameter.setMetadata({
            'widget_wrapper':
            'DsgTools.gui.ProcessingUI.colorWidgetWrapper.ColorWidgetWrapper'
        })
        self.addParameter(colorParameter)

        self.addOutput(
            QgsProcessingOutputVectorLayer(
                self.OUTPUT, self.tr('Original layer with assigned styles')))
예제 #29
0
 def initAlgorithm(self, config=None):
     self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT,
                                                         self.tr('Input Layer'),
                                                         [QgsProcessing.TypeVectorPolygon, QgsProcessing.TypeVectorPoint, QgsProcessing.TypeVectorLine]))
     self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Indexed layer')))
예제 #30
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)

        # 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)