當前位置: 首頁>>代碼示例>>Python>>正文


Python parameters.ParameterSelection類代碼示例

本文整理匯總了Python中processing.core.parameters.ParameterSelection的典型用法代碼示例。如果您正苦於以下問題:Python ParameterSelection類的具體用法?Python ParameterSelection怎麽用?Python ParameterSelection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ParameterSelection類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testMultiple

 def testMultiple(self):
     parameter = ParameterSelection("myName", "myDesc", ["option1", "option2", "option3"], multiple=True)
     self.assertEqual(parameter.setValue(1), True)
     self.assertEqual(parameter.value, 1)
     self.assertEqual(parameter.setValue([0, 1]), True)
     self.assertEqual(parameter.value, [0, 1])
     self.assertEqual(parameter.setValue(["0", "1"]), True)
     self.assertEqual(parameter.value, [0, 1])
開發者ID:kalxas,項目名稱:QGIS,代碼行數:8,代碼來源:ParametersTest.py

示例2: defineCharacteristicsFromFile

    def defineCharacteristicsFromFile(self):
        with open(self.descriptionFile) as lines:
            line = lines.readline().strip('\n').strip()
            self.name = line
            if '|' in self.name:
                tokens = self.name.split('|')
                self.name = tokens[0]
                #cmdname is the name of the algorithm in SAGA, that is, the name to use to call it in the console
                self.cmdname = tokens[1]

            else:
                self.cmdname = self.name
                self.i18n_name = QCoreApplication.translate("SAGAAlgorithm", str(self.name))
            #_commandLineName is the name used in processing to call the algorithm
            #Most of the time will be equal to the cmdname, but in same cases, several processing algorithms
            #call the same SAGA one
            self._commandLineName = self.createCommandLineName(self.name)
            self.name = decoratedAlgorithmName(self.name)
            self.i18n_name = QCoreApplication.translate("SAGAAlgorithm", str(self.name))
            line = lines.readline().strip('\n').strip()
            self.undecoratedGroup = line
            self.group = decoratedGroupName(self.undecoratedGroup)
            self.i18n_group = QCoreApplication.translate("SAGAAlgorithm", self.group)
            line = lines.readline().strip('\n').strip()
            while line != '':
                if line.startswith('Hardcoded'):
                    self.hardcodedStrings.append(line[len('Hardcoded|'):])
                elif line.startswith('Parameter'):
                    self.addParameter(getParameterFromString(line))
                elif line.startswith('AllowUnmatching'):
                    self.allowUnmatchingGridExtents = True
                elif line.startswith('NoResamplingChoice'):
                    self.noResamplingChoice = True
                elif line.startswith('Extent'):
                    # An extent parameter that wraps 4 SAGA numerical parameters
                    self.extentParamNames = line[6:].strip().split(' ')
                    self.addParameter(ParameterExtent(self.OUTPUT_EXTENT,
                                                      'Output extent'))
                else:
                    self.addOutput(getOutputFromString(line))
                line = lines.readline().strip('\n').strip()
            hasRaster = False
            for param in self.parameters:
                if (isinstance(param, ParameterRaster) or
                    (isinstance(param, ParameterMultipleInput)
                        and param.datatype == ParameterMultipleInput.TYPE_RASTER)):
                    hasRaster = True
                    break

            if (not self.noResamplingChoice and hasRaster):
                param = ParameterSelection(self.RESAMPLING, "Resampling method", ["Nearest Neighbour", "Bilinear Interpolation", "Bicubic Spline Interpolation", "B-Spline Interpolation"], 3)
                param.isAdvanced = True
                self.addParameter(param)
開發者ID:DHI-GRAS,項目名稱:ESA_Processing,代碼行數:53,代碼來源:SagaAlgorithm.py

