31
31
from processing .core .parameters import ParameterTableField
32
32
from processing .core .parameters import ParameterSelection
33
33
from processing .core .parameters import ParameterNumber
34
+ from processing .core .parameters import ParameterBoolean
34
35
from processing .core .outputs import OutputRaster
35
36
from processing .algs .gdal .GdalUtils import GdalUtils
36
37
@@ -42,6 +43,7 @@ class rasterize(GdalAlgorithm):
42
43
DIMENSIONS = 'DIMENSIONS'
43
44
WIDTH = 'WIDTH'
44
45
HEIGHT = 'HEIGHT'
46
+ WRITEOVER = 'WRITEOVER'
45
47
RTYPE = 'RTYPE'
46
48
OUTPUT = 'OUTPUT'
47
49
@@ -56,8 +58,10 @@ def defineCharacteristics(self):
56
58
self .addParameter (ParameterVector (self .INPUT , 'Input layer' ))
57
59
self .addParameter (ParameterTableField (self .FIELD , 'Attribute field' ,
58
60
self .INPUT ))
61
+ self .addParameter (ParameterBoolean (self .WRITEOVER ,
62
+ 'Write values inside an existing raster layer(*)' , False ))
59
63
self .addParameter (ParameterSelection (self .DIMENSIONS ,
60
- 'Set output raster size' , ['Output size in pixels' ,
64
+ 'Set output raster size (ignored if above option is checked) ' , ['Output size in pixels' ,
61
65
'Output resolution in map units per pixel' ], 1 ))
62
66
self .addParameter (ParameterNumber (self .WIDTH , 'Horizontal' , 0.0 ,
63
67
99999999.999999 , 100.0 ))
@@ -69,22 +73,24 @@ def defineCharacteristics(self):
69
73
self .addOutput (OutputRaster (self .OUTPUT , 'Output layer' ))
70
74
71
75
def processAlgorithm (self , progress ):
76
+ writeOver = self .getParameterValue (self .WRITEOVER )
77
+
72
78
arguments = []
73
79
arguments .append ('-a' )
74
80
arguments .append (str (self .getParameterValue (self .FIELD )))
75
-
76
- arguments . append ( '-ot' )
77
- arguments .append (self . TYPE [ self . getParameterValue ( self . RTYPE )] )
78
-
79
- dimType = self .getParameterValue (self .DIMENSIONS )
80
- if dimType == 0 :
81
- # size in pixels
82
- arguments .append ('-ts' )
83
- else :
84
- # resolution in map units per pixel
85
- arguments .append ('-tr' )
86
- arguments .append (str (self .getParameterValue (self .WIDTH )))
87
- arguments .append (str (self .getParameterValue (self .HEIGHT )))
81
+
82
+ if not writeOver :
83
+ arguments .append ('-ot' )
84
+ arguments . append ( self . TYPE [ self . getParameterValue ( self . RTYPE )])
85
+ dimType = self .getParameterValue (self .DIMENSIONS )
86
+ if dimType == 0 :
87
+ # size in pixels
88
+ arguments .append ('-ts' )
89
+ else :
90
+ # resolution in map units per pixel
91
+ arguments .append ('-tr' )
92
+ arguments .append (str (self .getParameterValue (self .WIDTH )))
93
+ arguments .append (str (self .getParameterValue (self .HEIGHT )))
88
94
89
95
arguments .append ('-l' )
90
96
arguments .append (
0 commit comments