예제 #1
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(
            QgsProcessingParameterString(
                self.FIELD,
                self.tr('Name of the field to create'),
                defaultValue='DN'))
        self.addParameter(
            QgsProcessingParameterBoolean(self.EIGHT_CONNECTEDNESS,
                                          self.tr('Use 8-connectedness'),
                                          defaultValue=False))

        self.addParameter(
            QgsProcessingParameterVectorDestination(
                self.OUTPUT, self.tr('Vectorized'),
                QgsProcessing.TypeVectorPolygon))
예제 #2
0
    def initAlgorithm(self, config=None):
        self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
                                                              self.tr('Input layer'),
                                                              [QgsProcessing.TypeVectorLine]))
        self.addParameter(QgsProcessingParameterString(self.GEOMETRY,
                                                       self.tr('Geometry column name'),
                                                       defaultValue='geometry'))
        self.addParameter(QgsProcessingParameterDistance(self.DISTANCE,
                                                         self.tr('Offset distance (left-sided: positive, right-sided: negative)'),
                                                         parentParameterName=self.INPUT,
                                                         defaultValue=10))

        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('Offset curve'),
                                                                  QgsProcessing.TypeVectorLine))
예제 #3
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 polygon geometry
        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.INPUT,
                self.tr('Input layer (connection)'),
                [QgsProcessing.TypeVectorPolygon]
            )
        )

        
        # 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(
            QgsProcessingParameterVectorDestination(
                self.OUTPUT,
                self.tr('Output layer')
            )
        )

        # Input tables
        self.addParameter(QgsProcessingParameterString(self.TABLE,
                                                       self.tr('Outer Polygon table'),
                                                       defaultValue=''))

        self.addParameter(QgsProcessingParameterString(self.TABLE2,
                                                       self.tr('Inner Polygon table'),
                                                       defaultValue=''))                                                       

        # Input Primary Key
        self.addParameter(QgsProcessingParameterString(self.PRIMARY_KEY,
                                                       self.tr('Outer Polygon Table Primary Key'),
                                                       defaultValue='id'))
예제 #4
0
    def initAlgorithm(self, config=None):
        self.addParameter(
            QgsProcessingParameterVectorLayer(
                self.INPUT,
                self.tr('Points'),
                types=[QgsProcessing.TypeVectorPoint],
                defaultValue=None))

        self.addParameter(
            QgsProcessingParameterRasterLayer(self.INPUT1,
                                              self.tr('Raster'),
                                              defaultValue=None))

        #self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, 'Output layer', type=QgsProcessing.TypeVectorAnyGeometry, createByDefault=True, defaultValue=None))

        self.addParameter(
            QgsProcessingParameterVectorDestination(
                self.OUTPUT,
                self.tr('Output layer'),
                type=QgsProcessing.TypeVectorAnyGeometry,
                createByDefault=True,
                defaultValue=None))

        self.addParameter(
            QgsProcessingParameterExtent(self.EXTENT,
                                         self.tr('Extension'),
                                         defaultValue=None))

        self.addParameter(
            QgsProcessingParameterNumber(
                self.NUMBER,
                self.tr('Buffer radious in pixels'),
                type=QgsProcessingParameterNumber.Integer))

        self.addParameter(
            QgsProcessingParameterNumber(
                self.NUMBER1,
                self.tr('Min value acceptable'),
                type=QgsProcessingParameterNumber.Integer))
예제 #5
0
 def initAlgorithm(self, config=None):
     self.addParameter(
         QgsProcessingParameterFeatureSource(
             self.INPUT,
             self.tr('Input layer'),
             types=[QgsProcessing.TypeVectorAnyGeometry]))
     self.addParameter(
         QgsProcessingParameterFeatureSource(
             self.POINT,
             self.tr('Point layer'),
             types=[QgsProcessing.TypeVectorPoint]))
     self.addParameter(
         QgsProcessingParameterField(
             self.POP_COLUMN,
             self.tr('Population field'),
             parentLayerParameterName=self.POINT,
             type=QgsProcessingParameterField.Numeric,
             optional=True))
     search_radius = QgsProcessingParameterDistance(
         self.SEARCH_RADIUS,
         self.tr('Search radius'),
         parentParameterName=self.INPUT)
     search_radius.setMetadata({'widget_wrapper': {'decimals': 2}})
     self.addParameter(search_radius)
     self.addParameter(
         QgsProcessingParameterEnum(
             self.AREA_UNIT,
             self.tr('Area unit (for density value)'),
             options=[u[1] for u in self.area_unit],
             defaultValue=0))
     self.addParameter(
         QgsProcessingParameterString(
             name=self.OUTPUT_COLUMN,
             description=self.tr('Output column name'),
         ))
     self.addParameter(
         QgsProcessingParameterVectorDestination(self.OUTPUT,
                                                 self.tr('Output layer')))
    def initAlgorithm(self, config=None):
        self.addParameter(
            QgsProcessingParameterVectorLayer(
                'addresslayer',
                '住所レイヤ',
                types=[QgsProcessing.TypeVectorPolygon],
                defaultValue=None))
        self.addParameter(
            QgsProcessingParameterField(
                'addressfield',
                '住所フィールド',
                type=QgsProcessingParameterField.String,
                parentLayerParameterName='addresslayer',
                allowMultiple=False,
                defaultValue=None))

        #self.addParameter(QgsProcessingParameterFile('CSVfile', 'CSV file', behavior=QgsProcessingParameterFile.File, fileFilter='All Files(*.*)', defaultValue=None))
        self.addParameter(
            QgsProcessingParameterFile('INPUT', '入力csvファイル指定',
                                       extension='csv'))

        self.addParameter(
            QgsProcessingParameterEnum('ENCODING',
                                       'ENCODE',
                                       options=['SJIS', 'UTF-8'],
                                       allowMultiple=False,
                                       defaultValue=None))

        self.addParameter(
            QgsProcessingParameterCrs('CRS', "出力ファイル座標系", optional=True))

        self.addParameter(
            QgsProcessingParameterVectorDestination(
                'OUTPUT',
                '出力ファイル名',
                type=QgsProcessing.TypeVectorAnyGeometry,
                createByDefault=True,
                defaultValue=None))