示例3: __init__

    def __init__(self):
        super().__init__()
        self.addParameter(ParameterVector(self.INPUT_LAYER,
                                          self.tr('Point layer'), [dataobjects.TYPE_VECTOR_POINT]))
        self.addParameter(ParameterNumber(self.RADIUS,
                                          self.tr('Radius (layer units)'),
                                          0.0, 9999999999, 100.0))

        radius_field_param = ParameterTableField(self.RADIUS_FIELD,
                                                 self.tr('Radius from field'), self.INPUT_LAYER, optional=True, datatype=ParameterTableField.DATA_TYPE_NUMBER)
        radius_field_param.setFlags(radius_field_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(radius_field_param)

        class ParameterHeatmapPixelSize(ParameterNumber):

            def __init__(self, name='', description='', parent_layer=None, radius_param=None, radius_field_param=None, minValue=None, maxValue=None,
                         default=None, optional=False, metadata={}):
                ParameterNumber.__init__(self, name, description, minValue, maxValue, default, optional, metadata)
                self.parent_layer = parent_layer
                self.radius_param = radius_param
                self.radius_field_param = radius_field_param

        self.addParameter(ParameterHeatmapPixelSize(self.PIXEL_SIZE,
                                                    self.tr('Output raster size'), parent_layer=self.INPUT_LAYER, radius_param=self.RADIUS,
                                                    radius_field_param=self.RADIUS_FIELD,
                                                    minValue=0.0, maxValue=9999999999, default=0.1,
                                                    metadata={'widget_wrapper': HeatmapPixelSizeWidgetWrapper}))

        weight_field_param = ParameterTableField(self.WEIGHT_FIELD,
                                                 self.tr('Weight from field'), self.INPUT_LAYER, optional=True, datatype=ParameterTableField.DATA_TYPE_NUMBER)
        weight_field_param.setFlags(weight_field_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(weight_field_param)
        kernel_shape_param = ParameterSelection(self.KERNEL,
                                                self.tr('Kernel shape'), self.KERNELS)
        kernel_shape_param.setFlags(kernel_shape_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(kernel_shape_param)
        decay_ratio = ParameterNumber(self.DECAY,
                                      self.tr('Decay ratio (Triangular kernels only)'),
                                      -100.0, 100.0, 0.0)
        decay_ratio.setFlags(decay_ratio.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(decay_ratio)
        output_scaling = ParameterSelection(self.OUTPUT_VALUE,
                                            self.tr('Output value scaling'), self.OUTPUT_VALUES)
        output_scaling.setFlags(output_scaling.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(output_scaling)
        self.addOutput(OutputRaster(self.OUTPUT_LAYER,
                                    self.tr('Heatmap')))
開發者ID:rskelly,項目名稱:QGIS,代碼行數:47,代碼來源:Heatmap.py

示例4: testOptional

    def testOptional(self):
        optionalParameter = ParameterSelection(
            "myName", "myDesc", ["option1", "option2", "option3"], default=0, optional=True
        )
        self.assertEqual(optionalParameter.value, 0)
        optionalParameter.setValue(1)
        self.assertEqual(optionalParameter.value, 1)
        self.assertTrue(optionalParameter.setValue(None))
        self.assertEqual(optionalParameter.value, None)

        requiredParameter = ParameterSelection(
            "myName", "myDesc", ["option1", "option2", "option3"], default=0, optional=False
        )
        self.assertEqual(requiredParameter.value, 0)
        requiredParameter.setValue(1)
        self.assertEqual(requiredParameter.value, 1)
        self.assertFalse(requiredParameter.setValue(None))
        self.assertEqual(requiredParameter.value, 1)
開發者ID:kalxas,項目名稱:QGIS,代碼行數:18,代碼來源:ParametersTest.py

示例5: testSetValue

 def testSetValue(self):
     parameter = ParameterSelection("myName", "myDesc", ["option1", "option2", "option3"])
     self.assertIsNone(parameter.value)
     self.assertEqual(parameter.setValue(1), True)
     self.assertEqual(parameter.value, 1)
     self.assertEqual(parameter.setValue("1"), True)
     self.assertEqual(parameter.value, 1)
     self.assertEqual(parameter.setValue(1.0), True)
     self.assertEqual(parameter.value, 1)
     self.assertEqual(parameter.setValue("1a"), False)
     self.assertEqual(parameter.setValue([1]), False)
開發者ID:kalxas,項目名稱:QGIS,代碼行數:11,代碼來源:ParametersTest.py

示例6: testTupleOptions

    def testTupleOptions(self):
        options = (("o1", "option1"), ("o2", "option2"), ("o3", "option3"))

        optionalParameter = ParameterSelection("myName", "myDesc", options, default="o1")
        self.assertEqual(optionalParameter.value, "o1")
        optionalParameter.setValue("o2")
        self.assertEqual(optionalParameter.value, "o2")

        optionalParameter = ParameterSelection("myName", "myDesc", options, default=["o1", "o2"], multiple=True)
        self.assertEqual(optionalParameter.value, ["o1", "o2"])
        optionalParameter.setValue(["o2"])
        self.assertEqual(optionalParameter.value, ["o2"])
開發者ID:kalxas,項目名稱:QGIS,代碼行數:12,代碼來源:ParametersTest.py

示例7: testTupleOptions

    def testTupleOptions(self):
        options = (
            ('o1', 'option1'),
            ('o2', 'option2'),
            ('o3', 'option3'))

        optionalParameter = ParameterSelection('myName', 'myDesc', options, default='o1')
        self.assertEqual(optionalParameter.value, 'o1')
        optionalParameter.setValue('o2')
        self.assertEqual(optionalParameter.value, 'o2')

        optionalParameter = ParameterSelection('myName', 'myDesc', options, default=['o1', 'o2'], multiple=True)
        self.assertEqual(optionalParameter.value, ['o1', 'o2'])
        optionalParameter.setValue(['o2'])
        self.assertEqual(optionalParameter.value, ['o2'])
開發者ID:GeoCat,項目名稱:QGIS,代碼行數:15,代碼來源:ParametersTest.py


注:本文中的processing.core.parameters.ParameterSelection類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。