Пример #1
0
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 ''
Пример #2
0
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 ''
Пример #3
0
 def getFileFilter(self, alg):
     exts = dataobjects.getSupportedOutputRasterLayerExtensions()
     for i in range(len(exts)):
         exts[i] = self.tr('{0} files (*.{1})',
                           'OutputVector').format(exts[i].upper(),
                                                  exts[i].lower())
     return ';;'.join(exts)
Пример #4
0
    def checkOutputFileExtensions(self):
        """Checks if the values of outputs are correct and have one of
        the supported output extensions.

        If not, it adds the first one of the supported extensions, which
        is assumed to be the default one.
        """
        for out in self.outputs:
            if not out.hidden and out.value is not None:
                if not os.path.isabs(out.value):
                    continue
                if isinstance(out, OutputRaster):
                    exts = dataobjects.getSupportedOutputRasterLayerExtensions()
                elif isinstance(out, OutputVector):
                    exts = dataobjects.getSupportedOutputVectorLayerExtensions()
                elif isinstance(out, OutputTable):
                    exts = dataobjects.getSupportedOutputTableExtensions()
                elif isinstance(out, OutputHTML):
                    exts = ["html", "htm"]
                else:
                    continue
                idx = out.value.rfind(".")
                if idx == -1:
                    out.value = out.value + "." + exts[0]
                else:
                    ext = out.value[idx + 1 :]
                    if ext not in exts:
                        out.value = out.value + "." + exts[0]
Пример #5
0
    def checkOutputFileExtensions(self):
        """Checks if the values of outputs are correct and have one of
        the supported output extensions.

        If not, it adds the first one of the supported extensions, which
        is assumed to be the default one.
        """
        for out in self.outputs:
            if not out.hidden and out.value is not None:
                if not os.path.isabs(out.value):
                    continue
                if isinstance(out, OutputRaster):
                    exts = \
                        dataobjects.getSupportedOutputRasterLayerExtensions()
                elif isinstance(out, OutputVector):
                    exts = \
                        dataobjects.getSupportedOutputVectorLayerExtensions()
                elif isinstance(out, OutputTable):
                    exts = dataobjects.getSupportedOutputTableExtensions()
                elif isinstance(out, OutputHTML):
                    exts = ['html', 'htm']
                else:
                    continue
                idx = out.value.rfind('.')
                if idx == -1:
                    out.value = out.value + '.' + exts[0]
                else:
                    ext = out.value[idx + 1:]
                    if ext not in exts:
                        out.value = out.value + '.' + exts[0]
Пример #6
0
def getFileFilter(param):
    """
    Returns a suitable file filter pattern for the specified parameter definition
    :param param:
    :return:
    """
    if param.type() == 'multilayer':
        if param.layerType() == QgsProcessing.TypeRaster:
            exts = dataobjects.getSupportedOutputRasterLayerExtensions()
        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':
        exts = dataobjects.getSupportedOutputRasterLayerExtensions()
        for i in range(len(exts)):
            exts[i] = tr('{0} files (*.{1})',
                         'QgsProcessingParameterRasterDestination').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 (*.*)')

    return ''
 def getFileFilter(self):
     if self.datatype == ParameterMultipleInput.TYPE_RASTER:
         exts = dataobjects.getSupportedOutputRasterLayerExtensions()
     else:
         exts = dataobjects.getSupportedOutputVectorLayerExtensions()
     for i in range(len(exts)):
         exts[i] = exts[i].upper() + ' files(*.' + exts[i].lower() + ')'
     return ';;'.join(exts)
Пример #8
0
 def getFileFilter(self):
     if self.datatype == ParameterMultipleInput.TYPE_RASTER:
         exts = dataobjects.getSupportedOutputRasterLayerExtensions()
     else:
         exts = dataobjects.getSupportedOutputVectorLayerExtensions()
     for i in range(len(exts)):
         exts[i] = exts[i].upper() + ' files(*.' + exts[i].lower() + ')'
     return ';;'.join(exts)
