Skip to content

Commit

Permalink
Merge pull request #3568 from volaya/processing_fixes
Browse files Browse the repository at this point in the history
[processing] various fixes
  • Loading branch information
alexbruy authored Oct 4, 2016
2 parents a6bb8a9 + bd1cf0c commit b5f1267
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 30 deletions.
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/grass7/ext/i_aster_toar.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
__revision__ = '$Format:%H$'

from i import multipleOutputDir
from processoing.core.parameters import getParameterFromString
from processing.core.parameters import getParameterFromString


def processCommand(alg):
Expand Down
48 changes: 48 additions & 0 deletions python/plugins/processing/algs/help/saga.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
saga:rastercalculator: >
This algorithm allows to perform algebraic operations on raster layers

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.

The resulting layer has the extent and cellsize of the main layer.

The following operators and functions are available.

- Addition (+)

- Subtraction ( - )

- Multiplication (*)

- Division (/)

- Power (^)

- ln(x): returns natural logarithm of x.

- sin(x): returns the sine of x. x must be in radians

- cos(x): returns the cosine of x. x must be in radians

- cos(x): returns the tangente of x. x must be in radians

- asin(x): returns the arcsine of x, in radians

- acos(x): returns the arccosine of x, in radians

- atan(x): returns the arctangent of x, in radians

- atan2(x,y): returns the arctangent y/x, in radians

- abs(x): return the absolute value of x. abs(- 5)=5

- int(x): returns the integer part of x. int(5.4)=5

- mod(x,y): returns the modulus of x/y. mod(7,4)=3

- gt(x,y): true if x is greater than y

- lt(x,y): true if x is lower than y

- 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.

- ifelse(condition, x, y) returns x if condition evaluates to true (condition=1) or y if it evaluates to false
17 changes: 8 additions & 9 deletions python/plugins/processing/algs/qgis/ui/FieldsCalculatorDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,21 @@ def manageGui(self):

self.builder.loadRecent('fieldcalc')

self.updateLayer()
self.initContext()

def updateLayer(self):
self.layer = dataobjects.getObject(self.cmbInputLayer.currentText())

self.builder.setLayer(self.layer)
self.builder.loadFieldNames()

exp_context = QgsExpressionContext()
def initContext(self):
exp_context = self.builder.expressionContext()
exp_context.appendScope(QgsExpressionContextUtils.globalScope())
exp_context.appendScope(QgsExpressionContextUtils.projectScope())
exp_context.appendScope(QgsExpressionContextUtils.layerScope(self.layer))
exp_context.lastScope().setVariable("row_number", 1)
exp_context.setHighlightedVariables(["row_number"])
self.builder.setExpressionContext(exp_context)


def updateLayer(self):
self.layer = dataobjects.getObject(self.cmbInputLayer.currentText())
self.builder.setLayer(self.layer)
self.builder.loadFieldNames()
self.populateFields()

def setupSpinboxes(self, index):
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/r/RAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def processInputParameterToken(self, token, name):
found = True
break
if found:
param = ParameterTableMultipleField(token, desc, field)
param = ParameterTableMultipleField(name, desc, field)
elif token.lower().strip() == 'extent':
param = ParameterExtent(name, desc)
elif token.lower().strip() == 'point':
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/saga/SagaNameDecorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
'pj_geotrans': 'Projections and Transformations',
'pj_proj4': 'Projections and Transformations',
'pointcloud_tools': 'Point clouds',
'shapes_grid': 'Vector to raster',
'shapes_grid': 'Vector <-> raster',
'shapes_lines': 'Vector line tools',
'shapes_points': 'Vector point tools',
'shapes_polygons': 'Vector polygon tools',
Expand Down
3 changes: 2 additions & 1 deletion python/plugins/processing/core/GeoAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ def __str__(self):
for param in self.parameters:
s += '\t' + unicode(param) + '\n'
for out in self.outputs:
s += '\t' + unicode(out) + '\n'
if not out.hidden:
s += '\t' + unicode(out) + '\n'
s += '\n'
return s

Expand Down
5 changes: 3 additions & 2 deletions python/plugins/processing/gui/AlgorithmExecutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def runalg(alg, progress=None):
return True
except GeoAlgorithmExecutionException as e:
ProcessingLog.addToLog(sys.exc_info()[0], ProcessingLog.LOG_ERROR)
progress.error(e.msg)
if progress is not None:
progress.error(e.msg)
return False