예제 #7
0
    def initAlgorithm(self, config=None):
        self.addParameter(
            QgsProcessingParameterRasterLayer(self.INPUT,
                                              self.tr('Input layer')))
        self.addParameter(
            QgsProcessingParameterRasterLayer(self.SAMPLES,
                                              self.tr('Samples layer')))

        params = []
        params.append(
            QgsProcessingParameterString(
                self.CLASSES,
                self.tr('Classes to extract from raster'),
                defaultValue=None,
                optional=True))
        params.append(
            QgsProcessingParameterNumber(
                self.THRESHOLD,
                self.tr('Probability threshold for selecting samples'),
                type=QgsProcessingParameterNumber.Double,
                minValue=0,
                maxValue=100,
                defaultValue=None,
                optional=True))
        params.append(
            QgsProcessingParameterString(self.ARGUMENTS,
                                         self.tr('Additional arguments'),
                                         defaultValue=None,
                                         optional=True))

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

        self.addParameter(
            QgsProcessingParameterVectorDestination(self.OUTPUT,
                                                    self.tr('Output file')))
예제 #8
0
    def testVectorDestination(self):
        param = QgsProcessingParameterVectorDestination('test')
        alg = QgsApplication.processingRegistry().algorithmById(
            'native:centroids')
        panel = DestinationSelectionPanel(param, alg)

        panel.setValue('''ogr:dbname='/me/a.gpkg' table="d" (geom) sql=''')
        v = panel.getValue()
        self.assertIsInstance(v, QgsProcessingOutputLayerDefinition)
        self.assertEqual(v.createOptions, {'fileEncoding': 'System'})
        self.assertEqual(v.sink.staticValue(),
                         '''ogr:dbname='/me/a.gpkg' table="d" (geom) sql=''')

        panel.setValue(
            '''postgis:dbname='oraclesux' host=10.1.1.221 port=5432 user='******' password='******' table="stufff"."output" (the_geom) sql='''
        )
        v = panel.getValue()
        self.assertIsInstance(v, QgsProcessingOutputLayerDefinition)
        self.assertEqual(v.createOptions, {'fileEncoding': 'System'})
        self.assertEqual(
            v.sink.staticValue(),
            '''postgis:dbname='oraclesux' host=10.1.1.221 port=5432 user='******' password='******' table="stufff"."output" (the_geom) sql='''
        )

        panel.setValue('/home/me/test.shp')
        v = panel.getValue()
        self.assertIsInstance(v, QgsProcessingOutputLayerDefinition)
        self.assertEqual(v.createOptions, {'fileEncoding': 'System'})
        self.assertEqual(v.sink.staticValue(), '/home/me/test.shp')

        ProcessingConfig.setSettingValue(ProcessingConfig.OUTPUT_FOLDER,
                                         testDataPath)
        panel.setValue('test.shp')
        v = panel.getValue()
        self.assertIsInstance(v, QgsProcessingOutputLayerDefinition)
        self.assertEqual(v.createOptions, {'fileEncoding': 'System'})
        self.assertEqual(v.sink.staticValue(),
                         os.path.join(testDataPath, 'test.shp'))
 def initAlgorithm(self, config=None):
     self.addParameter(
         QgsProcessingParameterFeatureSource(self.LIGHTING,
                                             self.tr('Lighting layer')))
     self.addParameter(
         QgsProcessingParameterString(self.FLUX_FIELD_NAME,
                                      self.tr('Flux field name'),
                                      defaultValue="flux"))
     self.addParameter(
         QgsProcessingParameterBoolean(
             self.OVERWRITE,
             self.tr('Edit layer in place (new layer if unchecked)'),
             defaultValue=False))
     # self.addParameter(
     # QgsProcessingParameterField(
     # self.LIGHT_TYPE_FIELD,
     # description=self.tr('Light type field'),
     # defaultValue=self.DEFAULT_LIGHT_TYPE,
     # parentLayerParameterName=self.LIGHTING))
     # self.addParameter(
     # QgsProcessingParameterFile(
     # self.LIGHT_TYPE_ASSOC,
     # self.tr('Association file (light type -> light type)')))
     # self.addParameter(
     # QgsProcessingParameterFile(
     # self.FLUX_ASSOC,
     # self.tr('Association file (light type -> flux)')))
     self.addParameter(
         QgsProcessingParameterFile(
             self.LED_ASSOC,
             self.
             tr('LED efficacy association file (LED model -> luminous efficacy)'
                ),
             defaultValue=self.DEFAULT_LED_ASSOC))
     self.addParameter(
         QgsProcessingParameterVectorDestination(self.OUTPUT,
                                                 self.tr('Output layer'),
                                                 optional=True))
예제 #10
0
 def initAlgorithm(self, config=None):
     self.addParameter(
         QgsProcessingParameterFeatureSource(
             self.INPUT,
             self.tr('Input layer'),
             types=[QgsProcessing.TypeVectorAnyGeometry]))
     self.addParameter(
         QgsProcessingParameterField(
             self.FIELDS,
             self.tr('Fields'),
             parentLayerParameterName=self.INPUT,
             type=QgsProcessingParameterField.Numeric,
             allowMultiple=True))
     self.addParameter(
         QgsProcessingParameterString(
             self.WEIGHTS,
             self.tr('Weights (equals to the number of fields)')))
     self.addParameter(
         QgsProcessingParameterString(self.OUTPUT_COLUMN,
                                      self.tr('Output field name')))
     self.addParameter(
         QgsProcessingParameterVectorDestination(self.OUTPUT,
                                                 self.tr('Output layer')))
예제 #11
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.TypeVectorLine]
            )
        )
         
      
        self.addParameter(
            QgsProcessingParameterVectorDestination(
                self.OUTPUT,
                self.tr('Output Lineament Layer'),
            )
        )
예제 #12
0
파일: polygonize.py 프로젝트: zyhgit/QGIS
    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(QgsProcessingParameterString(self.FIELD,
                                                       self.tr('Name of the field to create'),
                                                       defaultValue='DN'))
        self.addParameter(QgsProcessingParameterBoolean(self.EIGHT_CONNECTEDNESS,
                                                        self.tr('Use 8-connectedness'),
                                                        defaultValue=False))

        extra_param = QgsProcessingParameterString(self.EXTRA,
                                                   self.tr('Additional command-line parameters'),
                                                   defaultValue=None,
                                                   optional=True)
        extra_param.setFlags(extra_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(extra_param)

        self.addParameter(QgsProcessingParameterVectorDestination(self.OUTPUT,
                                                                  self.tr('Vectorized'),
                                                                  QgsProcessing.TypeVectorPolygon))
예제 #13
0
    def initAlgorithm(self, config=None):
        self.addParameter(
            QgsProcessingParameterRasterLayer(self.D8_FLOWDIR,
                                              self.tr("D8 flow directions")))
        self.addParameter(
            QgsProcessingParameterRasterLayer(self.STREAM_RASTER,
                                              self.tr("Stream raster")))
        self.addParameter(
            QgsProcessingParameterVectorLayer(
                self.OUTLETS,
                self.tr("Outlets"),
                types=[QgsProcessing.TypeVectorPoint],
                optional=False))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.CELLS_TRAVERSE,
                self.tr("Maximum number of grid cells to traverse"),
                QgsProcessingParameterNumber.Integer, 50, False))

        self.addParameter(
            QgsProcessingParameterVectorDestination(
                self.MOVED_OUTLETS, self.tr("Moved outlets"),
                QgsProcessing.TypeVectorPoint))
