Skip to content
Permalink
Browse files

processing: add extent parameter to gdal rasterize

  • Loading branch information
Giovanni Manghi
Giovanni Manghi committed Mar 6, 2016
1 parent 42d8884 commit e4f75672bc11dc40a18cbc0c8a24df3b1bfb597a
Showing with 19 additions and 1 deletion.
  1. +19 −1 python/plugins/processing/algs/gdal/rasterize.py
@@ -30,6 +30,7 @@
from PyQt4.QtGui import QIcon

from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterExtent
from processing.core.parameters import ParameterTableField
from processing.core.parameters import ParameterSelection
from processing.core.parameters import ParameterNumber
@@ -66,7 +67,8 @@ class rasterize(GdalAlgorithm):
BIGTIFFTYPE = ['', 'YES', 'NO', 'IF_NEEDED', 'IF_SAFER']
COMPRESSTYPE = ['NONE', 'JPEG', 'LZW', 'PACKBITS', 'DEFLATE']
TFW = 'TFW'

RAST_EXT = 'RAST_EXT'

def getIcon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'rasterize.png'))

@@ -86,6 +88,7 @@ def defineCharacteristics(self):
self.tr('Horizontal'), 0.0, 99999999.999999, 100.0))
self.addParameter(ParameterNumber(self.HEIGHT,
self.tr('Vertical'), 0.0, 99999999.999999, 100.0))
self.addParameter(ParameterExtent(self.RAST_EXT, self.tr('Raster extent')))

params = []
params.append(ParameterSelection(self.RTYPE, self.tr('Raster type'),
@@ -133,6 +136,7 @@ def getConsoleCommands(self):
tfw = unicode(self.getParameterValue(self.TFW))
out = self.getOutputValue(self.OUTPUT)
extra = unicode(self.getParameterValue(self.EXTRA))
rastext = unicode(self.getParameterValue(self.RAST_EXT))

arguments = []
arguments.append('-a')
@@ -143,6 +147,20 @@ def getConsoleCommands(self):
dimType = self.getParameterValue(self.DIMENSIONS)
arguments.append('-of')
arguments.append(GdalUtils.getFormatShortNameFromFilename(out))

regionCoords = rastext.split(',')
try:
rastext = []
rastext.append('-te')
rastext.append(regionCoords[0])
rastext.append(regionCoords[2])
rastext.append(regionCoords[1])
rastext.append(regionCoords[3])
except IndexError:
rastext = []
if rastext:
arguments.extend(rastext)

if dimType == 0:
# size in pixels
arguments.append('-ts')

0 comments on commit e4f7567

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