Skip to content

Commit 02bec58

Browse files
Giovanni Manghialexbruy
Giovanni Manghi
authored andcommitted
fix gdal rasterize when using an existing raster layer
1 parent 66580c4 commit 02bec58

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

python/plugins/processing/algs/gdal/rasterize.py

+17-15
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ def defineCharacteristics(self):
101101
self.addParameter(ParameterSelection(self.BIGTIFF,
102102
self.tr('Control whether the created file is a BigTIFF or a classic TIFF'), self.BIGTIFFTYPE, 0))
103103
self.addParameter(ParameterBoolean(self.TFW,
104-
self.tr('Force the generation of an associated ESRI world file (.tfw))'), False))
104+
self.tr('Force the generation of an associated ESRI world file (.tfw)'), False))
105105
self.addOutput(OutputRaster(self.OUTPUT,
106-
self.tr('Output layer: mandatory to choose an existing raster layer if the (*) option is selected')))
106+
self.tr('Output layer: mandatory if the (*) option is selected')))
107107

108108
def processAlgorithm(self, progress):
109109
writeOver = self.getParameterValue(self.WRITEOVER)
@@ -127,19 +127,21 @@ def processAlgorithm(self, progress):
127127
arguments.append('-ot')
128128
arguments.append(self.TYPE[self.getParameterValue(self.RTYPE)])
129129
dimType = self.getParameterValue(self.DIMENSIONS)
130-
if dimType == 0:
131-
# size in pixels
132-
arguments.append('-ts')
133-
arguments.append(str(self.getParameterValue(self.WIDTH)))
134-
arguments.append(str(self.getParameterValue(self.HEIGHT)))
135-
else:
136-
# resolution in map units per pixel
137-
arguments.append('-tr')
138-
arguments.append(str(self.getParameterValue(self.WIDTH)))
139-
arguments.append(str(self.getParameterValue(self.HEIGHT)))
140-
if len(noData) > 0:
141-
arguments.append('-a_nodata')
142-
arguments.append(noData)
130+
if not writeOver:
131+
if dimType == 0:
132+
# size in pixels
133+
arguments.append('-ts')
134+
arguments.append(str(self.getParameterValue(self.WIDTH)))
135+
arguments.append(str(self.getParameterValue(self.HEIGHT)))
136+
else:
137+
# resolution in map units per pixel
138+
arguments.append('-tr')
139+
arguments.append(str(self.getParameterValue(self.WIDTH)))
140+
arguments.append(str(self.getParameterValue(self.HEIGHT)))
141+
if not writeOver:
142+
if len(noData) > 0:
143+
arguments.append('-a_nodata')
144+
arguments.append(noData)
143145
if (GdalUtils.getFormatShortNameFromFilename(out) == "GTiff") and (writeOver is False):
144146
arguments.append("-co COMPRESS="+compress)
145147
if compress == 'JPEG':

0 commit comments

Comments
 (0)