Beispiel #1
0
    def initAlgorithm(self, config=None):

        self.addParameter(ParameterInterpolationData(self.INTERPOLATION_DATA,
                                                     self.tr('Input layer(s)')))
        self.addParameter(QgsProcessingParameterNumber(self.DISTANCE_COEFFICIENT,
                                                       self.tr('Distance coefficient P'), type=QgsProcessingParameterNumber.Double,
                                                       minValue=0.0, maxValue=99.99, defaultValue=2.0))
        self.addParameter(QgsProcessingParameterExtent(self.EXTENT,
                                                       self.tr('Extent'),
                                                       optional=False))
        pixel_size_param = ParameterPixelSize(self.PIXEL_SIZE,
                                              self.tr('Output raster size'),
                                              layersData=self.INTERPOLATION_DATA,
                                              extent=self.EXTENT,
                                              minValue=0.0,
                                              default=0.1)
        self.addParameter(pixel_size_param)

        cols_param = QgsProcessingParameterNumber(self.COLUMNS,
                                                  self.tr('Number of columns'),
                                                  optional=True,
                                                  minValue=0, maxValue=10000000)
        cols_param.setFlags(cols_param.flags() | QgsProcessingParameterDefinition.FlagHidden)
        self.addParameter(cols_param)

        rows_param = QgsProcessingParameterNumber(self.ROWS,
                                                  self.tr('Number of rows'),
                                                  optional=True,
                                                  minValue=0, maxValue=10000000)
        rows_param.setFlags(rows_param.flags() | QgsProcessingParameterDefinition.FlagHidden)
        self.addParameter(rows_param)

        self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                                  self.tr('Interpolated')))