예제 #14
0
    def initAlgorithm(self, config=None):
        self.directions = [
            'Direct: Old Data -> PT-TM06/ETRS89 [EPSG:3763]',
            'Inverse: PT-TM06/ETRS89 [EPSG:3763] -> Old Data'
        ]

        self.datums = (
            ('Datum Lisboa [EPSG:20791/EPSG:5018/ESRI:102165]', 20791),
            ('Datum Lisboa Militar [EPSG:20790/ESRI:102164]', 20790),
            ('Datum 73 [EPSG:27493/ESRI:102161]', 27493),
            ('Datum 73 Militar [ESRI:102160]', 102160),
            ('ED50 UTM 29N [EPSG:23029] (Only grid from José Alberto Gonçalves)',
             23029),
        )

        self.grids = (('José Alberto Gonçalves', 'pt_e89'),
                      ('Direção-Geral do Territorio', 'PT_ETRS89_geo'))

        self.addParameter(
            QgsProcessingParameterFeatureSource(self.INPUT, 'Input vector'))
        self.addParameter(
            QgsProcessingParameterEnum(self.TRANSF,
                                       'Transformation',
                                       options=self.directions,
                                       defaultValue=0))
        self.addParameter(
            QgsProcessingParameterEnum(self.CRS,
                                       'Old Datum',
                                       options=[i[0] for i in self.datums],
                                       defaultValue=0))
        self.addParameter(
            QgsProcessingParameterEnum(self.GRID,
                                       'NTv2 Grid',
                                       options=[i[0] for i in self.grids],
                                       defaultValue=0))
        self.addParameter(
            QgsProcessingParameterVectorDestination(self.OUTPUT, 'Output'))
    def initAlgorithm(self, config=None):
        """
        Here we define the inputs and output of the algorithm, along
        with some other properties.
        """

        self.addParameter(
            QgsProcessingParameterDistance(self.INPUT_DISTANCE,
                                           self.tr('Distance of the buffer')))
        self.addParameter(
            QgsProcessingParameterRasterLayer(self.INPUT_DEM,
                                              self.tr('Input DEM'),
                                              defaultValue=None))
        self.addParameter(
            QgsProcessingParameterVectorLayer(self.INPUT_POINTS,
                                              self.tr('Input points'),
                                              [QgsProcessing.TypeVectorPoint]))
        self.addParameter(
            QgsProcessingParameterVectorDestination(
                self.OUTPUT_SUMMIT,
                self.tr('Local summits near the points of interest'),
                type=QgsProcessing.TypeVectorAnyGeometry,
                createByDefault=True,
                defaultValue=None))
        self.addParameter(
            QgsProcessingParameterField(
                self.INPUT_FIELD,
                self.tr("Unique ID field"),
                optional=True,
                type=QgsProcessingParameterField.Any,
                parentLayerParameterName=self.INPUT_POINTS,
                allowMultiple=False,
                defaultValue=None))
        self.addParameter(
            QgsProcessingParameterFolderDestination(
                self.OUTPUT_FOLDER,
                self.tr("Folder for intermediate results")))
예제 #16
0
 def initAlgorithm(self, config=None):
     self.addParameter(
         QgsProcessingParameterFeatureSource(
             self.INPUT,
             self.tr('Input layer'),
             types=[QgsProcessing.TypeVectorAnyGeometry]))
     self.addParameter(
         QgsProcessingParameterFeatureSource(
             self.LINE,
             self.tr('Line layer'),
             types=[QgsProcessing.TypeVectorLine]))
     self.addParameter(
         QgsProcessingParameterNumber(
             self.CELL_SIZE,
             self.tr('Cell size for rasterizing line layer'),
             defaultValue=30,
             type=QgsProcessingParameterNumber.Double))
     self.addParameter(
         QgsProcessingParameterEnum(self.METHOD,
                                    self.tr('Distance method'),
                                    options=[m[1] for m in self.method],
                                    defaultValue=0))
     self.addParameter(
         QgsProcessingParameterEnum(
             self.DATA_TYPE,
             self.tr('Output data type'),
             options=[dtype[1] for dtype in self.data_type],
             defaultValue=1))
     self.addParameter(
         QgsProcessingParameterString(
             name=self.OUTPUT_COLUMN,
             description=self.tr('Output column name'),
         ))
     self.addParameter(
         QgsProcessingParameterVectorDestination(self.OUTPUT,
                                                 self.tr('Output layer')))
예제 #17
0
 def initAlgorithm(self, config=None, clip_flag=False, out_sink=True):
     self.addParameter(
         QgsProcessingParameterFeatureSource(
             self.INPUT, self.tr("Input layer"),
             [QgsProcessing.TypeVectorPolygon]))
     self.addParameter(
         QgsProcessingParameterFeatureSource(
             self.REPORTING, self.tr("Reporting layer"),
             [QgsProcessing.TypeVectorPolygon]))
     self.addParameter(
         QgsProcessingParameterCrs(self.CRS,
                                   description=self.tr("Output CRS"),
                                   defaultValue=params.defaultCrs))
     self.addParameter(
         QgsProcessingParameterBoolean(
             self.INCLUDE_CBC,
             self.tr("Include Cross-boundary connection metrics")))
     self.addParameter(
         QgsProcessingParameterEnum(
             self.UNIT,
             description=self.tr("Report areas unit"),
             options=self.getUnitOptions()))
     if clip_flag:
         self.addParameter(
             QgsProcessingParameterBoolean(
                 self.CLIP_FLAG,
                 self.tr("Clip input layer at reporting boundaries"),
                 defaultValue=False))
     if out_sink:
         self.addParameter(
             QgsProcessingParameterFeatureSink(self.OUTPUT,
                                               self.tr("Output layer")))
     else:
         self.addParameter(
             QgsProcessingParameterVectorDestination(
                 self.OUTPUT, self.tr("Output layer")))
