mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
fix processing gdal_rasterize to allow write vector values in a existing raster layer
This commit is contained in:
parent
4bcde11753
commit
ee8b74f5ca
@ -31,6 +31,7 @@ from processing.core.parameters import ParameterVector
|
||||
from processing.core.parameters import ParameterTableField
|
||||
from processing.core.parameters import ParameterSelection
|
||||
from processing.core.parameters import ParameterNumber
|
||||
from processing.core.parameters import ParameterBoolean
|
||||
from processing.core.outputs import OutputRaster
|
||||
from processing.algs.gdal.GdalUtils import GdalUtils
|
||||
|
||||
@ -42,6 +43,7 @@ class rasterize(GdalAlgorithm):
|
||||
DIMENSIONS = 'DIMENSIONS'
|
||||
WIDTH = 'WIDTH'
|
||||
HEIGHT = 'HEIGHT'
|
||||
WRITEOVER = 'WRITEOVER'
|
||||
RTYPE = 'RTYPE'
|
||||
OUTPUT = 'OUTPUT'
|
||||
|
||||
@ -56,8 +58,10 @@ class rasterize(GdalAlgorithm):
|
||||
self.addParameter(ParameterVector(self.INPUT, 'Input layer'))
|
||||
self.addParameter(ParameterTableField(self.FIELD, 'Attribute field',
|
||||
self.INPUT))
|
||||
self.addParameter(ParameterBoolean(self.WRITEOVER,
|
||||
'Write values inside an existing raster layer(*)', False))
|
||||
self.addParameter(ParameterSelection(self.DIMENSIONS,
|
||||
'Set output raster size', ['Output size in pixels',
|
||||
'Set output raster size (ignored if above option is checked)', ['Output size in pixels',
|
||||
'Output resolution in map units per pixel'], 1))
|
||||
self.addParameter(ParameterNumber(self.WIDTH, 'Horizontal', 0.0,
|
||||
99999999.999999, 100.0))
|
||||
@ -69,22 +73,24 @@ class rasterize(GdalAlgorithm):
|
||||
self.addOutput(OutputRaster(self.OUTPUT, 'Output layer'))
|
||||
|
||||
def processAlgorithm(self, progress):
|
||||
writeOver = self.getParameterValue(self.WRITEOVER)
|
||||
|
||||
arguments = []
|
||||
arguments.append('-a')
|
||||
arguments.append(str(self.getParameterValue(self.FIELD)))
|
||||
|
||||
arguments.append('-ot')
|
||||
arguments.append(self.TYPE[self.getParameterValue(self.RTYPE)])
|
||||
|
||||
dimType = self.getParameterValue(self.DIMENSIONS)
|
||||
if dimType == 0:
|
||||
# size in pixels
|
||||
arguments.append('-ts')
|
||||
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 not writeOver:
|
||||
arguments.append('-ot')
|
||||
arguments.append(self.TYPE[self.getParameterValue(self.RTYPE)])
|
||||
dimType = self.getParameterValue(self.DIMENSIONS)
|
||||
if dimType == 0:
|
||||
# size in pixels
|
||||
arguments.append('-ts')
|
||||
else:
|
||||
# resolution in map units per pixel
|
||||
arguments.append('-tr')
|
||||
arguments.append(str(self.getParameterValue(self.WIDTH)))
|
||||
arguments.append(str(self.getParameterValue(self.HEIGHT)))
|
||||
|
||||
arguments.append('-l')
|
||||
arguments.append(
|
||||
|
Loading…
x
Reference in New Issue
Block a user