Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #2873 from NaturalGIS/processing_add_extent_gdal_r…
…asterize

[processing] add extent parameter to gdal rasterize
  • Loading branch information
alexbruy committed Mar 8, 2016
2 parents e08130d + 2c7f40b commit dc137d7
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions python/plugins/processing/algs/gdal/rasterize.py
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,6 +67,7 @@ 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 dc137d7

Please sign in to comment.