예제 #18
0
 def initAlgorithm(self, config=None):
     self.addParameter(
         QgsProcessingParameterRasterLayer(
             name=self.INPUT,
             description=self.tr('Input Raster Layer'),
             defaultValue=None,
             optional=False))
     self.addParameter(
         QgsProcessingParameterBand(name=self.BAND,
                                    description=self.tr('Band Number'),
                                    defaultValue=1,
                                    parentLayerParameterName=self.INPUT,
                                    optional=False,
                                    allowMultiple=False))
     self.addParameter(
         QgsProcessingParameterBoolean(
             name=self.Z_POS_DOWN,
             description=self.tr('Raster Z positive down'),
             optional=False,
             defaultValue=False))
     self.addParameter(
         QgsProcessingParameterNumber(
             name=self.INTERVAL,
             description=self.tr('Contour Interval'),
             type=QgsProcessingParameterNumber.Integer,
             optional=False,
             defaultValue=self.interval,
             minValue=0,
             maxValue=12000))
     self.addParameter(
         QgsProcessingParameterVectorDestination(
             name=self.OUTPUT,
             description=self.tr('Contour File'),
             defaultValue=None,
             optional=False,
             createByDefault=False))
예제 #19
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.TypeVectorLine]))

        self.addParameter(
            QgsProcessingParameterNumber(self.INPUT_CELLSIZE,
                                         self.tr("Input Cell Size"),
                                         QgsProcessingParameterNumber.Double,
                                         1000))

        self.addParameter(
            QgsProcessingParameterVectorDestination(
                self.OUTPUT,
                self.tr('Output Density Grid'),
            ))
예제 #20
0
    def initAlgorithm(self, config=None):
        self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
                                                              self.tr('Input layer'),
                                                              [QgsProcessing.TypeVectorLine]))
        self.addParameter(QgsProcessingParameterString(self.GEOMETRY,
                                                       self.tr('Geometry column name'),
                                                       defaultValue='geometry'))
        self.addParameter(QgsProcessingParameterNumber(self.DISTANCE,
                                                       self.tr('Distance from line start represented as fraction of line length'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       minValue=0,
                                                       maxValue=1,
                                                       defaultValue=0.5))

        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('Points along lines'),
                                                                  QgsProcessing.TypeVectorPoint))
