Skip to content

Commit

Permalink
processing: add extent parameter to gdal rasterize
Browse files Browse the repository at this point in the history
  • Loading branch information
Giovanni Manghi committed Mar 6, 2016
1 parent 42d8884 commit e4f7567
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion python/plugins/processing/algs/gdal/rasterize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'))

Expand All @@ -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'),
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand Down

0 comments on commit e4f7567

Please sign in to comment.