当前位置: 首页>>代码示例>>Python>>正文


Python QgsVectorFileWriter.supportedFormatExtensions方法代码示例

本文整理汇总了Python中qgis.core.QgsVectorFileWriter.supportedFormatExtensions方法的典型用法代码示例。如果您正苦于以下问题:Python QgsVectorFileWriter.supportedFormatExtensions方法的具体用法?Python QgsVectorFileWriter.supportedFormatExtensions怎么用?Python QgsVectorFileWriter.supportedFormatExtensions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在qgis.core.QgsVectorFileWriter的用法示例。


在下文中一共展示了QgsVectorFileWriter.supportedFormatExtensions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getFileFilter

# 需要导入模块: from qgis.core import QgsVectorFileWriter [as 别名]
# 或者: from qgis.core.QgsVectorFileWriter import supportedFormatExtensions [as 别名]
def getFileFilter(param):
    """
    Returns a suitable file filter pattern for the specified parameter definition
    :param param:
    :return:
    """
    if param.type() == 'multilayer':
        if param.layerType() == QgsProcessingParameterDefinition.TypeRaster:
            exts = dataobjects.getSupportedOutputRasterLayerExtensions()
        elif param.layerType() == QgsProcessingParameterDefinition.TypeFile:
            return tr('All files (*.*)', 'QgsProcessingParameterMultipleLayers')
        else:
            exts = QgsVectorFileWriter.supportedFormatExtensions()
        for i in range(len(exts)):
            exts[i] = tr('{0} files (*.{1})', 'QgsProcessingParameterMultipleLayers').format(exts[i].upper(), exts[i].lower())
        return ';;'.join(exts)
    elif param.type() in ('raster', 'rasterOut'):
        exts = dataobjects.getSupportedOutputRasterLayerExtensions()
        for i in range(len(exts)):
            exts[i] = tr('{0} files (*.{1})', 'QgsProcessingParameterRasterOutput').format(exts[i].upper(), exts[i].lower())
        return ';;'.join(exts)
    elif param.type() == 'table':
        exts = ['csv', 'dbf']
        for i in range(len(exts)):
            exts[i] = tr('{0} files (*.{1})', 'ParameterTable').format(exts[i].upper(), exts[i].lower())
        return ';;'.join(exts)
    elif param.type() == 'sink':
        exts = QgsVectorFileWriter.supportedFormatExtensions()
        for i in range(len(exts)):
            exts[i] = tr('{0} files (*.{1})', 'ParameterVector').format(exts[i].upper(), exts[i].lower())
        return ';;'.join(exts)
    return ''
开发者ID:ndavid,项目名称:QGIS,代码行数:34,代码来源:ParameterGuiUtils.py

示例2: getOgrCompatibleSource

# 需要导入模块: from qgis.core import QgsVectorFileWriter [as 别名]
# 或者: from qgis.core.QgsVectorFileWriter import supportedFormatExtensions [as 别名]
 def getOgrCompatibleSource(self, parameter_name, parameters, context, feedback):
     """
     Interprets a parameter as an OGR compatible source and layer name
     """
     input_layer = self.parameterAsVectorLayer(parameters, parameter_name, context)
     ogr_data_path = None
     ogr_layer_name = None
     if input_layer is None:
         # parameter is not a vector layer - try to convert to a source compatible with OGR
         # and extract selection if required
         ogr_data_path = self.parameterAsCompatibleSourceLayerPath(parameters, parameter_name, context,
                                                                   QgsVectorFileWriter.supportedFormatExtensions(),
                                                                   feedback=feedback)
         ogr_layer_name = GdalUtils.ogrLayerName(ogr_data_path)
     elif input_layer.dataProvider().name() == 'ogr':
         # parameter is a vector layer, with OGR data provider
         # so extract selection if required
         ogr_data_path = self.parameterAsCompatibleSourceLayerPath(parameters, parameter_name, context,
                                                                   QgsVectorFileWriter.supportedFormatExtensions(),
                                                                   feedback=feedback)
         ogr_layer_name = GdalUtils.ogrLayerName(input_layer.dataProvider().dataSourceUri())
     else:
         # vector layer, but not OGR - get OGR compatible path
         # TODO - handle "selected features only" mode!!
         ogr_data_path = GdalUtils.ogrConnectionString(input_layer.dataProvider().dataSourceUri(), context)[1:-1]
         ogr_layer_name = GdalUtils.ogrLayerName(input_layer.dataProvider().dataSourceUri())
     return ogr_data_path, ogr_layer_name