예제 #21
0
파일: contour.py 프로젝트: zy6p/QGIS
    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)

        extra_param = QgsProcessingParameterString(
            self.EXTRA,
            self.tr('Additional command-line parameters'),
            defaultValue=None,
            optional=True)
        extra_param.setFlags(extra_param.flags()
                             | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(extra_param)

        # TODO: remove in QGIS 4
        options_param = QgsProcessingParameterString(
            self.OPTIONS,
            self.tr('Additional creation options'),
            defaultValue='',
            optional=True)
        options_param.setFlags(options_param.flags()
                               | QgsProcessingParameterDefinition.FlagHidden)
        self.addParameter(options_param)

        self.addParameter(
            QgsProcessingParameterVectorDestination(
                self.OUTPUT, self.tr('Contours'),
                QgsProcessing.TypeVectorLine))
    def accept(self):
        description = self.nameTextBox.text()
        if description.strip() == '':
            QMessageBox.warning(self, self.tr('Unable to define parameter'),
                                self.tr('Invalid parameter name'))
            return
        if self.param is None:
            validChars = \
                'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
            safeName = ''.join(c for c in description if c in validChars)
            name = safeName.lower()
            i = 2
            while self.alg.parameterDefinition(name):
                name = safeName.lower() + str(i)
                i += 1
        else:
            name = self.param.name()
        if (self.paramType == parameters.PARAMETER_BOOLEAN
                or isinstance(self.param, QgsProcessingParameterBoolean)):
            self.param = QgsProcessingParameterBoolean(name, description,
                                                       self.state.isChecked())
        elif (self.paramType == parameters.PARAMETER_TABLE_FIELD
              or isinstance(self.param, QgsProcessingParameterField)):
            if self.parentCombo.currentIndex() < 0:
                QMessageBox.warning(
                    self, self.tr('Unable to define parameter'),
                    self.tr('Wrong or missing parameter values'))
                return
            parent = self.parentCombo.currentData()
            datatype = self.datatypeCombo.currentData()
            default = self.defaultTextBox.text()
            if not default:
                default = None
            self.param = QgsProcessingParameterField(
                name,
                description,
                defaultValue=default,
                parentLayerParameterName=parent,
                type=datatype,
                allowMultiple=self.multipleCheck.isChecked())
        elif (self.paramType == parameters.PARAMETER_BAND
              or isinstance(self.param, QgsProcessingParameterBand)):
            if self.parentCombo.currentIndex() < 0:
                QMessageBox.warning(
                    self, self.tr('Unable to define parameter'),
                    self.tr('Wrong or missing parameter values'))
                return
            parent = self.parentCombo.currentData()
            self.param = QgsProcessingParameterBand(name, description, None,
                                                    parent)
        elif (self.paramType == parameters.PARAMETER_MAP_LAYER
              or isinstance(self.param, QgsProcessingParameterMapLayer)):
            self.param = QgsProcessingParameterMapLayer(name, description)
        elif (self.paramType == parameters.PARAMETER_RASTER
              or isinstance(self.param, QgsProcessingParameterRasterLayer)):
            self.param = QgsProcessingParameterRasterLayer(name, description)
        elif (self.paramType == parameters.PARAMETER_TABLE
              or isinstance(self.param, QgsProcessingParameterVectorLayer)):
            self.param = QgsProcessingParameterVectorLayer(
                name, description, [self.shapetypeCombo.currentData()])
        elif (self.paramType == parameters.PARAMETER_VECTOR
              or isinstance(self.param, QgsProcessingParameterFeatureSource)):
            self.param = QgsProcessingParameterFeatureSource(
                name, description, [self.shapetypeCombo.currentData()])
        elif (self.paramType == parameters.PARAMETER_MULTIPLE
              or isinstance(self.param, QgsProcessingParameterMultipleLayers)):
            self.param = QgsProcessingParameterMultipleLayers(
                name, description, self.datatypeCombo.currentData())
        elif (self.paramType == parameters.PARAMETER_NUMBER or isinstance(
                self.param,
            (QgsProcessingParameterNumber, QgsProcessingParameterDistance))):
            try:
                self.param = QgsProcessingParameterNumber(
                    name, description, QgsProcessingParameterNumber.Double,
                    self.defaultTextBox.text())
                vmin = self.minTextBox.text().strip()
                if not vmin == '':
                    self.param.setMinimum(float(vmin))
                vmax = self.maxTextBox.text().strip()
                if not vmax == '':
                    self.param.setMaximum(float(vmax))
            except:
                QMessageBox.warning(
                    self, self.tr('Unable to define parameter'),
                    self.tr('Wrong or missing parameter values'))
                return
        elif (self.paramType == parameters.PARAMETER_EXPRESSION
              or isinstance(self.param, QgsProcessingParameterExpression)):
            parent = self.parentCombo.currentData()
            self.param = QgsProcessingParameterExpression(
                name, description, str(self.defaultEdit.expression()), parent)
        elif (self.paramType == parameters.PARAMETER_STRING
              or isinstance(self.param, QgsProcessingParameterString)):
            self.param = QgsProcessingParameterString(
                name, description, str(self.defaultTextBox.text()))
        elif (self.paramType == parameters.PARAMETER_EXTENT
              or isinstance(self.param, QgsProcessingParameterExtent)):
            self.param = QgsProcessingParameterExtent(name, description)
        elif (self.paramType == parameters.PARAMETER_FILE
              or isinstance(self.param, QgsProcessingParameterFile)):
            isFolder = self.fileFolderCombo.currentIndex() == 1
            self.param = QgsProcessingParameterFile(
                name, description, QgsProcessingParameterFile.Folder
                if isFolder else QgsProcessingParameterFile.File)
        elif (self.paramType == parameters.PARAMETER_POINT
              or isinstance(self.param, QgsProcessingParameterPoint)):
            self.param = QgsProcessingParameterPoint(
                name, description, str(self.defaultTextBox.text()))
        elif (self.paramType == parameters.PARAMETER_CRS
              or isinstance(self.param, QgsProcessingParameterCrs)):
            self.param = QgsProcessingParameterCrs(
                name, description,
                self.selector.crs().authid())
        elif (self.paramType == parameters.PARAMETER_ENUM
              or isinstance(self.param, QgsProcessingParameterEnum)):
            self.param = QgsProcessingParameterEnum(
                name, description, self.widget.options(),
                self.widget.allowMultiple(), self.widget.defaultOptions())
        elif (self.paramType == parameters.PARAMETER_MATRIX
              or isinstance(self.param, QgsProcessingParameterMatrix)):
            self.param = QgsProcessingParameterMatrix(
                name,
                description,
                hasFixedNumberRows=self.widget.fixedRows(),
                headers=self.widget.headers(),
                defaultValue=self.widget.value())

        # Destination parameter
        elif (isinstance(self.param, QgsProcessingParameterFeatureSink)):
            self.param = QgsProcessingParameterFeatureSink(
                name=name,
                description=self.param.description(),
                type=self.param.dataType(),
                defaultValue=self.defaultWidget.getValue())
        elif (isinstance(self.param, QgsProcessingParameterFileDestination)):
            self.param = QgsProcessingParameterFileDestination(
                name=name,
                description=self.param.description(),
                fileFilter=self.param.fileFilter(),
                defaultValue=self.defaultWidget.getValue())
        elif (isinstance(self.param, QgsProcessingParameterFolderDestination)):
            self.param = QgsProcessingParameterFolderDestination(
                name=name,
                description=self.param.description(),
                defaultValue=self.defaultWidget.getValue())
        elif (isinstance(self.param, QgsProcessingParameterRasterDestination)):
            self.param = QgsProcessingParameterRasterDestination(
                name=name,
                description=self.param.description(),
                defaultValue=self.defaultWidget.getValue())
        elif (isinstance(self.param, QgsProcessingParameterVectorDestination)):
            self.param = QgsProcessingParameterVectorDestination(
                name=name,
                description=self.param.description(),
                type=self.param.dataType(),
                defaultValue=self.defaultWidget.getValue())

        else:
            if self.paramType:
                typeId = self.paramType
            else:
                typeId = self.param.type()

            paramTypeDef = QgsApplication.instance().processingRegistry(
            ).parameterType(typeId)
            if not paramTypeDef:
                msg = self.tr(
                    'The parameter `{}` is not registered, are you missing a required plugin?'
                    .format(typeId))
                raise UndefinedParameterException(msg)
            self.param = paramTypeDef.create(name)
            self.param.setDescription(description)
            self.param.setMetadata(paramTypeDef.metadata())

        if not self.requiredCheck.isChecked():
            self.param.setFlags(
                self.param.flags()
                | QgsProcessingParameterDefinition.FlagOptional)
        else:
            self.param.setFlags(
                self.param.flags()
                & ~QgsProcessingParameterDefinition.FlagOptional)

        settings = QgsSettings()
        settings.setValue(
            "/Processing/modelParametersDefinitionDialogGeometry",
            self.saveGeometry())

        QDialog.accept(self)
예제 #23
0
    def initAlgorithm(self, config=None):
        self.addParameter(
            QgsProcessingParameterFeatureSource(self.INPUT,
                                                self.tr('Input layer')))
        self.addParameter(
            QgsProcessingParameterField(self.FIELD,
                                        self.tr('Dissolve field'),
                                        None,
                                        self.INPUT,
                                        QgsProcessingParameterField.Any,
                                        optional=True))
        self.addParameter(
            QgsProcessingParameterString(self.GEOMETRY,
                                         self.tr('Geometry column name'),
                                         defaultValue='geometry'))
        params = []
        params.append(
            QgsProcessingParameterBoolean(
                self.EXPLODE_COLLECTIONS,
                self.
                tr('Produce one feature for each geometry in any kind of geometry collection in the source file'
                   ),
                defaultValue=False))
        params.append(
            QgsProcessingParameterBoolean(self.KEEP_ATTRIBUTES,
                                          self.tr('Keep input attributes'),
                                          defaultValue=False))
        params.append(
            QgsProcessingParameterBoolean(self.COUNT_FEATURES,
                                          self.tr('Count dissolved features'),
                                          defaultValue=False))
        params.append(
            QgsProcessingParameterBoolean(
                self.COMPUTE_AREA,
                self.tr('Compute area and perimeter of dissolved features'),
                defaultValue=False))
        params.append(
            QgsProcessingParameterBoolean(
                self.COMPUTE_STATISTICS,
                self.tr('Compute min/max/sum/mean for attribute'),
                defaultValue=False))
        params.append(
            QgsProcessingParameterField(
                self.STATISTICS_ATTRIBUTE,
                self.tr('Numeric attribute to calculate statistics on'),
                None,
                self.INPUT,
                QgsProcessingParameterField.Numeric,
                optional=True))
        params.append(
            QgsProcessingParameterString(
                self.OPTIONS,
                self.tr('Additional creation options'),
                defaultValue='',
                optional=True))
        for param in params:
            param.setFlags(param.flags()
                           | QgsProcessingParameterDefinition.FlagAdvanced)
            self.addParameter(param)

        self.addParameter(
            QgsProcessingParameterVectorDestination(self.OUTPUT,
                                                    self.tr('Dissolved')))
 def initAlgorithm(self, config=None):
     self.cap_styles = [self.tr('Round'), 'Flat', 'Square']
     self.addParameter(
         QgsProcessingParameterFeatureSource(
             self.ROADS, self.tr('Roads layer'),
             [QgsProcessing.TypeVectorLine]))
     self.addParameter(
         QgsProcessingParameterExpression(
             self.SELECT_EXPR,
             self.tr(
                 'Expression to select features (all features if empty)'),
             defaultValue=RoadsExtentGrpAlg.DEFAULT_EXPR,
             optional=True,
             parentLayerParameterName=self.ROADS))
     self.addParameter(
         QgsProcessingParameterExpression(
             self.BUFFER_EXPR,
             self.tr('Roads buffer value'),
             defaultValue=self.DEFAULT_BUFFER_EXPR,
             parentLayerParameterName=self.ROADS))
     self.addParameter(
         QgsProcessingParameterEnum(self.END_CAP_STYLE,
                                    self.tr('End cap style'),
                                    options=self.cap_styles,
                                    defaultValue=0))
     # Join parameters
     self.addParameter(
         QgsProcessingParameterBoolean(self.DISSOLVE,
                                       self.tr('Join roads by name'),
                                       defaultValue=True))
     paramNameField = QgsProcessingParameterField(
         self.NAME_FIELD,
         self.tr('Roads name field'),
         defaultValue=self.DEFAULT_NAME_FIELD,
         parentLayerParameterName=self.ROADS)
     # paramIncludeNull = self.addParameter(
     # QgsProcessingParameterBoolean(
     # self.INCLUDE_NULL,
     # self.tr('Include roads with NULL name'),
     # defaultValue=True))
     paramJoinExpr = QgsProcessingParameterExpression(
         self.JOIN_EXPR,
         self.tr('Expression to select entities to join'),
         defaultValue=self.DEFAULT_JOIN_EXPR,
         parentLayerParameterName=self.ROADS)
     paramsJoin = [paramNameField, paramJoinExpr]
     for param in paramsJoin:
         param.setFlags(param.flags()
                        | QgsProcessingParameterDefinition.FlagAdvanced)
         self.addParameter(param)
     # self.addParameter(
     # QgsProcessingParameterMultipleLayers(
     # self.POLYGON_LAYERS,
     # self.tr('Polygon layers to include'),
     # layerType=QgsProcessing.TypeVectorPolygon,
     # optional=True))
     self.addParameter(
         QgsProcessingParameterVectorDestination(self.OUTPUT,
                                                 self.tr('Output layer')))
     self.addParameter(
         QgsProcessingParameterVectorDestination(self.OUTPUT_LINEAR,
                                                 self.tr('Linear output'),
                                                 optional=True))
예제 #25
0
 def initAlgorithm(self, config=None):
     self.addParameter(
         QgsProcessingParameterFeatureSource(
             self.TRACKS,
             self.tr("Tracks"),
             types=[QgsProcessing.TypeVectorLine],
             defaultValue=None,
         )
     )
     self.addParameter(
         QgsProcessingParameterFeatureSource(
             self.AXIS,
             self.tr("Axis"),
             types=[QgsProcessing.TypeVectorLine],
             defaultValue=None,
         )
     )
     self.addParameter(
         QgsProcessingParameterNumber(
             self.FIRST_SECTION_ABS_LONG,
             self.tr("Abscissa of first section"),
             type=QgsProcessingParameterNumber.Double,
             defaultValue=0,
             optional=True,
         )
     )
     self.addParameter(
         QgsProcessingParameterNumber(
             self.FIRST_AXIS_POINT_ABS_LONG,
             self.tr(
                 "Abscissa of axis first point"
                 " (take precedence over abscissa of first section when set)"
             ),
             type=QgsProcessingParameterNumber.Double,
             optional=True,
         )
     )
     self.addParameter(
         QgsProcessingParameterField(
             self.NAME_FIELD,
             self.tr("Name field"),
             optional=True,
             type=QgsProcessingParameterField.String,
             parentLayerParameterName=self.TRACKS,
             allowMultiple=False,
             defaultValue=None,
         )
     )
     self.addParameter(
         QgsProcessingParameterNumber(
             self.DISTANCE,
             self.tr("Maximum distance between two points"),
             type=QgsProcessingParameterNumber.Double,
             defaultValue=100,
         )
     )
     self.addParameter(
         QgsProcessingParameterBoolean(
             self.STRICT_DISTANCE,
             self.tr("Apply strict distance (do not keep initial points)"),
             defaultValue=True,
         )
     )
     self.addParameter(
         QgsProcessingParameterRasterLayer(
             self.DEM, self.tr("Digital Elevation Model"), defaultValue=None
         )
     )
     self.addParameter(
         QgsProcessingParameterVectorDestination(
             self.OUTPUT,
             self.tr("Sections"),
             type=QgsProcessing.TypeVectorAnyGeometry,
             createByDefault=True,
             defaultValue=None,
         )
     )
예제 #26
0
    def initAlgorithm(self, config=None):
        self.rules = (
            (self.tr('Single pixel'), 'point'),
            (self.tr('All pixels'), 'allpoints'),
            (self.tr('Centroid of the polygon'), 'centroid'),
            (self.tr('Average within polygon'), 'mean'),
            (self.tr('Standard deviation within polygon'), 'stdev'),
            (self.tr('Median within polygon'), 'median'),
            (self.tr('Minimum within polygon'), 'min'),
            (self.tr('Maximum within polygon'), 'max'),
            (self.tr('Sum within polygon'), 'sum'),
            (self.tr('Mode of classes within polygon'), 'mode'),
            (self.tr('Proportion of classes within polygon'), 'proportion'),
            (self.tr('Count of classes within polygon'), 'count'),
            (self.tr('Percentile of values within polygon'), 'percentile'),
        )

        self.addParameter(
            QgsProcessingParameterRasterLayer(self.INPUT,
                                              self.tr('Input layer')))
        self.addParameter(
            QgsProcessingParameterEnum(self.RULE,
                                       self.tr('Sampling rule'),
                                       options=[i[0] for i in self.rules],
                                       defaultValue=2))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.COUNT,
                self.tr('Number of points to generate'),
                type=QgsProcessingParameterNumber.Integer,
                minValue=0,
                defaultValue=100))

        params = []
        params.append(
            QgsProcessingParameterNumber(
                self.BUFFER,
                self.tr('Buffer for point features, pixels'),
                type=QgsProcessingParameterNumber.Integer,
                minValue=0,
                defaultValue=3))
        params.append(
            QgsProcessingParameterString(
                self.CLASSES,
                self.tr('Classes to extract from raster'),
                defaultValue=None,
                optional=True))
        params.append(
            QgsProcessingParameterNumber(
                self.THRESHOLD,
                self.tr('Probability threshold for selecting samples'),
                type=QgsProcessingParameterNumber.Double,
                minValue=0,
                maxValue=100,
                defaultValue=None,
                optional=True))
        params.append(
            QgsProcessingParameterNumber(
                self.PERCENTILE,
                self.tr('Percentile'),
                type=QgsProcessingParameterNumber.Double,
                minValue=0,
                maxValue=100,
                defaultValue=None,
                optional=True))
        params.append(
            QgsProcessingParameterString(self.ARGUMENTS,
                                         self.tr('Additional arguments'),
                                         defaultValue=None,
                                         optional=True))

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

        self.addParameter(
            QgsProcessingParameterVectorDestination(self.OUTPUT,
                                                    self.tr('Output file')))