Expand Down Expand Up @@ -87,7 +88,7 @@ def runalgIterating(alg, paramToIter, progress):
out.value = filename
progress.setText(tr('Executing iteration %s/%s...' % (unicode(i), unicode(len(filelist)))))
progress.setPercentage(i * 100 / len(filelist))
if runalg(alg):
if runalg(alg, progress):
handleAlgorithmResults(alg, None, False)
else:
return False
Expand Down
15 changes: 8 additions & 7 deletions python/plugins/processing/gui/BatchPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ def getWidgetFromParameter(self, param, row, col):
else:
item = QLineEdit()
try:
item.setText(unicode(param.default))
if param.default:
item.setText(unicode(param.default))
except:
pass

Expand Down Expand Up @@ -346,12 +347,12 @@ def addRow(self):
self.tblParameters.setCellWidget(row, column, item)

def removeRows(self):
#~ self.tblParameters.setUpdatesEnabled(False)
#~ indexes = self.tblParameters.selectionModel().selectedIndexes()
#~ indexes.sort()
#~ for i in reversed(indexes):
#~ self.tblParameters.model().removeRow(i.row())
#~ self.tblParameters.setUpdatesEnabled(True)
# ~ self.tblParameters.setUpdatesEnabled(False)
# ~ indexes = self.tblParameters.selectionModel().selectedIndexes()
# ~ indexes.sort()
# ~ for i in reversed(indexes):
# ~ self.tblParameters.model().removeRow(i.row())
# ~ self.tblParameters.setUpdatesEnabled(True)
if self.tblParameters.rowCount() > 2:
self.tblParameters.setRowCount(self.tblParameters.rowCount() - 1)

Expand Down
15 changes: 10 additions & 5 deletions python/plugins/processing/modeler/ModelerAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,11 @@ def _toString(v):
return unicode(value)
params.append(_toString(value))
for out in self.algorithm.outputs:
if out.name in self.outputs:
params.append(safeName(self.outputs[out.name].description).lower())
else:
params.append(str(None))
if not out.hidden:
if out.name in self.outputs:
params.append(safeName(self.outputs[out.name].description).lower())
else:
params.append(str(None))
s.append("outputs_%s=processing.runalg('%s', %s)" % (self.name, self.consoleName, ",".join(params)))
return s

Expand Down Expand Up @@ -209,7 +210,11 @@ class ModelerAlgorithm(GeoAlgorithm):
def getCopy(self):
newone = ModelerAlgorithm()
newone.provider = self.provider
newone.algs = copy.deepcopy(self.algs)

newone.algs = {}
for algname, alg in self.algs.iteritems():
newone.algs[algname] = Algorithm()
newone.algs[algname].__dict__.update(copy.deepcopy(alg.todict()))
newone.inputs = copy.deepcopy(self.inputs)
newone.defineCharacteristics()
newone.name = self.name
Expand Down
5 changes: 3 additions & 2 deletions python/plugins/processing/tools/dataobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,15 @@ def getObjectFromUri(uri, forceLoad=True):
settings.setValue('/Projections/defaultBehaviour', '')

# If is not opened, we open it
name = os.path.basename(uri)
for provider in ['ogr', 'postgres', 'spatialite', 'virtual']:
layer = QgsVectorLayer(uri, uri, provider)
layer = QgsVectorLayer(uri, name, provider)
if layer.isValid():
if prjSetting:
settings.setValue('/Projections/defaultBehaviour', prjSetting)
_loadedLayers[normalizeLayerSource(layer.source())] = layer
return layer
layer = QgsRasterLayer(uri, uri)
layer = QgsRasterLayer(uri, name)
if layer.isValid():
if prjSetting:
settings.setValue('/Projections/defaultBehaviour', prjSetting)
Expand Down
8 changes: 7 additions & 1 deletion python/plugins/processing/tools/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,13 @@ def testForUniqueness(fieldList1, fieldList2):
def spatialindex(layer):
"""Creates a spatial index for the passed vector layer.
"""
idx = QgsSpatialIndex(layer.getFeatures())
request = QgsFeatureRequest()
request.setSubsetOfAttributes([])
if ProcessingConfig.getSetting(ProcessingConfig.USE_SELECTED) \
and layer.selectedFeatureCount() > 0:
idx = layer.selectedFeaturesIterator(request)
else:
idx = QgsSpatialIndex(layer.getFeatures(request))
return idx


Expand Down

0 comments on commit b5f1267

Please sign in to comment.