开发者ID:GeoCat,项目名称:QGIS,代码行数:29,代码来源:GdalAlgorithm.py

示例3: getFileFilter

# 需要导入模块: from qgis.core import QgsVectorFileWriter [as 别名]
# 或者: from qgis.core.QgsVectorFileWriter import supportedFormatExtensions [as 别名]
def getFileFilter(param):
    """
    Returns a suitable file filter pattern for the specified parameter definition
    :param param:
    :return:
    """
    if param.type() == 'layer':
        vectors = QgsProviderRegistry.instance().fileVectorFilters().split(';;')
        vectors.pop(0)
        rasters = QgsProviderRegistry.instance().fileRasterFilters().split(';;')
        rasters.pop(0)
        filters = set(vectors + rasters)
        filters = sorted(filters)
        return tr('All files (*.*)') + ';;' + ";;".join(filters)
    elif param.type() == 'multilayer':
        if param.layerType() == QgsProcessing.TypeRaster:
            exts = QgsRasterFileWriter.supportedFormatExtensions()
        elif param.layerType() == QgsProcessing.TypeFile:
            return tr('All files (*.*)', 'QgsProcessingParameterMultipleLayers')
        else:
            exts = QgsVectorFileWriter.supportedFormatExtensions()
        for i in range(len(exts)):
            exts[i] = tr('{0} files (*.{1})', 'QgsProcessingParameterMultipleLayers').format(exts[i].upper(), exts[i].lower())
        return tr('All files (*.*)') + ';;' + ';;'.join(exts)
    elif param.type() == 'raster':
        return QgsProviderRegistry.instance().fileRasterFilters()
    elif param.type() == 'rasterDestination':
        if param.provider() is not None:
            exts = param.provider().supportedOutputRasterLayerExtensions()
        else:
            exts = QgsRasterFileWriter.supportedFormatExtensions()
        for i in range(len(exts)):
            exts[i] = tr('{0} files (*.{1})', 'ParameterRaster').format(exts[i].upper(), exts[i].lower())
        return ';;'.join(exts) + ';;' + tr('All files (*.*)')
    elif param.type() in ('sink', 'vectorDestination'):
        if param.provider() is not None:
            exts = param.provider().supportedOutputVectorLayerExtensions()
        else:
            exts = QgsVectorFileWriter.supportedFormatExtensions()
        for i in range(len(exts)):
            exts[i] = tr('{0} files (*.{1})', 'ParameterVector').format(exts[i].upper(), exts[i].lower())
        return ';;'.join(exts) + ';;' + tr('All files (*.*)')
    elif param.type() == 'source':
        return QgsProviderRegistry.instance().fileVectorFilters()
    elif param.type() == 'vector':
        return QgsProviderRegistry.instance().fileVectorFilters()
    elif param.type() == 'fileDestination':
        return param.fileFilter() + ';;' + tr('All files (*.*)')

    if param.defaultFileExtension():
        return tr('Default extension') + ' (*.' + param.defaultFileExtension() + ')'
    else:
        return ''
开发者ID:sbrunner,项目名称:QGIS,代码行数:55,代码来源:ParameterGuiUtils.py

示例4: getOgrCompatibleSource

