Exemple #1
0
    def testRange(self):
        # minimal test to check if wrapper generate GUI for each processign context
        self.checkConstructWrapper(QgsProcessingParameterRange('test'), RangeWidgetWrapper)

        alg = QgsApplication.processingRegistry().createAlgorithmById('native:centroids')
        dlg = AlgorithmDialog(alg)
        param = QgsProcessingParameterRange(
            name='test',
            description='test',
            type=QgsProcessingParameterNumber.Double,
            defaultValue="0.0,100.0")

        wrapper = RangeWidgetWrapper(param, dlg)
        widget = wrapper.createWidget()

        # range values check

        # check initial value
        self.assertEqual(widget.getValue(), '0.0,100.0')
        # check set/get
        widget.setValue("100.0,200.0")
        self.assertEqual(widget.getValue(), '100.0,200.0')
        # check that min/max are mutually adapted
        widget.setValue("200.0,100.0")
        self.assertEqual(widget.getValue(), '100.0,100.0')
        widget.spnMax.setValue(50)
        self.assertEqual(widget.getValue(), '50.0,50.0')
        widget.spnMin.setValue(100)
        self.assertEqual(widget.getValue(), '100.0,100.0')

        # check for integers
        param = QgsProcessingParameterRange(
            name='test',
            description='test',
            type=QgsProcessingParameterNumber.Integer,
            defaultValue="0.1,100.1")

        wrapper = RangeWidgetWrapper(param, dlg)
        widget = wrapper.createWidget()

        # range values check

        # check initial value
        self.assertEqual(widget.getValue(), '0.0,100.0')
        # check rounding
        widget.setValue("100.1,200.1")
        self.assertEqual(widget.getValue(), '100.0,200.0')
        widget.setValue("100.6,200.6")
        self.assertEqual(widget.getValue(), '101.0,201.0')
        # check set/get
        widget.setValue("100.1,200.1")
        self.assertEqual(widget.getValue(), '100.0,200.0')
        # check that min/max are mutually adapted
        widget.setValue("200.1,100.1")
        self.assertEqual(widget.getValue(), '100.0,100.0')
        widget.spnMax.setValue(50.1)
        self.assertEqual(widget.getValue(), '50.0,50.0')
        widget.spnMin.setValue(100.1)
        self.assertEqual(widget.getValue(), '100.0,100.0')
    def initAlgorithm(self, config=None):
        self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT,
                                                            self.tr('Input raster')))
        self.addParameter(QgsProcessingParameterRange(self.RANGE,
                                                     self.tr('Min and max values for color table'),
                                                     type=QgsProcessingParameterNumber.Double))
        self.addParameter(QgsProcessingParameterBoolean(self.GRAYSCALE,
                                                        self.tr('Greyscale color table'),
                                                        defaultValue=False))

        params = []
        params.append(QgsProcessingParameterString(self.ARGUMENTS,
                                                   self.tr('Additional arguments'),
                                                   defaultValue=None,
                                                   optional=True))

        options = QgsProcessingParameterString(self.OPTIONS,
                                               self.tr('Raster creation options'),
                                               defaultValue=None,
                                               optional=True)
        options.setMetadata({
            'widget_wrapper': {
                'class': 'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'}})
        params.append(options)

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

        self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                                  self.tr('Output file')))
    def initAlgorithm(self, config=None):
        self.addParameter(
            QgsProcessingParameterFeatureSource(self.INPUT,
                                                self.tr('Input layer')))
        self.addParameter(
            QgsProcessingParameterField(
                self.INPUT_FIELD,
                self.tr('Input field'),
                parentLayerParameterName=self.INPUT,
                type=QgsProcessingParameterField.String))
        self.addParameter(
            QgsProcessingParameterRange(
                self.RANGE,
                description=self.tr('Index range'),
                type=QgsProcessingParameterNumber.Integer,
                defaultValue=[0.0, 9999.0],
                optional=True))

        self.addParameter(
            QgsProcessingParameterString(
                self.OUTPUT_FIELD,
                self.tr('Output index field name'),
                defaultValue=self.OUTPUT_FIELD_DEFAULT))
        self.addParameter(
            QgsProcessingParameterFeatureSink(self.OUTPUT,
                                              self.tr("Output layer")))
Exemple #4
0
    def initAlgorithm(self, config):

        #---------------LAYER A
        self.addParameter(
            QgsProcessingParameterVectorLayer(
                self.LAYER_TO  #layer id
                ,
                self.tr('Layer with contours')  #display text
                ,
                [QgsProcessing.TypeVectorLine]  #layer types
                ,
                '',
                False  #[is Optional?]
            ))

        self.addParameter(
            QgsProcessingParameterField(
                self.VALUE_FIELD,
                self.tr('Field {} with contour value ').format(
                    self.VALUE_FIELD)  #display text
                ,
                '',
                self.LAYER_TO  #field layer
                ,
                QgsProcessingParameterField.Numeric,
                optional=False  #[is Optional?]
            ))
        self.addParameter(
            QgsProcessingParameterRange(
                name=self.LIMITS,
                description=self.tr('Interval limits')  #display text
                ,
                defaultValue='-20000,20000',
                optional=True))

        for [param_id, desc, is_optional, param_default] in self.PARAMS:
            self.addParameter(
                QgsProcessingParameterNumber(name=param_id,
                                             description=desc,
                                             defaultValue=param_default,
                                             optional=is_optional))
    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.

        # 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('Output layer')))

        self.addParameter(
            QgsProcessingParameterFolderDestination(self.INPUT,
                                                    'Dossier LAS/LAZ'))

        self.addParameter(QgsProcessingParameterRange(self.FORMAT, 'Format'))

        self.addParameter(QgsProcessingParameterCrs(self.CRS, 'Projection'))