Skip to content

Commit

Permalink
[processing] fix gdal_contour algorithm
Browse files Browse the repository at this point in the history
(cherry picked from commit e4c1d89)

Conflicts:
	python/plugins/processing/algs/gdal/GdalUtils.py
  • Loading branch information
alexbruy committed Jun 22, 2016
1 parent d3d2603 commit 8778943
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
14 changes: 13 additions & 1 deletion python/plugins/processing/algs/gdal/GdalUtils.py
Expand Up @@ -29,7 +29,7 @@
import subprocess
import platform
from PyQt4.QtCore import QSettings
from qgis.core import QgsApplication
from qgis.core import QgsApplication, QgsVectorFileWriter
from processing.core.ProcessingLog import ProcessingLog

try:
Expand Down Expand Up @@ -130,6 +130,18 @@ 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():
if ext in k:
return v
return 'ESRI Shapefile'

@staticmethod
def getFormatShortNameFromFilename(filename):
ext = filename[filename.rfind('.') + 1:]
Expand Down
7 changes: 6 additions & 1 deletion python/plugins/processing/algs/gdal/contour.py
Expand Up @@ -62,6 +62,7 @@ def defineCharacteristics(self):
self.tr('Contours')))

def getConsoleCommands(self):
output = self.getOutputValue(self.OUTPUT_VECTOR)
interval = unicode(self.getParameterValue(self.INTERVAL))
fieldName = unicode(self.getParameterValue(self.FIELD_NAME))
extra = self.getParameterValue(self.EXTRA)
Expand All @@ -75,10 +76,14 @@ def getConsoleCommands(self):
arguments.append('-i')
arguments.append(interval)

driver = GdalUtils.getVectorDriverFromFileName(output)
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)]

0 comments on commit 8778943

Please sign in to comment.