# 需要导入模块: from qgis.core import QgsVectorFileWriter [as 别名]
# 或者: from qgis.core.QgsVectorFileWriter import supportedFormatExtensions [as 别名]
    def getOgrCompatibleSource(self, parameter_name, parameters, context, feedback, executing):
        """
        Interprets a parameter as an OGR compatible source and layer name
        :param executing:
        """
        if not executing and parameter_name in parameters and isinstance(parameters[parameter_name], QgsProcessingFeatureSourceDefinition):
            # if not executing, then we throw away all 'selected features only' settings
            # since these have no meaning for command line gdal use, and we don't want to force
            # an export of selected features only to a temporary file just to show the command!
            parameters = {parameter_name: parameters[parameter_name].source}

        input_layer = self.parameterAsVectorLayer(parameters, parameter_name, context)
        ogr_data_path = None
        ogr_layer_name = None
        if input_layer is None or input_layer.dataProvider().name() == 'memory':
            if executing:
                # parameter is not a vector layer - try to convert to a source compatible with OGR
                # and extract selection if required
                ogr_data_path = self.parameterAsCompatibleSourceLayerPath(parameters, parameter_name, context,
                                                                          QgsVectorFileWriter.supportedFormatExtensions(),
                                                                          feedback=feedback)
                ogr_layer_name = GdalUtils.ogrLayerName(ogr_data_path)
            else:
                #not executing - don't waste time converting incompatible sources, just return dummy strings
                #for the command preview (since the source isn't compatible with OGR, it has no meaning anyway and can't
                #be run directly in the command line)
                ogr_data_path = 'path_to_data_file'
                ogr_layer_name = 'layer_name'
        elif input_layer.dataProvider().name() == 'ogr':
            if executing and isinstance(parameters[parameter_name], QgsProcessingFeatureSourceDefinition) and parameters[parameter_name].selectedFeaturesOnly:
                # parameter is a vector layer, with OGR data provider
                # so extract selection if required
                ogr_data_path = self.parameterAsCompatibleSourceLayerPath(parameters, parameter_name, context,
                                                                          QgsVectorFileWriter.supportedFormatExtensions(),
                                                                          feedback=feedback)
                parts = QgsProviderRegistry.instance().decodeUri('ogr', ogr_data_path)
                ogr_data_path = parts['path']
                if 'layerName' in parts and parts['layerName']:
                    ogr_layer_name = parts['layerName']
                else:
                    ogr_layer_name = GdalUtils.ogrLayerName(ogr_data_path)
            else:
                #either not using the selection, or
                #not executing - don't worry about 'selected features only' handling. It has no meaning
                #for the command line preview since it has no meaning outside of a QGIS session!
                ogr_data_path = GdalUtils.ogrConnectionStringAndFormatFromLayer(input_layer)[0]
                ogr_layer_name = GdalUtils.ogrLayerName(input_layer.dataProvider().dataSourceUri())
        else:
            # vector layer, but not OGR - get OGR compatible path
            # TODO - handle "selected features only" mode!!
            ogr_data_path = GdalUtils.ogrConnectionStringFromLayer(input_layer)
            ogr_layer_name = GdalUtils.ogrLayerName(input_layer.dataProvider().dataSourceUri())
        return ogr_data_path, ogr_layer_name
开发者ID:manisandro,项目名称:QGIS,代码行数:55,代码来源:GdalAlgorithm.py

示例5: loadVectorLayerFromParameter

# 需要导入模块: from qgis.core import QgsVectorFileWriter [as 别名]
# 或者: from qgis.core.QgsVectorFileWriter import supportedFormatExtensions [as 别名]
    def loadVectorLayerFromParameter(self, name, parameters, context, feedback, external=False):
        """
        Creates a dedicated command to load a vector into
        the temporary GRASS DB.
        :param name: name of the parameter
        :param parameters: Parameters of the algorithm.
        :param context: Processing context
        :param external: use v.external (v.in.ogr if False).
        """
        layer = self.parameterAsVectorLayer(parameters, name, context)

        is_ogr_disk_based_layer = layer is not None and layer.dataProvider().name() == 'ogr'
        if is_ogr_disk_based_layer:
            # we only support direct reading of disk based ogr layers -- not ogr postgres layers, etc
            source_parts = QgsProviderRegistry.instance().decodeUri('ogr', layer.source())
            if not source_parts.get('path'):
                is_ogr_disk_based_layer = False
            elif source_parts.get('layerId'):
                # no support for directly reading layers by id in grass
                is_ogr_disk_based_layer = False

        if not is_ogr_disk_based_layer:
            # parameter is not a vector layer or not an OGR layer - try to convert to a source compatible with
            # grass OGR inputs and extract selection if required
            path = self.parameterAsCompatibleSourceLayerPath(parameters, name, context,
                                                             QgsVectorFileWriter.supportedFormatExtensions(),
                                                             feedback=feedback)
            ogr_layer = QgsVectorLayer(path, '', 'ogr')
            self.loadVectorLayer(name, ogr_layer, external=external, feedback=feedback)
        else:
            # already an ogr disk based layer source
            self.loadVectorLayer(name, layer, external=external, feedback=feedback)