예제 #27
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 has 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 pixel size (in meters)",
            type=QgsProcessingParameterNumber.Double,
            defaultValue=defaultValue,
            minValue=0.1,
        )
        self.addParameter(param)
        param.setFlags(param.flags()
                       | QgsProcessingParameterDefinition.FlagAdvanced)

        param = QgsProcessingParameterVectorDestination(
            "sampling_layer",
            "Sampling grid layer",
            type=QgsProcessing.TypeVectorPoint,
            createByDefault=True,
            defaultValue=None,
        )
        self.addParameter(param)
        param.setFlags(param.flags()
                       | QgsProcessingParameterDefinition.FlagAdvanced)

        if DEBUG:
            param = QgsProcessingParameterVectorDestination(
                "tex_extent_layer",  # Name
                "FDS texture",  # Description
                type=QgsProcessing.TypeVectorPolygon,
                createByDefault=True,
                defaultValue=None,
            )
            self.addParameter(param)

            param = QgsProcessingParameterVectorDestination(
                "dem_extent_layer",  # Name
                "FDS terrain extent layer",  # Description
                type=QgsProcessing.TypeVectorPolygon,
                createByDefault=True,
                defaultValue=None,
            )
            self.addParameter(param)

            param = QgsProcessingParameterVectorDestination(
                "utm_extent_layer",  # Name
                "FDS domain extent layer",  # Description
                type=QgsProcessing.TypeVectorPolygon,
                createByDefault=True,
                defaultValue=None,
            )
            self.addParameter(param)
