Skip to content

Commit b5f1267

Browse files
authoredOct 4, 2016
Merge pull request #3568 from volaya/processing_fixes
[processing] various fixes
2 parents a6bb8a9 + bd1cf0c commit b5f1267

File tree

11 files changed

+92
-30
lines changed

11 files changed

+92
-30
lines changed
 

‎python/plugins/processing/algs/grass7/ext/i_aster_toar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
__revision__ = '$Format:%H$'
2727

2828
from i import multipleOutputDir
29-
from processoing.core.parameters import getParameterFromString
29+
from processing.core.parameters import getParameterFromString
3030

3131

3232
def processCommand(alg):
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
saga:rastercalculator: >
2+
This algorithm allows to perform algebraic operations on raster layers
3+
4+
It requires a base layer, and a set of additional layers. The base layer is identified as "a" in the formula, while the additional layers are identified as "b, c, d...", using the order in which they appear in the multiple selection dialog.
5+
6+
The resulting layer has the extent and cellsize of the main layer.
7+
8+
The following operators and functions are available.
9+
10+
- Addition (+)
11+
12+
- Subtraction ( - )
13+
14+
- Multiplication (*)
15+
16+
- Division (/)
17+
18+
- Power (^)
19+
20+
- ln(x): returns natural logarithm of x.
21+
22+
- sin(x): returns the sine of x. x must be in radians
23+
24+
- cos(x): returns the cosine of x. x must be in radians
25+
26+
- cos(x): returns the tangente of x. x must be in radians
27+
28+
- asin(x): returns the arcsine of x, in radians
29+
30+
- acos(x): returns the arccosine of x, in radians
31+
32+
- atan(x): returns the arctangent of x, in radians
33+
34+
- atan2(x,y): returns the arctangent y/x, in radians
35+
36+
- abs(x): return the absolute value of x. abs(- 5)=5
37+
38+
- int(x): returns the integer part of x. int(5.4)=5
39+
40+
- mod(x,y): returns the modulus of x/y. mod(7,4)=3
41+
42+
- gt(x,y): true if x is greater than y
43+
44+
- lt(x,y): true if x is lower than y
45+
46+
- eq(x,y): true if x equals y. When using this function SAGA evaluates it in a per–cell basis. Therefore, eq(a,b) will not return 1 if grid a equals grid b. It will return 1 for those cells that have the same value in both grids, and zero otherwise.
47+
48+
- ifelse(condition, x, y) returns x if condition evaluates to true (condition=1) or y if it evaluates to false

‎python/plugins/processing/algs/qgis/ui/FieldsCalculatorDialog.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,21 @@ def manageGui(self):
8989

9090
self.builder.loadRecent('fieldcalc')
9191

92-
self.updateLayer()
92+
self.initContext()
9393

94-
def updateLayer(self):
95-
self.layer = dataobjects.getObject(self.cmbInputLayer.currentText())
96-
97-
self.builder.setLayer(self.layer)
98-
self.builder.loadFieldNames()
99-
100-
exp_context = QgsExpressionContext()
94+
def initContext(self):
95+
exp_context = self.builder.expressionContext()
10196
exp_context.appendScope(QgsExpressionContextUtils.globalScope())
10297
exp_context.appendScope(QgsExpressionContextUtils.projectScope())
10398
exp_context.appendScope(QgsExpressionContextUtils.layerScope(self.layer))
10499
exp_context.lastScope().setVariable("row_number", 1)
105100
exp_context.setHighlightedVariables(["row_number"])
106101
self.builder.setExpressionContext(exp_context)
107-
102+
103+
def updateLayer(self):
104+
self.layer = dataobjects.getObject(self.cmbInputLayer.currentText())
105+
self.builder.setLayer(self.layer)
106+
self.builder.loadFieldNames()
108107
self.populateFields()
109108

110109
def setupSpinboxes(self, index):

‎python/plugins/processing/algs/r/RAlgorithm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def processInputParameterToken(self, token, name):
243243
found = True
244244
break
245245
if found:
246-
param = ParameterTableMultipleField(token, desc, field)
246+
param = ParameterTableMultipleField(name, desc, field)
247247
elif token.lower().strip() == 'extent':
248248
param = ParameterExtent(name, desc)
249249
elif token.lower().strip() == 'point':

‎python/plugins/processing/algs/saga/SagaNameDecorator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
'pj_geotrans': 'Projections and Transformations',
5454
'pj_proj4': 'Projections and Transformations',
5555
'pointcloud_tools': 'Point clouds',
56-
'shapes_grid': 'Vector to raster',
56+
'shapes_grid': 'Vector <-> raster',
5757
'shapes_lines': 'Vector line tools',
5858
'shapes_points': 'Vector point tools',
5959
'shapes_polygons': 'Vector polygon tools',

‎python/plugins/processing/core/GeoAlgorithm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,8 @@ def __str__(self):
486486
for param in self.parameters:
487487
s += '\t' + unicode(param) + '\n'
488488
for out in self.outputs:
489-
s += '\t' + unicode(out) + '\n'
489+
if not out.hidden:
490+
s += '\t' + unicode(out) + '\n'
490491
s += '\n'
491492
return s
492493

