diff --git a/python/plugins/processing/algs/gdal/GdalUtils.py b/python/plugins/processing/algs/gdal/GdalUtils.py index d244bcc0247d..b0564d59ec8a 100644 --- a/python/plugins/processing/algs/gdal/GdalUtils.py +++ b/python/plugins/processing/algs/gdal/GdalUtils.py @@ -29,7 +29,7 @@ import subprocess import platform from qgis.PyQt.QtCore import QSettings -from qgis.core import QgsApplication +from qgis.core import QgsApplication, QgsVectorFileWriter from processing.core.ProcessingLog import ProcessingLog from processing.core.SilentProgress import SilentProgress @@ -142,6 +142,19 @@ def getSupportedRasterExtensions(): allexts.append(ext) return allexts + @staticmethod + def getVectorDriverFromFileName(filename): + ext = os.path.splitext(filename)[1] + if ext == '': + return 'ESRI Shapefile' + + formats = QgsVectorFileWriter.supportedFiltersAndFormats() + for k, v in formats.iteritems(): + print k, v + if ext in k: + return v + return 'ESRI Shapefile' + @staticmethod def getFormatShortNameFromFilename(filename): ext = filename[filename.rfind('.') + 1:] diff --git a/python/plugins/processing/algs/gdal/contour.py b/python/plugins/processing/algs/gdal/contour.py index e9bde62262fa..b57a004b16e7 100644 --- a/python/plugins/processing/algs/gdal/contour.py +++ b/python/plugins/processing/algs/gdal/contour.py @@ -71,6 +71,8 @@ def defineCharacteristics(self): self.tr('Contours'))) def getConsoleCommands(self): + output = self.getOutputValue(self.OUTPUT_VECTOR) + print 'OUTPUT', output interval = unicode(self.getParameterValue(self.INTERVAL)) fieldName = unicode(self.getParameterValue(self.FIELD_NAME)) extra = self.getParameterValue(self.EXTRA) @@ -84,10 +86,15 @@ def getConsoleCommands(self): arguments.append('-i') arguments.append(interval) + driver = GdalUtils.getVectorDriverFromFileName(output) + print 'DRIVER', driver + arguments.append('-f') + arguments.append(driver) + if extra and len(extra) > 0: arguments.append(extra) arguments.append(self.getParameterValue(self.INPUT_RASTER)) - arguments.append(self.getOutputValue(self.OUTPUT_VECTOR)) + arguments.append(output) return ['gdal_contour', GdalUtils.escapeAndJoin(arguments)]