开发者ID:tomkralidis,项目名称:QGIS,代码行数:34,代码来源:Grass7Algorithm.py

示例6: getOgrCompatibleSource

# 需要导入模块: from qgis.core import QgsVectorFileWriter [as 别名]
# 或者: from qgis.core.QgsVectorFileWriter import supportedFormatExtensions [as 别名]
 def getOgrCompatibleSource(self, parameter_name, parameters, context, feedback, executing):
     """
     Interprets a parameter as an OGR compatible source and layer name
     :param executing:
     """
     input_layer = self.parameterAsVectorLayer(parameters, parameter_name, context)
     ogr_data_path = None
     ogr_layer_name = None
     if input_layer is None:
         if executing:
             # parameter is not a vector layer - try to convert to a source compatible with OGR
             # and extract selection if required
             ogr_data_path = self.parameterAsCompatibleSourceLayerPath(parameters, parameter_name, context,
                                                                       QgsVectorFileWriter.supportedFormatExtensions(),
                                                                       feedback=feedback)
             ogr_layer_name = GdalUtils.ogrLayerName(ogr_data_path)
         else:
             #not executing - don't waste time converting incompatible sources, just return dummy strings
             #for the command preview (since the source isn't compatible with OGR, it has no meaning anyway and can't
             #be run directly in the command line)
             ogr_data_path = 'path_to_data_file'
             ogr_layer_name = 'layer_name'
     elif input_layer.dataProvider().name() == 'ogr':
         if executing:
             # parameter is a vector layer, with OGR data provider
             # so extract selection if required
             ogr_data_path = self.parameterAsCompatibleSourceLayerPath(parameters, parameter_name, context,
                                                                       QgsVectorFileWriter.supportedFormatExtensions(),
                                                                       feedback=feedback)
             ogr_layer_name = GdalUtils.ogrLayerName(input_layer.dataProvider().dataSourceUri())
         else:
             #not executing - don't worry about 'selected features only' handling. It has no meaning
             #for the command line preview since it has no meaning outside of a QGIS session!
             ogr_data_path = GdalUtils.ogrConnectionString(input_layer.dataProvider().dataSourceUri(), context)[1:-1]
             ogr_layer_name = GdalUtils.ogrLayerName(input_layer.dataProvider().dataSourceUri())
     else:
         # vector layer, but not OGR - get OGR compatible path
         # TODO - handle "selected features only" mode!!
         ogr_data_path = GdalUtils.ogrConnectionString(input_layer.dataProvider().dataSourceUri(), context)[1:-1]
         ogr_layer_name = GdalUtils.ogrLayerName(input_layer.dataProvider().dataSourceUri())
     return ogr_data_path, ogr_layer_name
开发者ID:mhugo,项目名称:QGIS,代码行数:43,代码来源:GdalAlgorithm.py

示例7: testSupportedFormatExtensions

# 需要导入模块: from qgis.core import QgsVectorFileWriter [as 别名]
# 或者: from qgis.core.QgsVectorFileWriter import supportedFormatExtensions [as 别名]
    def testSupportedFormatExtensions(self):
        formats = QgsVectorFileWriter.supportedFormatExtensions()
        self.assertTrue('gpkg' in formats)
        self.assertFalse('exe' in formats)
        self.assertEqual(formats[0], 'gpkg')
        self.assertEqual(formats[1], 'shp')
        self.assertTrue('ods' in formats)
        self.assertTrue('xtf' in formats)
        self.assertTrue('ili' in formats)

        for i in range(2, len(formats) - 1):
            self.assertLess(formats[i].lower(), formats[i + 1].lower())

        # alphabetical sorting
        formats2 = QgsVectorFileWriter.supportedFormatExtensions(QgsVectorFileWriter.VectorFormatOptions())
        self.assertTrue(formats2[0] < formats2[1])
        self.assertCountEqual(formats, formats2)
        self.assertNotEqual(formats2[0], 'gpkg')
        for i in range(0, len(formats2) - 1):
            self.assertLess(formats2[i].lower(), formats2[i + 1].lower())

        formats = QgsVectorFileWriter.supportedFormatExtensions(QgsVectorFileWriter.SkipNonSpatialFormats)
        self.assertFalse('ods' in formats)