‎python/plugins/processing/gui/AlgorithmExecutor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def runalg(alg, progress=None):
4949
return True
5050
except GeoAlgorithmExecutionException as e:
5151
ProcessingLog.addToLog(sys.exc_info()[0], ProcessingLog.LOG_ERROR)
52-
progress.error(e.msg)
52+
if progress is not None:
53+
progress.error(e.msg)
5354
return False
5455

5556

@@ -87,7 +88,7 @@ def runalgIterating(alg, paramToIter, progress):
8788
out.value = filename
8889
progress.setText(tr('Executing iteration %s/%s...' % (unicode(i), unicode(len(filelist)))))
8990
progress.setPercentage(i * 100 / len(filelist))
90-
if runalg(alg):
91+
if runalg(alg, progress):
9192
handleAlgorithmResults(alg, None, False)
9293
else:
9394
return False

‎python/plugins/processing/gui/BatchPanel.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ def getWidgetFromParameter(self, param, row, col):
171171
else:
172172
item = QLineEdit()
173173
try:
174-
item.setText(unicode(param.default))
174+
if param.default:
175+
item.setText(unicode(param.default))
175176
except:
176177
pass
177178

@@ -346,12 +347,12 @@ def addRow(self):
346347
self.tblParameters.setCellWidget(row, column, item)
347348

348349
def removeRows(self):
349-
#~ self.tblParameters.setUpdatesEnabled(False)
350-
#~ indexes = self.tblParameters.selectionModel().selectedIndexes()
351-
#~ indexes.sort()
352-
#~ for i in reversed(indexes):
353-
#~ self.tblParameters.model().removeRow(i.row())
354-
#~ self.tblParameters.setUpdatesEnabled(True)
350+
# ~ self.tblParameters.setUpdatesEnabled(False)
351+
# ~ indexes = self.tblParameters.selectionModel().selectedIndexes()
352+
# ~ indexes.sort()
353+
# ~ for i in reversed(indexes):
354+
# ~ self.tblParameters.model().removeRow(i.row())
355+
# ~ self.tblParameters.setUpdatesEnabled(True)
355356
if self.tblParameters.rowCount() > 2:
356357
self.tblParameters.setRowCount(self.tblParameters.rowCount() - 1)
357358

‎python/plugins/processing/modeler/ModelerAlgorithm.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,11 @@ def _toString(v):
151151
return unicode(value)
152152
params.append(_toString(value))
153153
for out in self.algorithm.outputs:
154-
if out.name in self.outputs:
155-
params.append(safeName(self.outputs[out.name].description).lower())
156-
else:
157-
params.append(str(None))
154+
if not out.hidden:
155+
if out.name in self.outputs:
156+
params.append(safeName(self.outputs[out.name].description).lower())
157+
else:
158+
params.append(str(None))
158159
s.append("outputs_%s=processing.runalg('%s', %s)" % (self.name, self.consoleName, ",".join(params)))
159160
return s
160161

@@ -209,7 +210,11 @@ class ModelerAlgorithm(GeoAlgorithm):
209210
def getCopy(self):
210211
newone = ModelerAlgorithm()
211212
newone.provider = self.provider
212-
newone.algs = copy.deepcopy(self.algs)
213+
214+
newone.algs = {}
215+
for algname, alg in self.algs.iteritems():
216+
newone.algs[algname] = Algorithm()
217+
newone.algs[algname].__dict__.update(copy.deepcopy(alg.todict()))
213218
newone.inputs = copy.deepcopy(self.inputs)
214219
newone.defineCharacteristics()
215220
newone.name = self.name

‎python/plugins/processing/tools/dataobjects.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,15 @@ def getObjectFromUri(uri, forceLoad=True):
253253
settings.setValue('/Projections/defaultBehaviour', '')
254254

255255
# If is not opened, we open it
256+
name = os.path.basename(uri)
256257
for provider in ['ogr', 'postgres', 'spatialite', 'virtual']:
257-
layer = QgsVectorLayer(uri, uri, provider)
258+
layer = QgsVectorLayer(uri, name, provider)
258259
if layer.isValid():
259260
if prjSetting:
260261
settings.setValue('/Projections/defaultBehaviour', prjSetting)
261262
_loadedLayers[normalizeLayerSource(layer.source())] = layer
262263
return layer
263-
layer = QgsRasterLayer(uri, uri)
264+
layer = QgsRasterLayer(uri, name)
264265
if layer.isValid():
265266
if prjSetting:
266267
settings.setValue('/Projections/defaultBehaviour', prjSetting)

‎python/plugins/processing/tools/vector.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,13 @@ def testForUniqueness(fieldList1, fieldList2):
200200
def spatialindex(layer):
201201
"""Creates a spatial index for the passed vector layer.
202202
"""
203-
idx = QgsSpatialIndex(layer.getFeatures())
203+
request = QgsFeatureRequest()
204+
request.setSubsetOfAttributes([])
205+
if ProcessingConfig.getSetting(ProcessingConfig.USE_SELECTED) \
206+
and layer.selectedFeatureCount() > 0:
207+
idx = layer.selectedFeaturesIterator(request)
208+
else:
209+
idx = QgsSpatialIndex(layer.getFeatures(request))
204210
return idx
205211

206212

0 commit comments

Comments
 (0)
Please sign in to comment.