Skip to content

Commit

Permalink
[processing] fix gdal_contour algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Jun 22, 2016
1 parent f645b79 commit e4c1d89
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
15 changes: 14 additions & 1 deletion python/plugins/processing/algs/gdal/GdalUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:]
Expand Down
9 changes: 8 additions & 1 deletion python/plugins/processing/algs/gdal/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)]

0 comments on commit e4c1d89

Please sign in to comment.