开发者ID:boundlessgeo,项目名称:QGIS,代码行数:25,代码来源:test_qgsvectorfilewriter.py

示例8: getFileFilter

# 需要导入模块: from qgis.core import QgsVectorFileWriter [as 别名]
# 或者: from qgis.core.QgsVectorFileWriter import supportedFormatExtensions [as 别名]
 def getFileFilter(self, datatype):
     """
     Returns a suitable file filter pattern for the specified parameter definition
     :param param:
     :return:
     """
     if datatype == QgsProcessing.TypeRaster:
         return QgsProviderRegistry.instance().fileRasterFilters()
     elif datatype == QgsProcessing.TypeFile:
         return self.tr('All files (*.*)')
     else:
         exts = QgsVectorFileWriter.supportedFormatExtensions()
         for i in range(len(exts)):
             exts[i] = self.tr('{0} files (*.{1})').format(exts[i].upper(), exts[i].lower())
         return self.tr('All files (*.*)') + ';;' + ';;'.join(exts)
开发者ID:m-kuhn,项目名称:QGIS,代码行数:17,代码来源:MultipleInputDialog.py

示例9: processAlgorithm

# 需要导入模块: from qgis.core import QgsVectorFileWriter [as 别名]
# 或者: from qgis.core.QgsVectorFileWriter import supportedFormatExtensions [as 别名]
    def processAlgorithm(self, parameters, context, feedback):
        commands = self.getConsoleCommands(parameters)
        layers = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance())
        supported = QgsVectorFileWriter.supportedFormatExtensions()
        for i, c in enumerate(commands):
            for layer in layers:
                if layer.source() in c:
                    exported = dataobjects.exportVectorLayer(layer, supported)
                    exportedFileName = os.path.splitext(os.path.split(exported)[1])[0]
                    c = c.replace(layer.source(), exported)
                    if os.path.isfile(layer.source()):
                        fileName = os.path.splitext(os.path.split(layer.source())[1])[0]
                        c = re.sub('[\s]{}[\s]'.format(fileName), ' ' + exportedFileName + ' ', c)
                        c = re.sub('[\s]{}'.format(fileName), ' ' + exportedFileName, c)
                        c = re.sub('["\']{}["\']'.format(fileName), "'" + exportedFileName + "'", c)

            commands[i] = c
        GdalUtils.runGdal(commands, feedback)
开发者ID:ndavid,项目名称:QGIS,代码行数:20,代码来源:GdalAlgorithm.py

示例10: loadVectorLayerFromParameter

# 需要导入模块: from qgis.core import QgsVectorFileWriter [as 别名]
# 或者: from qgis.core.QgsVectorFileWriter import supportedFormatExtensions [as 别名]
 def loadVectorLayerFromParameter(self, name, parameters, context, feedback, external=False):
     """
     Creates a dedicated command to load a vector into
     the temporary GRASS DB.
     :param name: name of the parameter
     :param parameters: Parameters of the algorithm.
     :param context: Processing context
     :param external: use v.external (v.in.ogr if False).
     """
     layer = self.parameterAsVectorLayer(parameters, name, context)
     if layer is None or layer.dataProvider().name() != 'ogr':
         # parameter is not a vector layer or not an OGR layer - try to convert to a source compatible with
         # grass OGR inputs and extract selection if required
         path = self.parameterAsCompatibleSourceLayerPath(parameters, name, context,
                                                          QgsVectorFileWriter.supportedFormatExtensions(),
                                                          feedback=feedback)
         ogr_layer = QgsVectorLayer(path, '', 'ogr')
         self.loadVectorLayer(name, ogr_layer, external)
     else:
         # already an ogr layer source
         self.loadVectorLayer(name, layer, external)