Пример #9
0
 def getFileFilter(self):
     if self.datatype == ParameterMultipleInput.TYPE_RASTER:
         exts = dataobjects.getSupportedOutputRasterLayerExtensions()
     elif self.datatype == ParameterMultipleInput.TYPE_FILE:
         return self.tr('All files (*.*)', 'ParameterMultipleInput')
     else:
         exts = dataobjects.getSupportedOutputVectorLayerExtensions()
     for i in range(len(exts)):
         exts[i] = self.tr('%s files(*.%s)', 'ParameterMultipleInput') % (exts[i].upper(), exts[i].lower())
     return ';;'.join(exts)
Пример #10
0
 def getFileFilter(self, alg):
     providerExts = alg.provider.getSupportedOutputRasterLayerExtensions()
     if providerExts == ['tif']:
         # use default extensions
         exts = dataobjects.getSupportedOutputRasterLayerExtensions()
     else:
         # use extensions given by the algorithm provider
         exts = providerExts
     for i in range(len(exts)):
         exts[i] = self.tr('%s files(*.%s)', 'OutputRaster') % (exts[i].upper(), exts[i].lower())
     return ';;'.join(exts)
Пример #11
0
 def getFileFilter(self, alg):
     providerExts = alg.provider.getSupportedOutputRasterLayerExtensions()
     if providerExts == ['tif']:
         # use default extensions
         exts = dataobjects.getSupportedOutputRasterLayerExtensions()
     else:
         # use extensions given by the algorithm provider
         exts = providerExts
     for i in range(len(exts)):
         exts[i] = self.tr('%s files(*.%s)', 'OutputRaster') % (exts[i].upper(), exts[i].lower())
     return ';;'.join(exts)
Пример #12
0
def getFileFilter(param):
    """
    Returns a suitable file filter pattern for the specified parameter definition
    :param param:
    :return:
    """
    if param.type() == 'multilayer':
        if param.layerType() == QgsProcessing.TypeRaster:
            exts = dataobjects.getSupportedOutputRasterLayerExtensions()
        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':
        exts = dataobjects.getSupportedOutputRasterFilters()
        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 (*.*)')

    return ''
Пример #13
0
 def getFileFilter(self):
     exts = dataobjects.getSupportedOutputRasterLayerExtensions()
     for i in range(len(exts)):
         exts[i] = self.tr('%s files(*.%s)', 'ParameterRaster') % (exts[i].upper(), exts[i].lower())
     return ';;'.join(exts)
Пример #14
0
 def getFileFilter(self):
     exts = dataobjects.getSupportedOutputRasterLayerExtensions()
     for i in range(len(exts)):
         exts[i] = exts[i].upper() + " files(*." + exts[i].lower() + ")"
     return ";;".join(exts)
Пример #15
0
 def getFileFilter(self, alg):
     exts = dataobjects.getSupportedOutputRasterLayerExtensions()
     for i in range(len(exts)):
         exts[i] = exts[i].upper() + ' files(*.' + exts[i].lower() + ')'
     return ';;'.join(exts)
Пример #16
0
 def getFileFilter(self):
     exts = dataobjects.getSupportedOutputRasterLayerExtensions()
     for i in range(len(exts)):
         exts[i] = self.tr("%s files(*.%s)", "ParameterRaster") % (exts[i].upper(), exts[i].lower())
     return ";;".join(exts)
Пример #17
0
 def getFileFilter(self, alg):
     exts = dataobjects.getSupportedOutputRasterLayerExtensions()
     for i in range(len(exts)):
         exts[i] = self.tr('%s files (*.%s)', 'OutputVector') % (exts[i].upper(), exts[i].lower())
     return ';;'.join(exts)
Пример #18
0
 def getFileFilter(self, alg):
     exts = dataobjects.getSupportedOutputRasterLayerExtensions()
     for i in range(len(exts)):
         exts[i] = exts[i].upper() + ' files(*.' + exts[i].lower() + ')'
     return ';;'.join(exts)