Skip to content
Permalink
Browse files

[processing] use core methods for raster and vector extensions handling

  • Loading branch information
alexbruy committed Dec 11, 2017
1 parent 48661ad commit 79d83f20667d0597fa0a677bd5d07117a341ed70
@@ -31,7 +31,8 @@
from qgis.core import (NULL,
QgsApplication,
QgsSettings,
QgsVectorFileWriter)
QgsVectorFileWriter,
QgsRasterFileWriter)
from processing.tools.system import defaultOutputFolder
import processing.tools.dataobjects

@@ -170,7 +171,7 @@ def initialize():
valuetype=Setting.SELECTION,
options=extensions))

extensions = processing.tools.dataobjects.getSupportedOutputRasterLayerExtensions()
extensions = QgsRasterFileWriter.supportedFormatExtensions()
ProcessingConfig.addSetting(Setting(
ProcessingConfig.tr('General'),
ProcessingConfig.DEFAULT_OUTPUT_RASTER_LAYER_EXT,
@@ -29,7 +29,8 @@
from qgis.core import (QgsProcessing,
QgsProviderRegistry,
QgsProcessingFeatureSourceDefinition,
QgsVectorFileWriter)
QgsVectorFileWriter,
QgsRasterFileWriter)
from qgis.PyQt.QtCore import QCoreApplication
from processing.tools import dataobjects

@@ -48,7 +49,7 @@ def getFileFilter(param):
"""
if param.type() == 'multilayer':
if param.layerType() == QgsProcessing.TypeRaster:
exts = dataobjects.getSupportedOutputRasterLayerExtensions()
exts = QgsRasterFileWriter.supportedFormatExtensions()
elif param.layerType() == QgsProcessing.TypeFile:
return tr('All files (*.*)', 'QgsProcessingParameterMultipleLayers')
else:
@@ -59,7 +60,12 @@ def getFileFilter(param):
elif param.type() == 'raster':
return QgsProviderRegistry.instance().fileRasterFilters()
elif param.type() == 'rasterDestination':
exts = dataobjects.getSupportedOutputRasterFilters()
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:
@@ -105,35 +105,6 @@ def createExpressionContext():
return context


def getSupportedOutputRasterLayerExtensions():
allexts = []
for exts in list(GdalUtils.getSupportedRasters().values()):
for ext in exts:
if ext != 'tif' and ext not in allexts:
allexts.append(ext)
allexts.sort()
allexts.insert(0, 'tif') # tif is the default, should be the first
return allexts


def getSupportedOutputRasterFilters():
"""
Return a list of file filters for supported raster formats.
Supported formats come from Gdal.
:return: a list of strings for Qt file filters.
"""
allFilters = []
supported = GdalUtils.getSupportedOutputRasters()
formatList = sorted(supported.keys())
# Place GTiff as the first format
if 'GTiff' in formatList:
formatList.pop(formatList.index('GTiff'))
formatList.insert(0, 'GTiff')
for f in formatList:
allFilters.append('{0} files (*.{1})'.format(f, ' *.'.join(supported[f])))
return allFilters


def load(fileName, name=None, crs=None, style=None, isRaster=False):
"""Loads a layer/table into the current project, given its file.
"""
@@ -18,6 +18,7 @@
#include "qgsprocessingprovider.h"
#include "qgsapplication.h"
#include "qgsvectorfilewriter.h"
#include "qgsrasterfilewriter.h"
#include "qgssettings.h"

QgsProcessingProvider::QgsProcessingProvider( QObject *parent SIP_TRANSFERTHIS )
@@ -47,7 +48,7 @@ QString QgsProcessingProvider::longName() const

QStringList QgsProcessingProvider::supportedOutputRasterLayerExtensions() const
{
return QStringList() << QStringLiteral( "tif" );
return QgsRasterFileWriter::supportedFormatExtensions();
}

void QgsProcessingProvider::refreshAlgorithms()
@@ -136,4 +137,3 @@ QString QgsProcessingProvider::defaultRasterFileExtension() const
return defaultExtension;
}
}

0 comments on commit 79d83f2

Please sign in to comment.
You can’t perform that action at this time.