开发者ID:tcoupin,项目名称:QGIS,代码行数:23,代码来源:Grass7Algorithm.py

示例11: addDirectory

# 需要导入模块: from qgis.core import QgsVectorFileWriter [as 别名]
# 或者: from qgis.core.QgsVectorFileWriter import supportedFormatExtensions [as 别名]
    def addDirectory(self):
        settings = QgsSettings()
        path = str(settings.value('/Processing/LastInputPath'))

        ret = QFileDialog.getExistingDirectory(self, self.tr('Select File(s)'), path)
        if ret:
            exts = []

            if self.datatype == QgsProcessing.TypeVector:
                exts = QgsVectorFileWriter.supportedFormatExtensions()
            elif self.datatype == QgsProcessing.TypeRaster:
                for t in QgsProviderRegistry.instance().fileRasterFilters().split(';;')[1:]:
                    for e in t[t.index('(') + 1:-1].split(' '):
                        if e != "*.*" and e.startswith("*."):
                            exts.append(e[2:])

            files = []
            for pp in Path(ret).rglob("*"):
                if not pp.is_file():
                    continue

                if exts and pp.suffix[1:] not in exts:
                    continue

                p = pp.as_posix()

                files.append(p)

            settings.setValue('/Processing/LastInputPath', ret)

            for filename in files:
                item = QStandardItem(filename)
                item.setData(filename, Qt.UserRole)
                item.setCheckState(Qt.Checked)
                item.setCheckable(True)
                item.setDropEnabled(False)
                self.model.appendRow(item)
开发者ID:digitalsatori,项目名称:QGIS,代码行数:39,代码来源:MultipleInputDialog.py

示例12: testSupportedFormatExtensions

# 需要导入模块: from qgis.core import QgsVectorFileWriter [as 别名]
# 或者: from qgis.core.QgsVectorFileWriter import supportedFormatExtensions [as 别名]
 def testSupportedFormatExtensions(self):
     formats = QgsVectorFileWriter.supportedFormatExtensions()
     self.assertTrue('gpkg' in formats)
     self.assertFalse('exe' in formats)
     self.assertEqual(formats[0], 'shp')
开发者ID:rskelly,项目名称:QGIS,代码行数:7,代码来源:test_qgsvectorfilewriter.py

示例13: supportedOutputVectorLayerExtensions

# 需要导入模块: from qgis.core import QgsVectorFileWriter [as 别名]
# 或者: from qgis.core.QgsVectorFileWriter import supportedFormatExtensions [as 别名]
 def supportedOutputVectorLayerExtensions(self):
     # We use the same extensions than QGIS because:
     # - QGIS is using OGR like GRASS
     # - There are very chances than OGR version used in GRASS is
     # different from QGIS OGR version.
     return QgsVectorFileWriter.supportedFormatExtensions()
开发者ID:tomkralidis,项目名称:QGIS,代码行数:8,代码来源:Grass7AlgorithmProvider.py

示例14: getSupportedOutputVectorLayerExtensions

# 需要导入模块: from qgis.core import QgsVectorFileWriter [as 别名]
# 或者: from qgis.core.QgsVectorFileWriter import supportedFormatExtensions [as 别名]
 def getSupportedOutputVectorLayerExtensions(self):
     exts = QgsVectorFileWriter.supportedFormatExtensions()
     if not self.hasGeometry():
         exts = ['dbf'] + [ext for ext in exts if ext in VectorWriter.nogeometry_extensions]
     return exts
开发者ID:cayetanobv,项目名称:QGIS,代码行数:7,代码来源:outputs.py

示例15: processCommand