Beispiel #2
0
    def initAlgorithm(self, config=None):
        self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT,
                                                            self.tr('Input layer')))
        self.addParameter(QgsProcessingParameterBand(self.BAND,
                                                     self.tr('Band number'),
                                                     1,
                                                     parentLayerParameterName=self.INPUT))
        self.addParameter(QgsProcessingParameterNumber(self.INTERVAL,
                                                       self.tr('Interval between contour lines'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       minValue=0.0,
                                                       defaultValue=10.0))
        self.addParameter(QgsProcessingParameterString(self.FIELD_NAME,
                                                       self.tr('Attribute name (if not set, no elevation attribute is attached)'),
                                                       defaultValue='ELEV',
                                                       optional=True))

        create_3d_param = QgsProcessingParameterBoolean(self.CREATE_3D,
                                                        self.tr('Produce 3D vector'),
                                                        defaultValue=False)
        create_3d_param.setFlags(create_3d_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(create_3d_param)

        ignore_nodata_param = QgsProcessingParameterBoolean(self.IGNORE_NODATA,
                                                            self.tr('Treat all raster values as valid'),
                                                            defaultValue=False)
        ignore_nodata_param.setFlags(ignore_nodata_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(ignore_nodata_param)

        nodata_param = QgsProcessingParameterNumber(self.NODATA,
                                                    self.tr('Input pixel value to treat as "nodata"'),
                                                    type=QgsProcessingParameterNumber.Double,
                                                    defaultValue=None,
                                                    optional=True)
        nodata_param.setFlags(nodata_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(nodata_param)

        offset_param = QgsProcessingParameterNumber(self.OFFSET,
                                                    self.tr('Offset from zero relative to which to interpret intervals'),
                                                    type=QgsProcessingParameterNumber.Double,
                                                    defaultValue=0.0,
                                                    optional=True)
        nodata_param.setFlags(offset_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(offset_param)

        options_param = QgsProcessingParameterString(self.OPTIONS,
                                                     self.tr('Additional creation options'),
                                                     defaultValue='',
                                                     optional=True)
        options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(options_param)

        self.addParameter(QgsProcessingParameterVectorDestination(
            self.OUTPUT, self.tr('Contours'), QgsProcessing.TypeVectorLine))
Beispiel #3
0
    def initParameters(self, config=None):
        self.addParameter(QgsProcessingParameterNumber(self.ANGLE_TOLERANCE,
                                                       self.tr('Maximum angle tolerance (degrees)'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       minValue=0.0, maxValue=45.0, defaultValue=15.0))

        max_iterations = QgsProcessingParameterNumber(self.MAX_ITERATIONS,
                                                      self.tr('Maximum algorithm iterations'),
                                                      type=QgsProcessingParameterNumber.Integer,
                                                      minValue=1, maxValue=10000, defaultValue=1000)
        max_iterations.setFlags(max_iterations.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(max_iterations)
Beispiel #4
0
    def initAlgorithm(self, config=None):
        self.METHODS = [self.tr('Linear'),
                        self.tr('Clough-Toucher (cubic)')
                        ]

        self.addParameter(ParameterInterpolationData(self.INTERPOLATION_DATA,
                                                     self.tr('Input layer(s)')))
        self.addParameter(QgsProcessingParameterEnum(self.METHOD,
                                                     self.tr('Interpolation method'),
                                                     options=self.METHODS,
                                                     defaultValue=0))
        self.addParameter(QgsProcessingParameterExtent(self.EXTENT,
                                                       self.tr('Extent'),
                                                       optional=False))
        pixel_size_param = ParameterPixelSize(self.PIXEL_SIZE,
                                              self.tr('Output raster size'),
                                              layersData=self.INTERPOLATION_DATA,
                                              extent=self.EXTENT,
                                              minValue=0.0,
                                              default=0.1)
        self.addParameter(pixel_size_param)

        cols_param = QgsProcessingParameterNumber(self.COLUMNS,
                                                  self.tr('Number of columns'),
                                                  optional=True,
                                                  minValue=0, maxValue=10000000)
        cols_param.setFlags(cols_param.flags() | QgsProcessingParameterDefinition.FlagHidden)
        self.addParameter(cols_param)

        rows_param = QgsProcessingParameterNumber(self.ROWS,
                                                  self.tr('Number of rows'),
                                                  optional=True,
                                                  minValue=0, maxValue=10000000)
        rows_param.setFlags(rows_param.flags() | QgsProcessingParameterDefinition.FlagHidden)
        self.addParameter(rows_param)

        self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                                  self.tr('Interpolated')))

        triangulation_file_param = QgsProcessingParameterFeatureSink(self.TRIANGULATION,
                                                                     self.tr('Triangulation'),
                                                                     type=QgsProcessing.TypeVectorLine,
                                                                     optional=True)
        triangulation_file_param.setCreateByDefault(False)
        self.addParameter(triangulation_file_param)
Beispiel #5
0
    def initAlgorithm(self, config=None):
        self.addParameter(QgsProcessingParameterMultipleLayers(self.INPUT,
                                                               self.tr('Input layers'),
                                                               QgsProcessing.TypeRaster))
        self.addParameter(QgsProcessingParameterBoolean(self.PCT,
                                                        self.tr('Grab pseudocolor table from first layer'),
                                                        defaultValue=False))
        self.addParameter(QgsProcessingParameterBoolean(self.SEPARATE,
                                                        self.tr('Place each input file into a separate band'),
                                                        defaultValue=False))

        nodata_param = QgsProcessingParameterNumber(self.NODATA_INPUT,
                                                    self.tr('Input pixel value to treat as "nodata"'),
                                                    type=QgsProcessingParameterNumber.Integer,
                                                    defaultValue=None,
                                                    optional=True)
        nodata_param.setFlags(nodata_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(nodata_param)

        nodata_out_param = QgsProcessingParameterNumber(self.NODATA_OUTPUT,
                                                        self.tr('Assign specified "nodata" value to output'),
                                                        type=QgsProcessingParameterNumber.Integer,
                                                        defaultValue=None,
                                                        optional=True)
        nodata_out_param.setFlags(nodata_out_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(nodata_out_param)

        options_param = QgsProcessingParameterString(self.OPTIONS,
                                                     self.tr('Additional creation options'),
                                                     defaultValue='',
                                                     optional=True)
        options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class': 'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'}})
        self.addParameter(options_param)

        self.addParameter(QgsProcessingParameterEnum(self.DATA_TYPE,
                                                     self.tr('Output data type'),
                                                     self.TYPES,
                                                     allowMultiple=False,
                                                     defaultValue=5))

        self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                                  self.tr('Merged')))
Beispiel #6
0
    def add_bottom_parameters(self):
        parameter = QgsProcessingParameterNumber(
            self.TIMEOUT, tr('Timeout'), defaultValue=25, minValue=5)
        parameter.setFlags(parameter.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(parameter)

        server = get_setting('defaultOAPI', OVERPASS_SERVERS[0]) + 'interpreter'
        parameter = QgsProcessingParameterString(
            self.SERVER, tr('Overpass server'), optional=False, defaultValue=server)
        parameter.setFlags(parameter.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(parameter)

        self.addOutput(
            QgsProcessingOutputString(
                self.OUTPUT_URL, tr('Query as encoded URL')))

        self.addOutput(
            QgsProcessingOutputString(
                self.OUTPUT_OQL_QUERY, tr('Raw query as OQL')))
Beispiel #7
0
    def initAlgorithm(self, config=None):
        """
        Here we define the inputs and output of the algorithm, along with some other properties.
        """
        # We add the input vector features source. It can have any kind of geometry.
        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.INPUT,
                self.tr('Input layer'),
                [QgsProcessing.TypeVector]
            )
        )
        
        optional_start_value = QgsProcessingParameterNumber(
            self.OPTIONAL_START_VALUE,
            self.tr('Optional start value for progressive (default = 0)'), 0
        )
        optional_start_value.setFlags(optional_start_value.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(optional_start_value)
        
        result_field_name = QgsProcessingParameterString(
            self.RESULT_FIELD_NAME,
            self.tr('Optional new Field name suffix'), ' '
        )
        result_field_name.setFlags(result_field_name.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(result_field_name)
        
        id_calc = QgsProcessingParameterBoolean(
            self.ID_CALC,
            self.tr('Optional add Id calculation column'), 0
        )
        id_calc.setFlags(id_calc.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(id_calc)
        
        id_dec = QgsProcessingParameterBoolean(
            self.ID_DEC,
            self.tr('Optional 5 decimal places'), 0
        )
        id_dec.setFlags(id_dec.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(id_dec)
        
        
        self.addParameter(QgsProcessingParameterField(self.OPERATION_FIELD_NAME,
														'Choose operation field',
														type=QgsProcessingParameterField.Numeric,
														parentLayerParameterName=self.INPUT))
        
        self.addParameter(QgsProcessingParameterEnum(self.OUTPUT_OPERATION, 'Option calc: Prog, %, M Mobile, M Ponderata, Var, Var %',
                                                        options=['PROGRESSIVA','PERCENTUALE','MEDIA MOBILE','MEDIA PONDERATA','VARIAZIONE','VARIAZIONE %'],
                                                        allowMultiple=False, defaultValue = None))
        
        self.addParameter(QgsProcessingParameterField(self.WEIGHT_FIELD_NAME,
														self.tr('Choose weight field'),
                                                        optional = 1,
														type=QgsProcessingParameterField.Numeric,
														parentLayerParameterName=self.INPUT))

        
        # We add a feature sink in which to store our processed features (this
        # usually takes the form of a newly created vector layer when the
        # algorithm is run in QGIS).
        self.addParameter(
            QgsProcessingParameterFeatureSink(
                self.OUTPUT,
                self.tr('Calc_' + str(datetime.datetime.now().strftime("%d-%m-%Y %H:%M:%S")))
            )
        )
Beispiel #8
0
    def initAlgorithm(self, config=None):
        self.units = [self.tr("Pixels"),
                      self.tr("Georeferenced units")]

        self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
                                                              self.tr('Input layer')))
        self.addParameter(QgsProcessingParameterField(self.FIELD,
                                                      self.tr('Field to use for a burn-in value'),
                                                      None,
                                                      self.INPUT,
                                                      QgsProcessingParameterField.Numeric,
                                                      optional=True))
        self.addParameter(QgsProcessingParameterNumber(self.BURN,
                                                       self.tr('A fixed value to burn'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       defaultValue=0.0,
                                                       optional=True))
        self.addParameter(QgsProcessingParameterEnum(self.UNITS,
                                                     self.tr('Output raster size units'),
                                                     self.units))
        self.addParameter(QgsProcessingParameterNumber(self.WIDTH,
                                                       self.tr('Width/Horizontal resolution'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       minValue=0.0,
                                                       defaultValue=0.0))
        self.addParameter(QgsProcessingParameterNumber(self.HEIGHT,
                                                       self.tr('Height/Vertical resolution'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       minValue=0.0,
                                                       defaultValue=0.0))
        self.addParameter(QgsProcessingParameterExtent(self.EXTENT,
                                                       self.tr('Output extent')))
        self.addParameter(QgsProcessingParameterNumber(self.NODATA,
                                                       self.tr('Assign a specified nodata value to output bands'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       defaultValue=0.0,
                                                       optional=True))

        options_param = QgsProcessingParameterString(self.OPTIONS,
                                                     self.tr('Additional creation parameters'),
                                                     defaultValue='',
                                                     optional=True)
        options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class': 'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'}})
        self.addParameter(options_param)

        dataType_param = QgsProcessingParameterEnum(self.DATA_TYPE,
                                                    self.tr('Output data type'),
                                                    self.TYPES,
                                                    allowMultiple=False,
                                                    defaultValue=5)
        dataType_param.setFlags(dataType_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        init_param = QgsProcessingParameterNumber(self.INIT,
                                                  self.tr('Pre-initialize the output image with value'),
                                                  type=QgsProcessingParameterNumber.Double,
                                                  defaultValue=0.0,
                                                  optional=True)
        init_param.setFlags(init_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(init_param)

        invert_param = QgsProcessingParameterBoolean(self.INVERT,
                                                     self.tr('Invert rasterization'),
                                                     defaultValue=False)
        invert_param.setFlags(invert_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(invert_param)

        self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                                  self.tr('Rasterized')))
Beispiel #9
0
    def initAlgorithm(self, config=None):
        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.INPUT, self.tr("Edges"), [QgsProcessing.TypeVectorLine]))

        self.addParameter(
            QgsProcessingParameterField(self.CLUSTER_FIELD,
                                        self.tr("Cluster field"),
                                        type=QgsProcessingParameterField.Any,
                                        parentLayerParameterName=self.INPUT,
                                        allowMultiple=False,
                                        defaultValue=None,
                                        optional=True))

        init_step_size = QgsProcessingParameterNumber(
            self.INITIAL_STEP_SIZE,
            self.
            tr("Initial step size (try 0.001 for GPS data or 100 for projected data)"
               ), QgsProcessingParameterNumber.Double, 0.001)
        init_step_size.setFlags(
            init_step_size.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(init_step_size)

        compatibility = QgsProcessingParameterNumber(
            self.COMPATIBILITY,
            self.tr(
                "Compatibility (a low value increases the grouping of paths)"),
            QgsProcessingParameterNumber.Double, 0.6)
        compatibility.setFlags(compatibility.flags()
                               | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(compatibility)

        cycles = QgsProcessingParameterNumber(
            self.CYCLES,
            self.tr("Cycles (increases the number of line breaks)"),
            QgsProcessingParameterNumber.Integer, 6)
        cycles.setFlags(cycles.flags()
                        | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(cycles)

        iterations = QgsProcessingParameterNumber(
            self.ITERATIONS,
            self.tr("Iterations (of the force-directed layout)"),
            QgsProcessingParameterNumber.Integer, 90)
        iterations.setFlags(iterations.flags()
                            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(iterations)

        max_dist = QgsProcessingParameterNumber(
            self.MAX_DISTANCE,
            self.tr("Maximum distance to merge overlapping segments"),
            type=QgsProcessingParameterNumber.Double,
            defaultValue=0.0005,
            optional=True)  #defaultValue=0.005,
        max_dist.setFlags(max_dist.flags()
                          | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(max_dist)

        weight = QgsProcessingParameterField(
            self.WEIGHT_FIELD,
            self.tr("Weight field"),
            type=QgsProcessingParameterField.Any,
            parentLayerParameterName=self.INPUT,
            allowMultiple=False,
            defaultValue=None,
            optional=True)
        weight.setFlags(weight.flags()
                        | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(weight)

        self.addParameter(
            QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr("Flow Map"),
                                              QgsProcessing.TypeVectorLine))
Beispiel #10
0
    def initAlgorithm(self, config=None):
        self.addParameter(
            QgsProcessingParameterMultipleLayers(self.INPUT,
                                                 self.tr('Input layers'),
                                                 QgsProcessing.TypeRaster))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.PCT,
                self.tr('Grab pseudocolor table from first layer'),
                defaultValue=False))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.SEPARATE,
                self.tr('Place each input file into a separate band'),
                defaultValue=False))

        nodata_param = QgsProcessingParameterNumber(
            self.NODATA_INPUT,
            self.tr('Input pixel value to treat as "nodata"'),
            type=QgsProcessingParameterNumber.Integer,
            defaultValue=None,
            optional=True)
        nodata_param.setFlags(nodata_param.flags()
                              | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(nodata_param)

        nodata_out_param = QgsProcessingParameterNumber(
            self.NODATA_OUTPUT,
            self.tr('Assign specified "nodata" value to output'),
            type=QgsProcessingParameterNumber.Integer,
            defaultValue=None,
            optional=True)
        nodata_out_param.setFlags(
            nodata_out_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(nodata_out_param)

        options_param = QgsProcessingParameterString(
            self.OPTIONS,
            self.tr('Additional creation options'),
            defaultValue='',
            optional=True)
        options_param.setFlags(options_param.flags()
                               | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class':
                'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'
            }
        })
        self.addParameter(options_param)

        self.addParameter(
            QgsProcessingParameterEnum(self.DATA_TYPE,
                                       self.tr('Output data type'),
                                       self.TYPES,
                                       allowMultiple=False,
                                       defaultValue=5))

        self.addParameter(
            QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                    self.tr('Merged')))
Beispiel #11
0
    def initAlgorithm(self, config):
        # use parent class to get other parameters
        super(self.__class__, self).initAlgorithm(config)

        project = QgsProject.instance()
        connection_name = QgsExpressionContextUtils.projectScope(project).variable('gobs_connection_name')
        get_data = QgsExpressionContextUtils.globalScope().variable('gobs_get_database_data')

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

        self.SERIES = ['%s' % a[1] for a in data]
        self.SERIES_DICT = {a[1]: a[0] for a in data}

        self.addParameter(
            QgsProcessingParameterEnum(
                self.SERIE,
                tr('Series of observations'),
                options=self.SERIES,
                optional=False
            )
        )

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

        # Add spatial object data ?
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.ADD_SPATIAL_OBJECT_DATA,
                tr('Add spatial object ID and label ?'),
                defaultValue=True,
                optional=False
            )
        )

        # Add spatial object geometry ?
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.ADD_SPATIAL_OBJECT_GEOM,
                tr('Add spatial object geometry ?'),
                defaultValue=False,
                optional=False
            )
        )

        # Aggregate with a temporal resolution, such as hour, day, etc. ?
        self.TEMPORAL_RESOLUTIONS = [
            'original',
            'second', 'minute', 'hour', 'day', 'week', 'month', 'year'
        ]
        self.addParameter(
            QgsProcessingParameterEnum(
                self.TEMPORAL_RESOLUTION,
                tr('Timestamp extraction resolution'),
                options=self.TEMPORAL_RESOLUTIONS,
                optional=False
            )
        )

        # Aggregate functions
        self.addParameter(
            QgsProcessingParameterEnum(
                self.AGGREGATE_FUNCTIONS,
                tr('Choose aggregate functions to use'),
                options=self.AGGREGATE_FUNCTIONS_LIST,
                optional=False,
                allowMultiple=True,
                defaultValue=[a for a in range(len(self.AGGREGATE_FUNCTIONS_LIST))]
            )
        )

        # Aggregate with a value
        # self.addParameter(
        #   QgsProcessingParameterBoolean(
        #       self.GROUP_BY_DISTINCT_VALUES,
        #       tr('Group by the distinct values'),
        #       defaultValue=False,
        #       optional=False
        #   )
        # )

        # Min timestamp
        self.addParameter(
            QgsProcessingParameterString(
                self.MIN_TIMESTAMP,
                tr('Minimum observation timestamp, Ex: 2019-01-01 or 2019-01-06 00:00:00'),
                defaultValue='',
                optional=True
            )
        )

        # Max timestamp
        self.addParameter(
            QgsProcessingParameterString(
                self.MAX_TIMESTAMP,
                tr('Maximum observation timestamp, Ex:2019-12-31 or 2019-12-31 23:59:53'),
                defaultValue='',
                optional=True
            )
        )
    def initAlgorithm(self, config):
        print('initAlgorithm()')

        #super(MappiaPublisherAlgorithm, self).initAlgorithm()
        """
        Here we define the inputs and output of the algorithm, along
        with some other properties.
        """

        options = OptionsCfg.read()

        self.last_update_date = options[OptionsCfg.UPDATE_CHECK]

        #self.addParameter(
        #    QgsProcessingParameterEnum(
        #        self.OPERATION,
        #        self.tr('Operation Type'),
        #        options=[self.tr(curOption) for curOption in OperationType.getOptions()],
        #        defaultValue=9
        #    )
        #)

        #TODO Implement layer attribute later.
        # self.addParameter(
        #     QgsProcessingParameterString(
        #         self.LAYER_ATTRIBUTE,
        #         self.tr('Layer style name (Change to different style names only if interested in publishing multiple (layers or attributes) of the same file.)'),
        #         optional=False,
        #         defaultValue=options['attrName']
        #     )
        # )

        self.addParameter(
            QgsProcessingParameterString(
                self.GITHUB_REPOSITORY,
                self.tr('* Repository name (or map group name)'),
                optional=False,
                defaultValue=options['gh_repository']))

        # We add the input vector features source. It can have any kind of
        # geometry.
        layerParam = QgsProcessingParameterMultipleLayers(
            self.LAYERS, self.tr('* Maps to display online'),
            QgsProcessing.TypeMapLayer
            #, defaultValue=[layer.id() for layer in iface.mapCanvas().layers()]#[layer.dataProvider().dataSourceUri(False) for layer in iface.mapCanvas().layers()]
        )
        layerParam.setMinimumNumberInputs(1)
        self.addParameter(layerParam)
        self.m_layerParam = layerParam

        maxZoomParameter = QgsProcessingParameterNumber(
            self.ZOOM_MAX,
            self.tr('Map max Zoom level [1 ~ 13] (lower is faster)'),
            minValue=1,
            maxValue=13,
            defaultValue=options["zoom_max"])
        maxZoomParameter.setFlags(
            maxZoomParameter.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(maxZoomParameter)

        includeSourceDownload = QgsProcessingParameterBoolean(
            self.INCLUDE_DOWNLOAD,
            self.tr(
                'Upload maps for further download (2GB limit per unique map)'),
            defaultValue=options['include_dl'])
        includeSourceDownload.setFlags(
            includeSourceDownload.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(includeSourceDownload)

        gitExeParameter = QgsProcessingParameterString(
            self.GIT_EXECUTABLE,
            self.tr('Git client executable path.'),
            optional=True,
            defaultValue=UTILS.getGitDefault(options['git_exe']))
        gitExeParameter.setFlags(
            gitExeParameter.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(gitExeParameter)

        ghUserParameter = QgsProcessingParameterString(
            self.GITHUB_USER,
            self.tr('Github USERNAME (Credentials for https://github.com)'),
            optional=True,
            defaultValue=options['gh_user'])
        ghUserParameter.setFlags(
            ghUserParameter.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(ghUserParameter)

        # ghPassParameter = QgsProcessingParameterString(
        #     self.GITHUB_PASS,
        #     self.tr('Github Access Token *'),
        #     optional=True,
        #     defaultValue=options['gh_pass']
        # )
        # ghPassParameter.setFlags(ghPassParameter.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        # self.addParameter(ghPassParameter)

        askUserConfirmation = QgsProcessingParameterBoolean(
            self.ASK_USER,
            self.tr('Ask user confirmation before each step.'),
            defaultValue=options['ask_user'])
        askUserConfirmation.setFlags(
            askUserConfirmation.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(askUserConfirmation)

        outputDirParameter = QgsProcessingParameterFolderDestination(
            self.OUTPUT_DIRECTORY,
            self.tr('Output directory'),
            optional=True,
            defaultValue=options["folder"] or None)
        outputDirParameter.setFlags(
            outputDirParameter.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(outputDirParameter)
Beispiel #13
0
    def initAlgorithm(self, config=None):
        self.units = [self.tr("Pixels"),
                      self.tr("Georeferenced units")]

        self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
                                                              self.tr('Input layer')))
        self.addParameter(QgsProcessingParameterField(self.FIELD,
                                                      self.tr('Field to use for a burn-in value'),
                                                      None,
                                                      self.INPUT,
                                                      QgsProcessingParameterField.Numeric,
                                                      optional=True))
        self.addParameter(QgsProcessingParameterNumber(self.BURN,
                                                       self.tr('A fixed value to burn'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       defaultValue=0.0,
                                                       optional=True))
        self.addParameter(QgsProcessingParameterEnum(self.UNITS,
                                                     self.tr('Output raster size units'),
                                                     self.units))
        self.addParameter(QgsProcessingParameterNumber(self.WIDTH,
                                                       self.tr('Width/Horizontal resolution'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       minValue=0.0,
                                                       defaultValue=0.0))
        self.addParameter(QgsProcessingParameterNumber(self.HEIGHT,
                                                       self.tr('Height/Vertical resolution'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       minValue=0.0,
                                                       defaultValue=0.0))
        self.addParameter(QgsProcessingParameterExtent(self.EXTENT,
                                                       self.tr('Output extent')))
        self.addParameter(QgsProcessingParameterNumber(self.NODATA,
                                                       self.tr('Assign a specified nodata value to output bands'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       defaultValue=0.0,
                                                       optional=True))

        options_param = QgsProcessingParameterString(self.OPTIONS,
                                                     self.tr('Additional creation options'),
                                                     defaultValue='',
                                                     optional=True)
        options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class': 'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'}})
        self.addParameter(options_param)

        dataType_param = QgsProcessingParameterEnum(self.DATA_TYPE,
                                                    self.tr('Output data type'),
                                                    self.TYPES,
                                                    allowMultiple=False,
                                                    defaultValue=5)
        dataType_param.setFlags(dataType_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        init_param = QgsProcessingParameterNumber(self.INIT,
                                                  self.tr('Pre-initialize the output image with value'),
                                                  type=QgsProcessingParameterNumber.Double,
                                                  optional=True)
        init_param.setFlags(init_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(init_param)

        invert_param = QgsProcessingParameterBoolean(self.INVERT,
                                                     self.tr('Invert rasterization'),
                                                     defaultValue=False)
        invert_param.setFlags(invert_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(invert_param)

        self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                                  self.tr('Rasterized')))
Beispiel #14
0
    def initAlgorithm(self, config=None):

        self.addParameter(
            QgsProcessingParameterMultipleLayers(self.INPUT_LAYERS,
                                                 self.tr('Input layers'),
                                                 QgsProcessing.TypeRaster))

        self.addParameter(
            QgsProcessingParameterFeatureSink(self.OUTPUT_FOOTPRINTS,
                                              self.tr('Images footprint'),
                                              QgsProcessing.TypeVectorPolygon))

        self.addParameter(
            QgsProcessingParameterFeatureSink(self.OUTPUT_NADIRS,
                                              self.tr('Images nadir'),
                                              QgsProcessing.TypeVectorPoint))

        self.addParameter(
            QgsProcessingParameterEnum(
                self.CAMERA_MODEL,
                self.tr('Camera model defining FOV values'),
                options=list(self.CAMERA_DATA.keys())))

        self.addParameter(
            QgsProcessingParameterCrs(self.SOURCE_CRS,
                                      self.tr('Source CRS'),
                                      defaultValue='EPSG:4326'))

        self.addParameter(
            QgsProcessingParameterCrs(self.DESTINATION_CRS,
                                      self.tr('Destination CRS'),
                                      optional=True,
                                      defaultValue='ProjectCrs'))

        # horizontal referred to flight direction => means wide angle
        parameter = QgsProcessingParameterNumber(
            self.HORIZONTAL_FOV,
            self.tr('Wide camera angle'),
            type=QgsProcessingParameterNumber.Double,
            defaultValue=84.0,
            minValue=0,
            maxValue=360)
        parameter.setFlags(parameter.flags()
                           | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(parameter)

        # vertical referred to flight direction => means tall angle
        parameter = QgsProcessingParameterNumber(
            self.VERTICAL_FOV,
            self.tr('Tall camera angle'),
            type=QgsProcessingParameterNumber.Double,
            defaultValue=54.0,
            minValue=0,
            maxValue=360)
        parameter.setFlags(parameter.flags()
                           | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(parameter)

        parameter = QgsProcessingParameterNumber(
            self.NADIR_TO_BOTTOM_OFFSET,
            self.tr('Offset to add to bottom distance result'),
            type=QgsProcessingParameterNumber.Double)
        parameter.setFlags(parameter.flags()
                           | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(parameter)

        parameter = QgsProcessingParameterNumber(
            self.NADIR_TO_UPPPER_OFFSET,
            self.tr('Offset to add to upper distance result'),
            type=QgsProcessingParameterNumber.Double)
        parameter.setFlags(parameter.flags()
                           | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(parameter)
Beispiel #15
0
    def initAlgorithm(self, config=None):
        self.addParameter(
            QgsProcessingParameterRasterLayer(self.INPUT,
                                              self.tr('Input layer')))
        self.addParameter(
            QgsProcessingParameterBand(self.BAND,
                                       self.tr('Band number'),
                                       parentLayerParameterName=self.INPUT))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.INTERVAL,
                self.tr('Interval between contour lines'),
                type=QgsProcessingParameterNumber.Double,
                minValue=0.0,
                defaultValue=10.0))
        self.addParameter(
            QgsProcessingParameterString(
                self.FIELD_NAME,
                self.
                tr('Attribute name (if not set, no elevation attribute is attached)'
                   ),
                defaultValue='ELEV',
                optional=True))

        create_3d_param = QgsProcessingParameterBoolean(
            self.CREATE_3D, self.tr('Produce 3D vector'), defaultValue=False)
        create_3d_param.setFlags(
            create_3d_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(create_3d_param)

        ignore_nodata_param = QgsProcessingParameterBoolean(
            self.IGNORE_NODATA,
            self.tr('Treat all raster values as valid'),
            defaultValue=False)
        ignore_nodata_param.setFlags(
            ignore_nodata_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(ignore_nodata_param)

        nodata_param = QgsProcessingParameterNumber(
            self.NODATA,
            self.tr('Input pixel value to treat as "nodata"'),
            type=QgsProcessingParameterNumber.Double,
            defaultValue=None,
            optional=True)
        nodata_param.setFlags(nodata_param.flags()
                              | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(nodata_param)

        offset_param = QgsProcessingParameterNumber(
            self.OFFSET,
            self.tr(
                'Offset from zero relative to which to interpret intervals'),
            type=QgsProcessingParameterNumber.Double,
            defaultValue=0.0,
            optional=True)
        nodata_param.setFlags(offset_param.flags()
                              | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(offset_param)

        self.addParameter(
            QgsProcessingParameterVectorDestination(
                self.OUTPUT, self.tr('Contours'),
                QgsProcessing.TypeVectorLine))
Beispiel #16
0
    def initAlgorithm(self, config):
        # INPUTS
        connection_name = QgsExpressionContextUtils.globalScope().variable('gobs_connection_name')
        get_data = QgsExpressionContextUtils.globalScope().variable('gobs_get_database_data')

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

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

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

        # Confirmation
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.RUN_DELETE,
                tr('Check this box to delete. No action will be done otherwise'),
                defaultValue=False,
            )
        )

        # Delete the series
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.DELETE_SERIES,
                tr('Also delete the series item'),
                defaultValue=False,
            )
        )

        # OUTPUTS
        # Add output for status (integer)
        self.addOutput(
            QgsProcessingOutputNumber(
                self.OUTPUT_STATUS,
                tr('Output status')
            )
        )
        # Add output for message
        self.addOutput(
            QgsProcessingOutputString(
                self.OUTPUT_STRING,
                tr('Output message')
            )
        )
    def initAlgorithm(self, config=None):
        """
        Here we define the inputs and output of the algorithm, along
        with some other properties.
        """

        self.addParameter(
            QgsProcessingParameterRasterLayer(
                self.IMG_REF,
                self.tr('The REFERENCE image to use as based to co-register the target image')
            )
        )

        self.addParameter(
            QgsProcessingParameterRasterLayer(
                self.INPUT,
                self.tr('The TARGET image for co-register'),
            )
        )

        self.addParameter(
            QgsProcessingParameterBoolean(
                self.ALIGN_GRIDS,
                self.tr('Align the input coordinate grid to the reference'),
                defaultValue=True,
            )
        )

        self.addParameter(
            QgsProcessingParameterBoolean(
                self.MATCH_GSD,
                self.tr('Match the input pixel size to the reference pixel size'),
                defaultValue=True,
            )
        )

        self.addParameter(
            QgsProcessingParameterNumber(
                self.GRID_RES,
                self.tr('Tie point grid resolution (pixel units of the target image)'),
                type=QgsProcessingParameterNumber.Integer,
                defaultValue=200,
            )
        )

        self.addParameter(
            QgsProcessingParameterNumber(
                self.WINDOW_SIZE,
                self.tr('Custom matching window size (width and height in pixel units)'),
                type=QgsProcessingParameterNumber.Integer,
                defaultValue=256,
            )
        )

        parameter = \
            QgsProcessingParameterNumber(
                self.MAX_SHIFT,
                self.tr('Maximum shift distance in reference image pixel units'),
                type=QgsProcessingParameterNumber.Integer,
                defaultValue=5,
                optional=False
            )
        parameter.setFlags(parameter.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(parameter)

        parameter = \
            QgsProcessingParameterEnum(
                self.RESAMPLING,
                self.tr('The resampling algorithm to be used for shift correction (if necessary)'),
                options=[i[0] for i in self.resampling_methods],
                defaultValue=2,
                optional=False
            )
        parameter.setFlags(parameter.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(parameter)

        self.addParameter(
            QgsProcessingParameterRasterDestination(
                self.OUTPUT,
                self.tr('Output raster file co-registered')
            )
        )
    def initAlgorithm(self, config):
        """
		Here we define the inputs and output of the algorithm, along
		with some other properties.
		"""

        # We add the input vector features source. It can have any kind of
        # geometry.

        self.addParameter(
            QgsProcessingParameterRasterLayer(self.TI,
                                              self.tr('Training raster')))

        self.addParameter(
            QgsProcessingParameterBand(self.BANDS_TI,
                                       self.tr('Selected band(s)'),
                                       None,
                                       self.TI,
                                       allowMultiple=True))

        self.addParameter(
            QgsProcessingParameterRasterLayer(
                self.INPUT, self.tr('Raster on which to simulate')))

        self.addParameter(
            QgsProcessingParameterBand(self.BANDS_INPUT,
                                       self.tr('Selected band(s)'),
                                       None,
                                       self.INPUT,
                                       allowMultiple=True))

        # We add a feature sink in which to store our processed features (this
        # usually takes the form of a newly created vector layer when the
        # algorithm is run in QGIS).
        self.addParameter(
            QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                    self.tr('QS simulation')))

        self.addParameter(
            QgsProcessingParameterNumber(
                self.PARAM_K,
                self.tr('Parameter k'),
                QgsProcessingParameterNumber.Double,
                1.2,
                minValue=1,
            ))

        self.addParameter(
            QgsProcessingParameterNumber(
                self.PARAM_N,
                self.tr('Parameter N'),
                QgsProcessingParameterNumber.Integer,
                30,
                minValue=1,
            ))

        self.addParameter(
            QgsProcessingParameterEnum(self.KERNEL_TYPE,
                                       self.tr('Type of kernel'), [
                                           self.tr('Uniform'),
                                           self.tr('Exponential'),
                                           self.tr('Gaussian')
                                       ],
                                       defaultValue=0,
                                       optional=True))

        self.addParameter(
            QgsProcessingParameterNumber(self.KERNEL_ALPHA,
                                         self.tr('Kernel Alpha OR Max radius'),
                                         QgsProcessingParameterNumber.Double,
                                         1,
                                         minValue=0.001,
                                         optional=True))

        paramj = QgsProcessingParameterNumber(
            self.PARAM_J,
            self.
            tr('Parallelization, interger for number of cores, and decimal ]0,1[, for porcentage of total cores'
               ),
            QgsProcessingParameterNumber.Double,
            0.5,
            minValue=0.001,
            optional=True)
        paramj.setFlags(paramj.flags()
                        | QgsProcessingParameterDefinition.FlagAdvanced)

        paramSA = QgsProcessingParameterString(
            self.PARAM_SA,
            self.tr('DNS name or IP of the G2S server'),
            'localhost',
            optional=True)
        paramSA.setFlags(paramSA.flags()
                         | QgsProcessingParameterDefinition.FlagAdvanced)

        ignoreResolution = QgsProcessingParameterBoolean(
            self.PARAM_IGNORE_RESOLUTION,
            self.tr('ignore resolution check'),
            False,
            optional=True)
        ignoreResolution.setFlags(
            ignoreResolution.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)

        self.addParameter(paramj)
        self.addParameter(paramSA)
        self.addParameter(ignoreResolution)
Beispiel #19
0
 def initAlgorithm(self, config=None):
     self.addParameter(
         QgsProcessingParameterRasterLayer(
             self.INPUT,
             "Modèle numérique de terrain",
             defaultValue=None,
         ))
     self.addParameter(
         QgsProcessingParameterNumber(
             self.ITERATION,
             "Nombre d'itération",
             type=QgsProcessingParameterNumber.Integer,
             minValue=1,
             defaultValue=25,
         ))
     self.addParameter(
         QgsProcessingParameterNumber(
             self.BRUITAGE_MIN,
             "Bruitage minimal",
             type=QgsProcessingParameterNumber.Double,
             minValue=0.01,
             defaultValue=0.01,
         ))
     self.addParameter(
         QgsProcessingParameterNumber(
             self.BRUITAGE_MAX,
             "Bruitage maximal",
             type=QgsProcessingParameterNumber.Double,
             minValue=0.01,
             defaultValue=5,
         ))
     self.addParameter(
         QgsProcessingParameterNumber(
             self.SEUIL,
             "Seuil",
             type=QgsProcessingParameterNumber.Integer,
             defaultValue=500,
         ))
     param = QgsProcessingParameterNumber(
         self.MINIMUMSIZEOFEXTERIORWATERSHEDBASIN,
         # TODO : traduire ça
         "Minimum size of exterior watershed basin",
         type=QgsProcessingParameterNumber.Integer,
         defaultValue=500,
     )
     param.setFlags(param.flags()
                    | QgsProcessingParameterDefinition.FlagAdvanced)
     self.addParameter(param)
     param = QgsProcessingParameterBoolean(
         self.SUPPRFICHIERSINTERMED,
         "Suppression des fichiers intermédaires au fur et à mesure des itérations",
         defaultValue=True,
     )
     param.setFlags(param.flags()
                    | QgsProcessingParameterDefinition.FlagAdvanced)
     self.addParameter(param)
     self.addParameter(
         QgsProcessingParameterRasterDestination(
             self.OUTPUT,
             "Couche ExZEco générée",
             createByDefault=True,
             defaultValue=None,
         ))
Beispiel #20
0
    def initAlgorithm(self, config):
        x_min = -100e3
        x_max = 200e3
        y_min = -150e3
        y_max = 150e3
        dx = 750
        dy = 750
        x0 = -25e3
        y0 = 0.0
        sigma_x = 15e3
        sigma_y = 15e3

        self.addParameter(
            QgsProcessingParameterCrs(self.TARGET_CRS, self.tr('Target CRS'),
                                      'ProjectCrs'))

        self.addParameter(
            QgsProcessingParameterExtent(
                self.EXTENT, self.tr('Extent'),
                "{}, {}, {}, {}".format(x_min, x_max, y_min, y_max)))

        self.addParameter(
            QgsProcessingParameterNumber(self.DX,
                                         self.tr("Grid spacing (dx, meters)"),
                                         QgsProcessingParameterNumber.Double,
                                         defaultValue=dx,
                                         minValue=0.0))
        self.addParameter(
            QgsProcessingParameterNumber(self.DY,
                                         self.tr("Grid spacing (dy, meters)"),
                                         QgsProcessingParameterNumber.Double,
                                         defaultValue=dy,
                                         minValue=0.0))

        self.addParameter(
            QgsProcessingParameterPoint(self.CENTER, self.tr("Center"),
                                        "{}, {}".format(x0, y0)))

        s_x = QgsProcessingParameterNumber(
            self.SIGMA_X,
            self.tr("Spread in the X direction (sigma_x)"),
            QgsProcessingParameterNumber.Double,
            defaultValue=sigma_x,
            minValue=0.0)
        s_x.setFlags(s_x.flags()
                     | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(s_x)

        s_y = QgsProcessingParameterNumber(
            self.SIGMA_Y,
            self.tr("Spread in the Y direction (sigma_y)"),
            QgsProcessingParameterNumber.Double,
            defaultValue=sigma_y,
            minValue=0.0)
        s_y.setFlags(s_y.flags()
                     | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(s_y)

        self.addParameter(
            QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                    self.tr('Testing DEM')))
Beispiel #21
0
    def initAlgorithm(self, config=None):
        self.KERNELS = OrderedDict([(self.tr('Quartic'), QgsKernelDensityEstimation.KernelQuartic),
                                    (self.tr('Triangular'), QgsKernelDensityEstimation.KernelTriangular),
                                    (self.tr('Uniform'), QgsKernelDensityEstimation.KernelUniform),
                                    (self.tr('Triweight'), QgsKernelDensityEstimation.KernelTriweight),
                                    (self.tr('Epanechnikov'), QgsKernelDensityEstimation.KernelEpanechnikov)])

        self.OUTPUT_VALUES = OrderedDict([(self.tr('Raw'), QgsKernelDensityEstimation.OutputRaw),
                                          (self.tr('Scaled'), QgsKernelDensityEstimation.OutputScaled)])

        self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
                                                              self.tr('Point layer'),
                                                              [QgsProcessing.TypeVectorPoint]))

        self.addParameter(QgsProcessingParameterDistance(self.RADIUS,
                                                         self.tr('Radius'),
                                                         100.0, self.INPUT, False, 0.0))

        radius_field_param = QgsProcessingParameterField(self.RADIUS_FIELD,
                                                         self.tr('Radius from field'),
                                                         None,
                                                         self.INPUT,
                                                         QgsProcessingParameterField.Numeric,
                                                         optional=True
                                                         )
        radius_field_param.setFlags(radius_field_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(radius_field_param)

        class ParameterHeatmapPixelSize(QgsProcessingParameterNumber):

            def __init__(self, name='', description='', parent_layer=None, radius_param=None, radius_field_param=None, minValue=None,
                         default=None, optional=False):
                QgsProcessingParameterNumber.__init__(self, name, description, QgsProcessingParameterNumber.Double, default, optional, minValue)
                self.parent_layer = parent_layer
                self.radius_param = radius_param
                self.radius_field_param = radius_field_param

            def clone(self):
                copy = ParameterHeatmapPixelSize(self.name(), self.description(), self.parent_layer, self.radius_param, self.radius_field_param, self.minimum(), self.maximum(), self.defaultValue((), self.flags() & QgsProcessingParameterDefinition.FlagOptional))
                return copy

        pixel_size_param = ParameterHeatmapPixelSize(self.PIXEL_SIZE,
                                                     self.tr('Output raster size'),
                                                     parent_layer=self.INPUT,
                                                     radius_param=self.RADIUS,
                                                     radius_field_param=self.RADIUS_FIELD,
                                                     minValue=0.0,
                                                     default=0.1)
        pixel_size_param.setMetadata({
            'widget_wrapper': {
                'class': 'processing.algs.qgis.ui.HeatmapWidgets.HeatmapPixelSizeWidgetWrapper'}})
        self.addParameter(pixel_size_param)

        weight_field_param = QgsProcessingParameterField(self.WEIGHT_FIELD,
                                                         self.tr('Weight from field'),
                                                         None,
                                                         self.INPUT,
                                                         QgsProcessingParameterField.Numeric,
                                                         optional=True
                                                         )
        weight_field_param.setFlags(weight_field_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(weight_field_param)

        keys = list(self.KERNELS.keys())
        kernel_shape_param = QgsProcessingParameterEnum(self.KERNEL,
                                                        self.tr('Kernel shape'),
                                                        keys,
                                                        allowMultiple=False,
                                                        defaultValue=0)
        kernel_shape_param.setFlags(kernel_shape_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(kernel_shape_param)

        decay_ratio = QgsProcessingParameterNumber(self.DECAY,
                                                   self.tr('Decay ratio (Triangular kernels only)'),
                                                   QgsProcessingParameterNumber.Double,
                                                   0.0, True, -100.0, 100.0)
        decay_ratio.setFlags(decay_ratio.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(decay_ratio)

        keys = list(self.OUTPUT_VALUES.keys())
        output_scaling = QgsProcessingParameterEnum(self.OUTPUT_VALUE,
                                                    self.tr('Output value scaling'),
                                                    keys,
                                                    allowMultiple=False,
                                                    defaultValue=0)
        output_scaling.setFlags(output_scaling.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(output_scaling)

        self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT, self.tr('Heatmap')))
Beispiel #22
0
    def initAlgorithm(self, config=None):
        self.KERNELS = OrderedDict([
            (self.tr('Quartic'), QgsKernelDensityEstimation.KernelQuartic),
            (self.tr('Triangular'),
             QgsKernelDensityEstimation.KernelTriangular),
            (self.tr('Uniform'), QgsKernelDensityEstimation.KernelUniform),
            (self.tr('Triweight'), QgsKernelDensityEstimation.KernelTriweight),
            (self.tr('Epanechnikov'),
             QgsKernelDensityEstimation.KernelEpanechnikov)
        ])

        self.OUTPUT_VALUES = OrderedDict([
            (self.tr('Raw'), QgsKernelDensityEstimation.OutputRaw),
            (self.tr('Scaled'), QgsKernelDensityEstimation.OutputScaled)
        ])

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.INPUT, self.tr('Point layer'),
                [QgsProcessing.TypeVectorPoint]))

        self.addParameter(
            QgsProcessingParameterDistance(self.RADIUS, self.tr('Radius'),
                                           100.0, self.INPUT, False, 0.0))

        radius_field_param = QgsProcessingParameterField(
            self.RADIUS_FIELD,
            self.tr('Radius from field'),
            None,
            self.INPUT,
            QgsProcessingParameterField.Numeric,
            optional=True)
        radius_field_param.setFlags(
            radius_field_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(radius_field_param)

        class ParameterHeatmapPixelSize(QgsProcessingParameterNumber):
            def __init__(self,
                         name='',
                         description='',
                         parent_layer=None,
                         radius_param=None,
                         radius_field_param=None,
                         minValue=None,
                         default=None,
                         optional=False):
                QgsProcessingParameterNumber.__init__(
                    self, name, description,
                    QgsProcessingParameterNumber.Double, default, optional,
                    minValue)
                self.parent_layer = parent_layer
                self.radius_param = radius_param
                self.radius_field_param = radius_field_param

            def clone(self):
                copy = ParameterHeatmapPixelSize(
                    self.name(), self.description(), self.parent_layer,
                    self.radius_param, self.radius_field_param, self.minimum(),
                    self.maximum(),
                    self.defaultValue(
                        (),
                        self.flags()
                        & QgsProcessingParameterDefinition.FlagOptional))
                return copy

        pixel_size_param = ParameterHeatmapPixelSize(
            self.PIXEL_SIZE,
            self.tr('Output raster size'),
            parent_layer=self.INPUT,
            radius_param=self.RADIUS,
            radius_field_param=self.RADIUS_FIELD,
            minValue=0.0,
            default=0.1)
        pixel_size_param.setMetadata({
            'widget_wrapper': {
                'class':
                'processing.algs.qgis.ui.HeatmapWidgets.HeatmapPixelSizeWidgetWrapper'
            }
        })
        self.addParameter(pixel_size_param)

        weight_field_param = QgsProcessingParameterField(
            self.WEIGHT_FIELD,
            self.tr('Weight from field'),
            None,
            self.INPUT,
            QgsProcessingParameterField.Numeric,
            optional=True)
        weight_field_param.setFlags(
            weight_field_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(weight_field_param)

        keys = list(self.KERNELS.keys())
        kernel_shape_param = QgsProcessingParameterEnum(
            self.KERNEL,
            self.tr('Kernel shape'),
            keys,
            allowMultiple=False,
            defaultValue=0)
        kernel_shape_param.setFlags(
            kernel_shape_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(kernel_shape_param)

        decay_ratio = QgsProcessingParameterNumber(
            self.DECAY, self.tr('Decay ratio (Triangular kernels only)'),
            QgsProcessingParameterNumber.Double, 0.0, True, -100.0, 100.0)
        decay_ratio.setFlags(decay_ratio.flags()
                             | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(decay_ratio)

        keys = list(self.OUTPUT_VALUES.keys())
        output_scaling = QgsProcessingParameterEnum(
            self.OUTPUT_VALUE,
            self.tr('Output value scaling'),
            keys,
            allowMultiple=False,
            defaultValue=0)
        output_scaling.setFlags(
            output_scaling.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(output_scaling)

        self.addParameter(
            QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                    self.tr('Heatmap')))
Beispiel #23
0
    def initAlgorithm(self, config=None):

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.INPUT, self.tr('Input layer'),
                [QgsProcessing.TypeVectorAnyGeometry]))

        self.addParameter(
            QgsProcessingParameterString(self.TITLE,
                                         self.tr('Title of figure'),
                                         defaultValue='Figure 1'))

        self.addParameter(
            QgsProcessingParameterField(self.xcoordinate,
                                        self.tr('Name of X Coordinate'), None,
                                        self.INPUT,
                                        QgsProcessingParameterField.Any))

        self.addParameter(
            QgsProcessingParameterString(
                self.xlabel,
                self.tr('X label'),
                defaultValue='Distance in meters [m]'))

        self.addParameter(
            QgsProcessingParameterField(self.ycoordinate,
                                        self.tr('Name of Y Coordinate Left'),
                                        None, self.INPUT,
                                        QgsProcessingParameterField.Any))

        self.addParameter(
            QgsProcessingParameterField(self.zcoordinate,
                                        self.tr('Name of Y Coordinate Rigth'),
                                        None, self.INPUT,
                                        QgsProcessingParameterField.Any))

        self.addParameter(
            QgsProcessingParameterString(self.ylabel,
                                         self.tr('Y label'),
                                         defaultValue='Width in meters [m]'))

        width = QgsProcessingParameterNumber(
            self.size_figx,
            self.tr('Width of figure'),
            QgsProcessingParameterNumber.Double,
            defaultValue=10.0)
        width.setFlags(width.flags()
                       | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(width)

        height = QgsProcessingParameterNumber(
            self.size_figy,
            self.tr('Height of figure'),
            QgsProcessingParameterNumber.Double,
            defaultValue=3.0)
        height.setFlags(height.flags()
                        | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(height)

        colors = QgsProcessingParameterEnum(
            self.colors,
            self.tr('Figure color'), ['grey', 'colors', 'colors with line'],
            defaultValue=1)
        colors.setFlags(colors.flags()
                        | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(colors)

        exten = QgsProcessingParameterEnum(
            self.ext,
            self.tr('Figure extension'), [
                '.eps', '.pdf', '.pgf', '.png', '.ps', '.raw', '.rgba', '.svg',
                '.svgz'
            ],
            defaultValue=3)
        exten.setFlags(exten.flags()
                       | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(exten)

        self.addParameter(
            QgsProcessingParameterFileDestination(self.OUTPUT,
                                                  self.tr('Output layer')))
    def initAlgorithm(self, config):
        # INPUTS
        project = QgsProject.instance()
        connection_name = QgsExpressionContextUtils.projectScope(
            project).variable('gobs_connection_name')
        get_data = QgsExpressionContextUtils.globalScope().variable(
            'gobs_get_database_data')

        # Add spatial layer choice
        # List of spatial_layer
        sql = '''
            SELECT id, sl_label
            FROM gobs.spatial_layer
            ORDER BY sl_label
        '''
        data = []
        if get_data == 'yes' and connection_name in getPostgisConnectionList():
            [header, data, rowCount, ok,
             error_message] = fetchDataFromSqlQuery(connection_name, sql)
        self.SPATIALLAYERS = ['%s - %s' % (a[1], a[0]) for a in data]
        self.SPATIALLAYERS_DICT = {a[0]: a[1] for a in data}
        self.addParameter(
            QgsProcessingParameterEnum(self.SPATIALLAYER,
                                       tr('Spatial layer'),
                                       options=self.SPATIALLAYERS,
                                       optional=False))

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

        # Confirmation
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.RUN_DELETE,
                tr('Check this box to delete. No action will be done otherwise'
                   ),
                defaultValue=False,
            ))

        # Delete the series
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.DELETE_SPATIAL_LAYER,
                tr('Also delete the spatial layer item'),
                defaultValue=False,
            ))

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

        #super(MappiaPublisherAlgorithm, self).initAlgorithm()
        """
        Here we define the inputs and output of the algorithm, along
        with some other properties.
        """

        options = OptionsCfg.read()

        #self.addParameter(
        #    QgsProcessingParameterEnum(
        #        self.OPERATION,
        #        self.tr('Operation Type'),
        #        options=[self.tr(curOption) for curOption in OperationType.getOptions()],
        #        defaultValue=9
        #    )
        #)

        #TODO Implement layer attribute later.
        # self.addParameter(
        #     QgsProcessingParameterString(
        #         self.LAYER_ATTRIBUTE,
        #         self.tr('Layer style name (Change to different style names only if interested in publishing multiple (layers or attributes) of the same file.)'),
        #         optional=False,
        #         defaultValue=options['attrName']
        #     )
        # )

        self.addParameter(
            QgsProcessingParameterString(
                self.GITHUB_REPOSITORY,
                self.tr('Repository name (or map group name)'),
                optional=False,
                defaultValue=options['gh_repository']))

        # We add the input vector features source. It can have any kind of
        # geometry.
        layerParam = QgsProcessingParameterMultipleLayers(
            self.LAYERS,
            self.tr('Maps to display online'),
            QgsProcessing.TypeMapLayer,
            defaultValue=[
                layer.dataProvider().dataSourceUri(False)
                for layer in iface.mapCanvas().layers()
            ])
        layerParam.setMinimumNumberInputs(1)
        self.addParameter(layerParam)

        maxZoomParameter = QgsProcessingParameterNumber(
            self.ZOOM_MAX,
            self.tr('Map max Zoom level [1 ~ 13] (lower is faster)'),
            minValue=1,
            maxValue=13,
            defaultValue=options["zoom_max"])
        maxZoomParameter.setFlags(
            maxZoomParameter.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(maxZoomParameter)

        gitExeParameter = QgsProcessingParameterString(
            self.GIT_EXECUTABLE,
            self.tr('Git client executable path.'),
            optional=True,
            defaultValue=self.getGitDefault(options))
        gitExeParameter.setFlags(
            gitExeParameter.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(gitExeParameter)

        ghUserParameter = QgsProcessingParameterString(
            self.GITHUB_USER,
            self.tr('Github USERNAME (Credentials for https://github.com)'),
            optional=True,
            defaultValue=options['gh_user'])
        ghUserParameter.setFlags(
            ghUserParameter.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(ghUserParameter)

        ghPassParameter = QgsProcessingParameterString(
            self.GITHUB_PASS,
            self.tr('Github Access Token'),
            optional=True,
            defaultValue=options['gh_pass'])
        ghPassParameter.setFlags(
            ghPassParameter.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(ghPassParameter)

        outputDirParameter = QgsProcessingParameterFolderDestination(
            self.OUTPUT_DIRECTORY,
            self.tr('Output directory'),
            optional=True,
            defaultValue=options["folder"])
        outputDirParameter.setFlags(
            outputDirParameter.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(outputDirParameter)
Beispiel #26
0
    def initAlgorithm(self, config=None):
        """!
        Inputs and output of the algorithm
        """
        project = QgsProject.instance()

        # Get project crs
        project_crs = project.crs()

        # Check if project crs changed
        prev_project_crs_desc, _ = project.readEntry("qgis2fds", "project_crs",
                                                     None)
        project_crs_changed = False
        if prev_project_crs_desc != project_crs.description():
            project_crs_changed = True

        defaultValue, _ = project.readEntry("qgis2fds", "chid", "terrain")
        self.addParameter(
            QgsProcessingParameterString(
                "chid",
                "FDS case identificator (CHID)",
                multiLine=False,
                defaultValue=defaultValue,
            ))

        defaultValue, _ = project.readEntry(
            "qgis2fds", "path",
            QgsProject.instance().readPath("./"))
        self.addParameter(
            QgsProcessingParameterFile(
                "path",
                "Save in folder",
                behavior=QgsProcessingParameterFile.Folder,
                fileFilter="All files (*.*)",
                defaultValue=defaultValue,
            ))

        # QGIS issue #37447, solved in QGIS 3.14.1
        defaultValue, _ = project.readEntry("qgis2fds", "extent", None)
        self.addParameter(
            QgsProcessingParameterExtent(
                "extent",
                "Terrain extent",
                defaultValue=defaultValue,
            ))

        defaultValue, _ = project.readEntry("qgis2fds", "dem_layer", None)
        if not defaultValue:
            try:  # first layer name containing "dem"
                defaultValue = [
                    layer.name()
                    for layer in QgsProject.instance().mapLayers().values()
                    if "DEM" in layer.name() or "dem" in layer.name()
                ][0]
            except IndexError:
                pass
        self.addParameter(
            QgsProcessingParameterRasterLayer(
                "dem_layer",
                "DEM layer",
                defaultValue=defaultValue,
            ))

        defaultValue, _ = project.readEntry("qgis2fds", "dem_sampling", "1")
        param = QgsProcessingParameterNumber(
            "dem_sampling",
            "DEM layer sampling factor",
            defaultValue=defaultValue,
            minValue=1,
        )
        self.addParameter(param)
        param.setFlags(param.flags()
                       | QgsProcessingParameterDefinition.FlagAdvanced)

        defaultValue, _ = project.readEntry("qgis2fds", "landuse_layer", None)
        self.addParameter(
            QgsProcessingParameterRasterLayer(
                "landuse_layer",
                "Landuse layer (if not set, landuse is not exported)",
                optional=True,
                defaultValue=defaultValue,
            ))

        defaultValue, _ = project.readNumEntry("qgis2fds", "landuse_type", 0)
        self.addParameter(
            QgsProcessingParameterEnum(
                "landuse_type",
                "Landuse layer type",
                options=fds.landuse_types,
                allowMultiple=False,
                defaultValue=defaultValue,
            ))

        if project_crs_changed:
            defaultValue = None
        else:
            defaultValue, _ = project.readEntry("qgis2fds", "origin", None)
        param = QgsProcessingParameterPoint(
            "origin",
            "Domain origin (if not set, use Terrain Extent centroid)",
            optional=True,
            defaultValue=defaultValue,
        )
        self.addParameter(param)
        param.setFlags(param.flags()
                       | QgsProcessingParameterDefinition.FlagAdvanced)

        if project_crs_changed:
            defaultValue = None
        else:
            defaultValue, _ = project.readEntry("qgis2fds", "fire_origin",
                                                None)
        param = QgsProcessingParameterPoint(
            "fire_origin",
            "Fire origin (if not set, use Domain Origin)",
            optional=True,
            defaultValue=defaultValue,
        )
        self.addParameter(param)
        param.setFlags(param.flags()
                       | QgsProcessingParameterDefinition.FlagAdvanced)

        defaultValue, _ = project.readEntry("qgis2fds", "tex_layer", None)
        param = QgsProcessingParameterRasterLayer(
            "tex_layer",
            "Texture layer (if not set, current view is exported)",
            optional=True,
            defaultValue=defaultValue,
        )
        self.addParameter(param)
        param.setFlags(param.flags()
                       | QgsProcessingParameterDefinition.FlagAdvanced)

        defaultValue, _ = project.readNumEntry("qgis2fds", "tex_pixel_size", 5)
        param = QgsProcessingParameterNumber(
            "tex_pixel_size",
            "Texture layer pixels size (in meters)",
            type=QgsProcessingParameterNumber.Double,
            defaultValue=defaultValue,
            minValue=0.1,
        )
        self.addParameter(param)
        param.setFlags(param.flags()
                       | QgsProcessingParameterDefinition.FlagAdvanced)

        param = QgsProcessingParameterFeatureSink(
            "sampling_layer",
            "Sampling grid output layer",
            type=QgsProcessing.TypeVectorAnyGeometry,
            createByDefault=True,
            defaultValue=None,
        )
        self.addParameter(param)