예제 #28
0
def create_output_from_token(name: str, description: str, token: str):  # pylint: disable=too-many-branches
    """
    Creates an output (or destination parameter) definition from a token string
    """
    no_prompt = False
    if 'noprompt' in token:
        no_prompt = True
        token = token.replace(' noprompt', '')

    output_type = token.lower().strip()

    out = None
    if output_type.startswith('vector'):
        vector_type = QgsProcessing.TypeVectorAnyGeometry
        if output_type == 'vector point':
            vector_type = QgsProcessing.TypeVectorPoint
        elif output_type == 'vector line':
            vector_type = QgsProcessing.TypeVectorLine
        elif output_type == 'vector polygon':
            vector_type = QgsProcessing.TypeVectorPolygon
        if no_prompt:
            out = QgsProcessingOutputVectorLayer(name, description,
                                                 vector_type)
        else:
            out = QgsProcessingParameterVectorDestination(name,
                                                          description,
                                                          type=vector_type)
    elif output_type.startswith('table'):
        if no_prompt:
            out = QgsProcessingOutputVectorLayer(name, description,
                                                 QgsProcessing.TypeVector)
        else:
            out = QgsProcessingParameterVectorDestination(
                name, description, type=QgsProcessing.TypeVector)
    elif output_type == 'multilayers':
        # out = QgsProcessingOutputMultipleLayers(name, description)
        #            elif token.lower().strip() == 'vector point':
        #                out = OutputVector(datatype=[dataobjects.TYPE_VECTOR_POINT])
        #            elif token.lower().strip() == 'vector line':
        #                out = OutputVector(datatype=[OutputVector.TYPE_VECTOR_LINE])
        #            elif token.lower().strip() == 'vector polygon':
        #                out = OutputVector(datatype=[OutputVector.TYPE_VECTOR_POLYGON])
        #            elif token.lower().strip().startswith('table'):
        #                out = OutputTable()
        #            elif token.lower().strip().startswith('file'):
        #                out = OutputFile()
        #                ext = token.strip()[len('file') + 1:]
        #                if ext:
        #                    out.ext = ext
        #            elif token.lower().strip().startswith('extent'):
        #                out = OutputExtent()
        pass
    elif not no_prompt:
        if output_type.startswith('raster'):
            out = QgsProcessingParameterRasterDestination(name, description)
        elif output_type.startswith('folder'):
            out = QgsProcessingParameterFolderDestination(name, description)
        elif output_type.startswith('html'):
            out = QgsProcessingParameterFileDestination(
                name, description, 'HTML Files (*.html)')
    if not out and output_type in OUTPUT_FACTORY:
        return OUTPUT_FACTORY[output_type](name, description)

    return out