# 需要导入模块: from qgis.core import QgsVectorFileWriter [as 别名]
# 或者: from qgis.core.QgsVectorFileWriter import supportedFormatExtensions [as 别名]
    def processCommand(self, parameters, context, feedback, delOutputs=False):
        """
        Prepare the GRASS algorithm command
        :param parameters:
        :param context:
        :param delOutputs: do not add outputs to commands.
        """
        noOutputs = [o for o in self.parameterDefinitions() if o not in self.destinationParameterDefinitions()]
        command = '{} '.format(self.grass7Name)
        command += '{}'.join(self.hardcodedStrings)

        # Add algorithm command
        for param in noOutputs:
            paramName = param.name()
            value = None

            # Exclude default GRASS parameters
            if paramName in [self.GRASS_REGION_CELLSIZE_PARAMETER,
                             self.GRASS_REGION_EXTENT_PARAMETER,
                             self.GRASS_MIN_AREA_PARAMETER,
                             self.GRASS_SNAP_TOLERANCE_PARAMETER,
                             self.GRASS_OUTPUT_TYPE_PARAMETER,
                             self.GRASS_REGION_ALIGN_TO_RESOLUTION,
                             self.GRASS_RASTER_FORMAT_OPT,
                             self.GRASS_RASTER_FORMAT_META,
                             self.GRASS_VECTOR_DSCO,
                             self.GRASS_VECTOR_LCO,
                             self.GRASS_VECTOR_EXPORT_NOCAT]:
                continue

            # Raster and vector layers
            if isinstance(param, (QgsProcessingParameterRasterLayer,
                                  QgsProcessingParameterVectorLayer,
                                  QgsProcessingParameterFeatureSource)):
                if paramName in self.exportedLayers:
                    value = self.exportedLayers[paramName]
                else:
                    value = self.parameterAsCompatibleSourceLayerPath(
                        parameters, paramName, context,
                        QgsVectorFileWriter.supportedFormatExtensions()
                    )
            # MultipleLayers
            elif isinstance(param, QgsProcessingParameterMultipleLayers):
                layers = self.parameterAsLayerList(parameters, paramName, context)
                values = []
                for idx in range(len(layers)):
                    layerName = '{}_{}'.format(paramName, idx)
                    values.append(self.exportedLayers[layerName])
                value = ','.join(values)
            # For booleans, we just add the parameter name
            elif isinstance(param, QgsProcessingParameterBoolean):
                if self.parameterAsBool(parameters, paramName, context):
                    command += ' {}'.format(paramName)
            # For Extents, remove if the value is null
            elif isinstance(param, QgsProcessingParameterExtent):
                if self.parameterAsExtent(parameters, paramName, context):
                    value = self.parameterAsString(parameters, paramName, context)
            # For enumeration, we need to grab the string value
            elif isinstance(param, QgsProcessingParameterEnum):
                # Handle multiple values
                if param.allowMultiple():
                    indexes = self.parameterAsEnums(parameters, paramName, context)
                else:
                    indexes = [self.parameterAsEnum(parameters, paramName, context)]
                if indexes:
                    value = '"{}"'.format(','.join([param.options()[i] for i in indexes]))
            # For strings, we just translate as string
            elif isinstance(param, QgsProcessingParameterString):
                data = self.parameterAsString(parameters, paramName, context)
                # if string is empty, we don't add it
                if len(data) > 0:
                    value = '"{}"'.format(
                        self.parameterAsString(parameters, paramName, context)
                    )
            # For fields, we just translate as string
            elif isinstance(param, QgsProcessingParameterField):
                value = ','.join(
                    self.parameterAsFields(parameters, paramName, context)
                )
            elif isinstance(param, QgsProcessingParameterFile):
                if self.parameterAsString(parameters, paramName, context):
                    value = '"{}"'.format(
                        self.parameterAsString(parameters, paramName, context)
                    )
            elif isinstance(param, QgsProcessingParameterPoint):
                if self.parameterAsString(parameters, paramName, context):
                    # parameter specified, evaluate as point
                    # TODO - handle CRS transform
                    point = self.parameterAsPoint(parameters, paramName, context)
                    value = '{},{}'.format(point.x(), point.y())
            # For numbers, we translate as a string
            elif isinstance(param, (QgsProcessingParameterNumber,
                                    QgsProcessingParameterPoint)):
                value = self.parameterAsString(parameters, paramName, context)
            # For everything else, we assume that it is a string
            else:
                value = '"{}"'.format(
                    self.parameterAsString(parameters, paramName, context)
                )
            if value:
#.........这里部分代码省略.........
开发者ID:tomkralidis,项目名称:QGIS,代码行数:103,代码来源:Grass7Algorithm.py


注:本文中的qgis.core.QgsVectorFileWriter.supportedFormatExtensions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。