Skip to content

Commit

Permalink
fix gdal_rasterize: remove duplicate options
Browse files Browse the repository at this point in the history
  • Loading branch information
Giovanni Manghi committed Apr 10, 2015
1 parent fa99a96 commit ed784d9
Showing 1 changed file with 20 additions and 25 deletions.
45 changes: 20 additions & 25 deletions python/plugins/processing/algs/gdal/rasterize.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class rasterize(OgrAlgorithm):
DIMENSIONS = 'DIMENSIONS'
WIDTH = 'WIDTH'
HEIGHT = 'HEIGHT'
WRITEOVER = 'WRITEOVER'
RTYPE = 'RTYPE'
OUTPUT = 'OUTPUT'
TYPE = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64']
Expand All @@ -71,8 +70,6 @@ def defineCharacteristics(self):
self.addParameter(ParameterVector(self.INPUT, self.tr('Input layer')))
self.addParameter(ParameterTableField(self.FIELD,
self.tr('Attribute field'), self.INPUT))
self.addParameter(ParameterBoolean(self.WRITEOVER,
self.tr('Write values inside an existing raster layer(*)'), False))
self.addParameter(ParameterSelection(self.DIMENSIONS,
self.tr('Set output raster size (ignored if above option is checked)'),
['Output size in pixels', 'Output resolution in map units per pixel'], 1))
Expand Down Expand Up @@ -103,10 +100,9 @@ def defineCharacteristics(self):
self.addParameter(ParameterBoolean(self.TFW,
self.tr('Force the generation of an associated ESRI world file (.tfw)'), False))
self.addOutput(OutputRaster(self.OUTPUT,
self.tr('Output layer: mandatory to choose an existing raster layer if the (*) option is selected')))
self.tr('Rasterized')))

def processAlgorithm(self, progress):
writeOver = self.getParameterValue(self.WRITEOVER)
inLayer = self.getParameterValue(self.INPUT)
ogrLayer = self.ogrConnectionString(inLayer)[1:-1]
noData = str(self.getParameterValue(self.NO_DATA))
Expand All @@ -123,27 +119,26 @@ def processAlgorithm(self, progress):
arguments.append('-a')
arguments.append(str(self.getParameterValue(self.FIELD)))

if not writeOver:
arguments.append('-ot')
arguments.append(self.TYPE[self.getParameterValue(self.RTYPE)])

arguments.append('-ot')
arguments.append(self.TYPE[self.getParameterValue(self.RTYPE)])
dimType = self.getParameterValue(self.DIMENSIONS)
if not writeOver:
if dimType == 0:
# size in pixels
arguments.append('-ts')
arguments.append(str(self.getParameterValue(self.WIDTH)))
arguments.append(str(self.getParameterValue(self.HEIGHT)))
else:
# resolution in map units per pixel
arguments.append('-tr')
arguments.append(str(self.getParameterValue(self.WIDTH)))
arguments.append(str(self.getParameterValue(self.HEIGHT)))

if len(noData) > 0:
arguments.append('-a_nodata')
arguments.append(noData)

if (GdalUtils.getFormatShortNameFromFilename(out) == "GTiff") and (writeOver is False):
if dimType == 0:
# size in pixels
arguments.append('-ts')
arguments.append(str(self.getParameterValue(self.WIDTH)))
arguments.append(str(self.getParameterValue(self.HEIGHT)))
else:
# resolution in map units per pixel
arguments.append('-tr')
arguments.append(str(self.getParameterValue(self.WIDTH)))
arguments.append(str(self.getParameterValue(self.HEIGHT)))

if len(noData) > 0:
arguments.append('-a_nodata')
arguments.append(noData)

if (GdalUtils.getFormatShortNameFromFilename(out) == "GTiff"):
arguments.append("-co COMPRESS="+compress)
if compress == 'JPEG':
arguments.append("-co JPEG_QUALITY="+jpegcompression)
Expand Down

0 comments on commit ed784d9

Please sign in to comment.