예제 #29
0
    def initAlgorithm(self, config):

        #분석지역
        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.IN_SITE,
                '❖ ' + self.tr('Analysis Site'),
                [QgsProcessing.TypeVectorPolygon],
                optional=False))

        # 기존 SOC 시설 레이어
        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.IN_CURSOC,
                '❖ ' + self.tr('Located Neighborhood Facility'),
                [QgsProcessing.TypeVectorPoint],
                optional=False))

        # 인구 레이어
        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.IN_POP,
                '❖ ' + self.tr('Resident Population'),
                [QgsProcessing.TypeVectorPoint],
                optional=False))

        # 인구 필드
        self.addParameter(
            QgsProcessingParameterField(self.IN_POP_CNTFID,
                                        self.tr('Population Field'),
                                        None,
                                        self.IN_POP,
                                        QgsProcessingParameterField.Numeric,
                                        optional=False))

        # 분석 최소단위(잠재적 위치 격자 사이즈)
        self.addParameter(
            QgsProcessingParameterNumber(
                self.IN_GRID_SIZE,
                '❖ ' + self.tr('Analysis Unit(Cell size : m)'),
                QgsProcessingParameterNumber.Integer, 1000, False, 100,
                10000)  #디폴트, 옵션, 미니멈, 맥시멈
        )
        # QgsProcessingParameterDefinition : 사용자 레이어 추가하여 잠재적 위치로 사용

        paramUsrgridlyr = QgsProcessingParameterFeatureSource(
            name=self.IN_USERGRID,
            description=self.tr('New Facility Location Review Area(Point)'),
            types=[QgsProcessing.TypeVectorPoint],
            defaultValue='',
            optional=True)
        paramUsrgridlyr.setFlags(
            paramUsrgridlyr.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(paramUsrgridlyr)

        # 거리 조락
        self.addParameter(
            QgsProcessingParameterNumber(
                self.IN_LIMIT_DIST,
                # "❖ " + self.tr('Facility Effective Service Coverage : If you input 0, it is regarded as the whole area'),
                "❖ " + self.tr('Facility Effective Service Coverage'),
                QgsProcessingParameterNumber.Integer,
                1000,
                False,
                0,
                1000000)  #디폴트, 옵션, 미니멈, 맥시멈
        )

        # 노드레이어
        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.IN_NODE,
                '❖ ' + self.tr('Node Layer'), [QgsProcessing.TypeVectorPoint],
                optional=False))
        # 노드레이어 PK
        self.addParameter(
            QgsProcessingParameterField(self.IN_NODE_ID,
                                        self.tr('Node ID FIELD'),
                                        None,
                                        self.IN_NODE,
                                        QgsProcessingParameterField.Any,
                                        optional=False))

        # 링크레이어
        self.addParameter(
            QgsProcessingParameterFeatureSource(self.IN_LINK,
                                                '❖ ' + self.tr('Link Layer'),
                                                [QgsProcessing.TypeVectorLine],
                                                optional=False))

        self.addParameter(
            QgsProcessingParameterEnum(
                self.IN_LINK_TYPE,
                self.tr('Network direction'),
                options=[self.tr('One-way'),
                         self.tr('Bidirectional')],
                defaultValue=1,
                optional=False))

        # 기점 노드 필드
        self.addParameter(
            QgsProcessingParameterField(self.IN_LINK_FNODE,
                                        self.tr('Origin field'),
                                        None,
                                        self.IN_LINK,
                                        QgsProcessingParameterField.Any,
                                        optional=False))

        self.addParameter(
            QgsProcessingParameterField(self.IN_LINK_TNODE,
                                        self.tr('Destination'),
                                        None,
                                        self.IN_LINK,
                                        QgsProcessingParameterField.Any,
                                        optional=False))

        self.addParameter(
            QgsProcessingParameterField(self.IN_LINK_LENGTH,
                                        self.tr('Link Length Field'),
                                        None,
                                        self.IN_LINK,
                                        QgsProcessingParameterField.Numeric,
                                        optional=False))
        self.addParameter(
            QgsProcessingParameterField(
                self.IN_LINK_SPEED,
                self.
                tr('Speed Field : If the speed value is zero, it is replaced by the minimum value'
                   ),
                None,
                self.IN_LINK,
                QgsProcessingParameterField.Numeric,
                optional=True))

        # 기존 SOC 서비스 중인 인구 제외 비율
        self.addParameter(
            QgsProcessingParameterNumber(
                self.IN_POP_EXCLUSION,
                '❖ ' + self.tr('Population Exclusion Ratio(%)'),
                QgsProcessingParameterNumber.Integer, 100, False, 0,
                100)  # 디폴트, 옵션, 미니멈, 맥시멈
        )

        # 등급
        self.addParameter(
            QgsProcessingParameterNumber(self.IN_CALSSIFYNUM, '❖' + self.tr(
                'Analysis result grade number of sections: configurable range (2 ~ 100)'
            ), QgsProcessingParameterNumber.Integer, 10, False, 2,
                                         100)  # 디폴트, 옵션, 미니멈, 맥시멈
        )

        # 최종 결과
        self.addParameter(
            QgsProcessingParameterVectorDestination(
                self.OUTPUT, self.tr('Efficiency Analysis Results(Network)')))
    def accept(self):
        description = self.nameTextBox.text()
        if description.strip() == '':
            QMessageBox.warning(self, self.tr('Unable to define parameter'),
                                self.tr('Invalid parameter name'))
            return

        validChars = \
            'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
        safeName = ''.join(c for c in description if c in validChars)
        name = safeName.lower()

        # Destination parameter
        if (isinstance(self.param, QgsProcessingParameterFeatureSink)):
            self.param = QgsProcessingParameterFeatureSink(
                name=name,
                description=description,
                type=self.param.dataType(),
                defaultValue=self.defaultWidget.value())
        elif (isinstance(self.param, QgsProcessingParameterFileDestination)):
            self.param = QgsProcessingParameterFileDestination(
                name=name,
                description=description,
                fileFilter=self.param.fileFilter(),
                defaultValue=self.defaultWidget.value())
        elif (isinstance(self.param, QgsProcessingParameterFolderDestination)):
            self.param = QgsProcessingParameterFolderDestination(
                name=name,
                description=description,
                defaultValue=self.defaultWidget.value())
        elif (isinstance(self.param, QgsProcessingParameterRasterDestination)):
            self.param = QgsProcessingParameterRasterDestination(
                name=name,
                description=description,
                defaultValue=self.defaultWidget.value())
        elif (isinstance(self.param, QgsProcessingParameterVectorDestination)):
            self.param = QgsProcessingParameterVectorDestination(
                name=name,
                description=description,
                type=self.param.dataType(),
                defaultValue=self.defaultWidget.value())

        else:
            if self.paramType:
                typeId = self.paramType
            else:
                typeId = self.param.type()

            paramTypeDef = QgsApplication.instance().processingRegistry(
            ).parameterType(typeId)
            if not paramTypeDef:
                msg = self.tr(
                    'The parameter `{}` is not registered, are you missing a required plugin?'
                    .format(typeId))
                raise UndefinedParameterException(msg)
            self.param = paramTypeDef.create(name)
            self.param.setDescription(description)
            self.param.setMetadata(paramTypeDef.metadata())

        if not self.requiredCheck.isChecked():
            self.param.setFlags(
                self.param.flags()
                | QgsProcessingParameterDefinition.FlagOptional)
        else:
            self.param.setFlags(
                self.param.flags()
                & ~QgsProcessingParameterDefinition.FlagOptional)

        if self.advancedCheck.isChecked():
            self.param.setFlags(
                self.param.flags()
                | QgsProcessingParameterDefinition.FlagAdvanced)
        else:
            self.param.setFlags(
                self.param.flags()
                & ~QgsProcessingParameterDefinition.FlagAdvanced)

        settings = QgsSettings()
        settings.setValue(
            "/Processing/modelParametersDefinitionDialogGeometry",
            self.saveGeometry())

        QDialog.accept(self)