@@ -153,84 +153,123 @@ def processParameterLine(self, line):
153
153
if tokens [1 ].lower ().strip () == 'group' :
154
154
self .group = tokens [0 ]
155
155
return
156
- if tokens [1 ].lower ().strip ().startswith ('raster' ):
157
- param = ParameterRaster (tokens [0 ], desc , False )
158
- elif tokens [1 ].lower ().strip () == 'vector' :
159
- param = ParameterVector (tokens [0 ], desc ,
156
+
157
+ if tokens [1 ].lower ().strip ().startswith ('output' ):
158
+ outToken = tokens [1 ].strip ()[len ('output' ) + 1 :]
159
+ out = self .processOutputParameterToken (outToken )
160
+
161
+ elif tokens [1 ].lower ().strip ().startswith ('optional' ):
162
+ optToken = tokens [1 ].strip ()[len ('optional' ) + 1 :]
163
+ param = self .processInputParameterToken (optToken , tokens [0 ])
164
+ if param :
165
+ param .optional = True
166
+
167
+ else :
168
+ param = self .processInputParameterToken (tokens [1 ], tokens [0 ])
169
+
170
+ if param is not None :
171
+ self .addParameter (param )
172
+ elif out is not None :
173
+ out .name = tokens [0 ]
174
+ out .description = tokens [0 ]
175
+ self .addOutput (out )
176
+ else :
177
+ raise WrongScriptException (
178
+ self .tr ('Could not load R script: %s.\n Problem with line %s' % (self .descriptionFile , line )))
179
+
180
+ def processInputParameterToken (self , token , name ):
181
+ param = None
182
+
183
+ desc = self .createDescriptiveName (name )
184
+
185
+ if token .lower ().strip ().startswith ('raster' ):
186
+ param = ParameterRaster (name , desc , False )
187
+ elif token .lower ().strip () == 'vector' :
188
+ param = ParameterVector (name , desc ,
160
189
[ParameterVector .VECTOR_TYPE_ANY ])
161
- elif tokens [ 1 ] .lower ().strip () == 'vector point' :
162
- param = ParameterVector (tokens [ 0 ] , desc ,
190
+ elif token .lower ().strip () == 'vector point' :
191
+ param = ParameterVector (name , desc ,
163
192
[ParameterVector .VECTOR_TYPE_POINT ])
164
- elif tokens [ 1 ] .lower ().strip () == 'vector line' :
165
- param = ParameterVector (tokens [ 0 ] , desc ,
193
+ elif token .lower ().strip () == 'vector line' :
194
+ param = ParameterVector (name , desc ,
166
195
[ParameterVector .VECTOR_TYPE_LINE ])
167
- elif tokens [ 1 ] .lower ().strip () == 'vector polygon' :
168
- param = ParameterVector (tokens [ 0 ] , desc ,
196
+ elif token .lower ().strip () == 'vector polygon' :
197
+ param = ParameterVector (name , desc ,
169
198
[ParameterVector .VECTOR_TYPE_POLYGON ])
170
- elif tokens [ 1 ] .lower ().strip () == 'table' :
171
- param = ParameterTable (tokens [ 0 ] , desc , False )
172
- elif tokens [ 1 ] .lower ().strip ().startswith ('multiple raster' ):
173
- param = ParameterMultipleInput (tokens [ 0 ] , desc ,
199
+ elif token .lower ().strip () == 'table' :
200
+ param = ParameterTable (name , desc , False )
201
+ elif token .lower ().strip ().startswith ('multiple raster' ):
202
+ param = ParameterMultipleInput (name , desc ,
174
203
ParameterMultipleInput .TYPE_RASTER )
175
204
param .optional = False
176
- elif tokens [ 1 ] .lower ().strip () == 'multiple vector' :
177
- param = ParameterMultipleInput (tokens [ 0 ] , desc ,
205
+ elif token .lower ().strip () == 'multiple vector' :
206
+ param = ParameterMultipleInput (name , desc ,
178
207
ParameterMultipleInput .TYPE_VECTOR_ANY )
179
208
param .optional = False
180
- elif tokens [1 ].lower ().strip ().startswith ('selection' ):
181
- options = tokens [1 ].strip ()[len ('selection' ):].split (';' )
182
- param = ParameterSelection (tokens [0 ], desc , options )
183
- elif tokens [1 ].lower ().strip ().startswith ('boolean' ):
184
- default = tokens [1 ].strip ()[len ('boolean' ) + 1 :]
185
- param = ParameterBoolean (tokens [0 ], desc , default )
186
- elif tokens [1 ].lower ().strip ().startswith ('number' ):
187
- try :
188
- default = float (tokens [1 ].strip ()[len ('number' ) + 1 :])
189
- param = ParameterNumber (tokens [0 ], desc , default = default )
190
- except :
191
- raise WrongScriptException (
192
- self .tr ('Could not load R script: %s.\n Problem with line %s' % (self .descriptionFile , line )))
193
- elif tokens [1 ].lower ().strip ().startswith ('field' ):
194
- field = tokens [1 ].strip ()[len ('field' ) + 1 :]
209
+ elif token .lower ().strip ().startswith ('selection' ):
210
+ options = token .strip ()[len ('selection' ):].split (';' )
211
+ param = ParameterSelection (name , desc , options )
212
+ elif token .lower ().strip ().startswith ('boolean' ):
213
+ default = token .strip ()[len ('boolean' ) + 1 :]
214
+ if default :
215
+ param = ParameterBoolean (name , desc , default )
216
+ else :
217
+ param = ParameterBoolean (name , desc )
218
+ elif token .lower ().strip ().startswith ('number' ):
219
+ default = token .strip ()[len ('number' ) + 1 :]
220
+ if default :
221
+ param = ParameterNumber (name , desc , default = default )
222
+ else :
223
+ param = ParameterNumber (name , desc )
224
+ elif token .lower ().strip ().startswith ('field' ):
225
+ field = token .strip ()[len ('field' ) + 1 :]
195
226
found = False
196
227
for p in self .parameters :
197
228
if p .name == field :
198
229
found = True
199
230
break
200
231
if found :
201
- param = ParameterTableField (tokens [0 ], tokens [0 ], field )
202
- elif tokens [1 ].lower ().strip () == 'extent' :
203
- param = ParameterExtent (tokens [0 ], desc )
204
- elif tokens [1 ].lower ().strip () == 'crs' :
205
- param = ParameterCrs (tokens [0 ], desc )
206
- elif tokens [1 ].lower ().strip () == 'file' :
207
- param = ParameterFile (tokens [0 ], desc , False )
208
- elif tokens [1 ].lower ().strip () == 'folder' :
209
- param = ParameterFile (tokens [0 ], desc , True )
210
- elif tokens [1 ].lower ().strip ().startswith ('string' ):
211
- default = tokens [1 ].strip ()[len ('string' ) + 1 :]
212
- param = ParameterString (tokens [0 ], desc , default )
213
- elif tokens [1 ].lower ().strip ().startswith ('longstring' ):
214
- default = tokens [1 ].strip ()[len ('longstring' ) + 1 :]
215
- param = ParameterString (tokens [0 ], desc , default , multiline = True )
216
- elif tokens [1 ].lower ().strip ().startswith ('output raster' ):
232
+ param = ParameterTableField (name , desc , field )
233
+ elif token .lower ().strip () == 'extent' :
234
+ param = ParameterExtent (name , desc )
235
+ elif token .lower ().strip () == 'file' :
236
+ param = ParameterFile (name , desc , False )
237
+ elif token .lower ().strip () == 'folder' :
238
+ param = ParameterFile (name , desc , True )
239
+ elif token .lower ().strip ().startswith ('string' ):
240
+ default = token .strip ()[len ('string' ) + 1 :]
241
+ if default :
242
+ param = ParameterString (name , desc , default )
243
+ else :
244
+ param = ParameterString (name , desc )
245
+ elif token .lower ().strip ().startswith ('longstring' ):
246
+ default = token .strip ()[len ('longstring' ) + 1 :]
247
+ if default :
248
+ param = ParameterString (name , desc , default , multiline = True )
249
+ else :
250
+ param = ParameterString (name , desc , multiline = True )
251
+ elif token .lower ().strip () == 'crs' :
252
+ default = token .strip ()[len ('crs' ) + 1 :]
253
+ if default :
254
+ param = ParameterCrs (name , desc , default )
255
+ else :
256
+ param = ParameterCrs (name , desc )
257
+
258
+ return param
259
+
260
+ def processOutputParameterToken (self , token ):
261
+ out = None
262
+
263
+ if token .lower ().strip ().startswith ('raster' ):
217
264
out = OutputRaster ()
218
- elif tokens [ 1 ] .lower ().strip ().startswith ('output vector' ):
265
+ elif token .lower ().strip ().startswith ('vector' ):
219
266
out = OutputVector ()
220
- elif tokens [ 1 ] .lower ().strip ().startswith ('output table' ):
267
+ elif token .lower ().strip ().startswith ('table' ):
221
268
out = OutputTable ()
222
- elif tokens [ 1 ] .lower ().strip ().startswith ('output file' ):
269
+ elif token .lower ().strip ().startswith ('file' ):
223
270
out = OutputFile ()
224
271
225
- if param is not None :
226
- self .addParameter (param )
227
- elif out is not None :
228
- out .name = tokens [0 ]
229
- out .description = tokens [0 ]
230
- self .addOutput (out )
231
- else :
232
- raise WrongScriptException (
233
- self .tr ('Could not load R script: %s.\n Problem with line %s' % (self .descriptionFile , line )))
272
+ return out
234
273
235
274
def processAlgorithm (self , progress ):
236
275
if isWindows ():
0 commit comments