Skip to content

Commit 14709f5

Browse files
author
Médéric RIBREUX
committedDec 28, 2017
Fix nearly all v. ext scripts
1 parent 90bf630 commit 14709f5

35 files changed

+282
-358
lines changed
 

‎python/plugins/processing/algs/grass7/Grass7Algorithm.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -523,14 +523,19 @@ def processCommand(self, parameters, context, delOutputs=False):
523523
elif isinstance(param, QgsProcessingParameterBoolean):
524524
if self.parameterAsBool(parameters, paramName, context):
525525
command += ' {}'.format(paramName)
526+
# For Extents, remove if the value is null
527+
elif isinstance(param, QgsProcessingParameterExtent):
528+
if self.parameterAsExtent(parameters, paramName, context):
529+
value = self.parameterAsString(parameters, paramName, context)
526530
# For enumeration, we need to grab the string value
527531
elif isinstance(param, QgsProcessingParameterEnum):
528532
# Handle multiple values
529533
if param.allowMultiple():
530534
indexes = self.parameterAsEnums(parameters, paramName, context)
531535
else:
532536
indexes = [self.parameterAsEnum(parameters, paramName, context)]
533-
value = '"{}"'.format(','.join([param.options()[i] for i in indexes]))
537+
if indexes:
538+
value = '"{}"'.format(','.join([param.options()[i] for i in indexes]))
534539
# For strings, we just translate as string
535540
elif isinstance(param, QgsProcessingParameterString):
536541
data = self.parameterAsString(parameters, paramName, context)
@@ -545,7 +550,10 @@ def processCommand(self, parameters, context, delOutputs=False):
545550
self.parameterAsFields(parameters, paramName, context)
546551
)
547552
elif isinstance(param, QgsProcessingParameterFile):
548-
value = self.parameterAsString(parameters, paramName, context)
553+
if self.parameterAsString(parameters, paramName, context):
554+
value = '"{}"'.format(
555+
self.parameterAsString(parameters, paramName, context)
556+
)
549557
# For numbers and points, we translate as a string
550558
elif isinstance(param, (QgsProcessingParameterNumber,
551559
QgsProcessingParameterPoint)):
@@ -795,13 +803,16 @@ def exportVectorLayer(self, grassName, fileName, dataType='auto', layer=None, no
795803
"""
796804
Creates a dedicated command to export a vector from
797805
temporary GRASS DB into a file via ogr.
798-
:param grassName: name of the parameter
799-
:param fileName: file path of raster layer
806+
:param grassName: name of the parameter.
807+
:param fileName: file path of raster layer.
808+
:param dataType: GRASS data type for exporting data.
809+
:param layer: In GRASS a vector can have multiple layers.
810+
:param nocats: Also export features without category if True.
800811
"""
801812
for cmd in [self.commands, self.outputCommands]:
802813
cmd.append(
803814
'v.out.ogr{0} type={1} {2} input="{3}" output="{4}" {5}'.format(
804-
'' if nocats else ' -c',
815+
' -c' if nocats else '',
805816
dataType,
806817
'layer={}'.format(layer) if layer else '',
807818
grassName,

‎python/plugins/processing/algs/grass7/description/v.edit.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ v.edit
22
Edits a vector map, allows adding, deleting and modifying selected vector features.
33
Vector (v.*)
44
QgsProcessingParameterVectorLayer|map|Name of vector layer|-1|None|False
5-
QgsProcessingParameterEnum|type|Input feature type|point;line;boundary;centroid|True|0,1,3,4|True
5+
QgsProcessingParameterEnum|type|Input feature type|point;line;boundary;centroid|True|0,1,2,3|True
66
QgsProcessingParameterEnum|tool|Tool|create;add;delete;copy;move;flip;catadd;catdel;merge;break;snap;connect;chtype;vertexadd;vertexdel;vertexmove;areadel;zbulk;select|False|0|False
77
QgsProcessingParameterFile|input|ASCII file for add tool|False|txt|None|True
88
QgsProcessingParameterString|move|Difference in x,y,z direction for moving feature or vertex|None|False|True
99
QgsProcessingParameterString|threshold|Threshold distance (coords,snap,query)|None|False|True
1010
QgsProcessingParameterString|ids|Feature ids|None|False|True
1111
QgsProcessingParameterString|cats|Category values|None|False|True
1212
QgsProcessingParameterString|coords|List of point coordinates|None|False|True
13-
QgsProcessingParameterString|bbox|Bounding box for selecting features|None|False|True
13+
QgsProcessingParameterExtent|bbox|Bounding box for selecting features|None|True
1414
QgsProcessingParameterString|polygon|Polygon for selecting features|None|False|True
1515
QgsProcessingParameterString|where|WHERE conditions of SQL statement without 'where' keyword|None|True|True
16-
QgsProcessingParameterEnum|query|Query tool|length;dangle|False|0|True
16+
QgsProcessingParameterEnum|query|Query tool|length;dangle|False|None|True
1717
QgsProcessingParameterVectorLayer|bgmap|Name of background vector map|-1|None|True
1818
QgsProcessingParameterEnum|snap|Snap added or modified features in the given threshold to the nearest existing feature|no;node;vertex|False|0|True
1919
QgsProcessingParameterString|zbulk|Starting value and step for z bulk-labeling. Pair: value,step (e.g. 1100,10)|None|False|True

‎python/plugins/processing/algs/grass7/description/v.net.allpairs.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Vector (v.*)
44
QgsProcessingParameterVectorLayer|input|Input vector line layer (arcs)|1|None|False
55
QgsProcessingParameterVectorLayer|points|Centers point layer (nodes)|0|None|False
66
QgsProcessingParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|QgsProcessingParameterNumber.Double|50.0|False|0.0|None
7-
*QgsProcessingParameterString|cats|Category values|1-10000|False|False
8-
*QgsProcessingParameterString|where|WHERE condition of SQL statement without 'where' keyword'|None|True|False
7+
*QgsProcessingParameterString|cats|Category values|1-10000|False|True
8+
*QgsProcessingParameterString|where|WHERE condition of SQL statement without 'where' keyword'|None|True|True
99
*QgsProcessingParameterField|arc_column|Arc forward/both direction(s) cost column (number)|None|input|0|False|True
1010
*QgsProcessingParameterField|arc_backward_column|Arc backward direction cost column (number)|None|input|0|False|True
1111
*QgsProcessingParameterField|node_column|Node cost column (number)|None|points|0|False|True

‎python/plugins/processing/algs/grass7/description/v.net.arcs.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.

‎python/plugins/processing/algs/grass7/description/v.net.bridge.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Vector (v.*)
44
QgsProcessingParameterVectorLayer|input|Input vector line layer (network)|1|None|False
55
QgsProcessingParameterVectorLayer|points|Centers point layer (nodes)|0|None|True
66
QgsProcessingParameterEnum|method|Feature type|bridge;articulation|False|0|False
7+
QgsProcessingParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|QgsProcessingParameterNumber.Double|50.0|True|0.0|None
78
*QgsProcessingParameterField|arc_column|Arc forward/both direction(s) cost column (name)|None|input|0|False|True
89
*QgsProcessingParameterField|arc_backward_column|Arc backward direction cost column (name)|None|input|0|False|True
910
*QgsProcessingParameterField|node_column|Node cost column (number)|None|points|0|False|True

‎python/plugins/processing/algs/grass7/description/v.net.centrality.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Computes degree, centrality, betweeness, closeness and eigenvector centrality me
33
Vector (v.*)
44
QgsProcessingParameterVectorLayer|input|Input vector line layer (network)|1|None|False
55
QgsProcessingParameterVectorLayer|points|Centers point layer (nodes)|0|None|False
6+
QgsProcessingParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|QgsProcessingParameterNumber.Double|50.0|False|0.0|None
67
QgsProcessingParameterString|degree|Name of output degree centrality column|degree|False|True
78
QgsProcessingParameterString|closeness|Name of output closeness centrality column|closeness|False|True
89
QgsProcessingParameterString|betweenness|Name of output betweenness centrality column|None|False|True

‎python/plugins/processing/algs/grass7/description/v.net.components.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Computes strongly and weakly connected components in the network.
33
Vector (v.*)
44
QgsProcessingParameterVectorLayer|input|Input vector line layer (network)|1|None|False
55
QgsProcessingParameterVectorLayer|points|Centers point layer (nodes)|0|None|True
6+
QgsProcessingParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|QgsProcessingParameterNumber.Double|50.0|True|0.0|None
67
QgsProcessingParameterEnum|method|Type of components|weak;strong|False|0|False
78
*QgsProcessingParameterField|arc_column|Arc forward/both direction(s) cost column (number)|None|input|0|False|True
89
*QgsProcessingParameterField|arc_backward_column|Arc backward direction cost column (number)|None|input|0|False|True

‎python/plugins/processing/algs/grass7/description/v.net.connect.txt

Lines changed: 0 additions & 9 deletions
This file was deleted.

‎python/plugins/processing/algs/grass7/description/v.net.distance.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ v.net.distance
22
Computes shortest distance via the network between the given sets of features.
33
Vector (v.*)
44
QgsProcessingParameterVectorLayer|input|Input vector line layer (network)|1|None|False
5-
QgsProcessingParameterVectorLayer|points|Centers point layer (nodes)|0|None|True
6-
QgsProcessingParameterVectorLayer|from_layer|Input vector from points layer (from)|0|None|True
7-
QgsProcessingParameterVectorLayer|to_layer|Input vector to points layer (to)|0|None|True
5+
QgsProcessingParameterVectorLayer|flayer|Input vector from points layer (from)|0|None|False
6+
QgsProcessingParameterVectorLayer|tlayer|Input vector to layer (to)|-1|None|False
87
QgsProcessingParameterNumber|threshold|Threshold for connecting nodes to the network (in map unit)|QgsProcessingParameterNumber.Double|50.0|False|0.0|None
98
*QgsProcessingParameterEnum|arc_type|Arc type|line;boundary|True|0,1|True
109
*QgsProcessingParameterString|from_cats|From Category values|None|False|True
@@ -14,7 +13,7 @@ QgsProcessingParameterNumber|threshold|Threshold for connecting nodes to the net
1413
*QgsProcessingParameterString|to_where|To WHERE conditions of SQL statement without 'where' keyword|None|True|True
1514
*QgsProcessingParameterField|arc_column|Arc forward/both direction(s) cost column (number)|None|input|0|False|True
1615
*QgsProcessingParameterField|arc_backward_column|Arc backward direction cost column (number)|None|input|0|False|True
17-
*QgsProcessingParameterField|node_column|Node cost column (number)|None|points|0|False|True
16+
*QgsProcessingParameterField|node_column|Node cost column (number)|None|from_layer|0|False|True
1817
*QgsProcessingParameterBoolean|-g|Use geodesic calculation for longitude-latitude locations|False|True
1918
*QgsProcessingParameterBoolean|-l|Write each output path as one line, not as original input segments|False|True
2019
QgsProcessingParameterVectorDestination|output|Network_Distance

‎python/plugins/processing/algs/grass7/description/v.net.nodes.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.

‎python/plugins/processing/algs/grass7/description/v.net.path.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ QgsProcessingParameterVectorLayer|turn_layer|Layer with turntable (with -t optio
77
QgsProcessingParameterVectorLayer|turn_cat_layer|Layer with unique categories used in turntable (with -t option)|0|None|True
88
QgsProcessingParameterFile|file|Name of file containing start and end points|False|txt|None|False
99
QgsProcessingParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|QgsProcessingParameterNumber.Double|50.0|False|0.0|None
10-
*QgsProcessingParameterEnum|type|Arc type|line;boundary|True|0,1|False
10+
*QgsProcessingParameterEnum|arc_type|Arc type|line;boundary|True|0,1|False
1111
*QgsProcessingParameterField|arc_column|Arc forward/both direction(s) cost column (number)|None|input|0|False|True
1212
*QgsProcessingParameterField|arc_backward_column|Arc backward direction cost column (number)|None|input|0|False|True
1313
*QgsProcessingParameterField|node_column|Node cost column (number)|None|points|0|False|True

‎python/plugins/processing/algs/grass7/description/v.net.spanningtree.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ v.net.spanningtree
22
Computes minimum spanning tree for the network.
33
Vector (v.*)
44
QgsProcessingParameterVectorLayer|input|Input vector line layer (arcs)|1|None|False
5-
QgsProcessingParameterVectorLayer|points|Input point layer (nodes)|0|None|False
6-
QgsProcessingParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|QgsProcessingParameterNumber.Double|50.0|False|0.0|None
5+
QgsProcessingParameterVectorLayer|points|Input point layer (nodes)|0|None|True
6+
QgsProcessingParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|QgsProcessingParameterNumber.Double|50.0|True|0.0|None
77
*QgsProcessingParameterField|arc_column|Arc forward/both direction(s) cost column (number)|None|input|0|False|True
88
*QgsProcessingParameterField|node_column|Node cost column (number)|None|points|0|False|True
99
*QgsProcessingParameterBoolean|-g|Use geodesic calculation for longitude-latitude locations|False|True
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
v.net
2+
Performs network maintenance
3+
Vector (v.*)
4+
QgsProcessingParameterVectorLayer|input|Input vector line layer (arcs)|1|None|True
5+
QgsProcessingParameterVectorLayer|points|Input vector point layer (nodes)|0|None|True
6+
QgsProcessingParameterVectorLayer|turn_layer|Layer with turntable|0|None|True
7+
QgsProcessingParameterVectorLayer|turn_cat_layer|Layer with unique categories used in turntable|0|None|True
8+
QgsProcessingParameterFile|file|Name of input arcs file|False|txt|None|True
9+
QgsProcessingParameterEnum|operation|Operation to be performed|nodes;connect;arcs;turntable|False|0|False
10+
QgsProcessingParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|QgsProcessingParameterNumber.Double|50.0|False|0.0|None
11+
QgsProcessingParameterEnum|arc_type|Arc type|line;boundary|True|0,1|True
12+
*QgsProcessingParameterBoolean|-s|Snap points to network|False
13+
*QgsProcessingParameterBoolean|-c|Assign unique categories to new points|False
14+
QgsProcessingParameterVectorDestination|output|Network|QgsProcessing.TypeVectorAnyGeometry|None|False

‎python/plugins/processing/algs/grass7/description/v.net.visibility.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ Vector (v.*)
44
QgsProcessingParameterVectorLayer|input|Input vector line layer (arcs)|-1|None|False
55
QgsProcessingParameterPoint|coordinates|Coordinates|None|True
66
QgsProcessingParameterString|coordinates|Coordinates|None|False|True
7-
QgsProcessingParameterVectorLayer|visibility|Input vector line layer containing visible points|1|None|True
7+
QgsProcessingParameterVectorLayer|visibility|Input vector line layer containing visible points|0|None|True
88
QgsProcessingParameterVectorDestination|output|Network Visibility

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

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,46 +29,34 @@
2929
import os
3030

3131

32-
def checkParameterValuesBeforeExecuting(alg):
32+
def checkParameterValuesBeforeExecuting(alg, parameters, context):
3333
""" Verify if we have the right parameters """
34-
if alg.getParameterValue('input_txt') and alg.getParameterValue(u'input'):
34+
if (alg.parameterAsString(parameters, 'input_txt', context)
35+
and alg.parameterAsString(parameters, 'input', context)):
3536
return alg.tr("You need to set either an input ASCII file or inline data!")
3637

3738
return None
3839

3940

40-
def processCommand(alg, parameters):
41-
# handle inline add data
42-
input_txt = alg.getParameterFromName('input_txt')
43-
inputParameter = alg.getParameterFromName('input')
44-
if input_txt.value:
41+
def processCommand(alg, parameters, context):
42+
# Handle inline rules
43+
txtRules = alg.parameterAsString(parameters, 'input_txt', context)
44+
if txtRules:
4545
# Creates a temporary txt file
46-
ruleFile = alg.getTempFilename()
47-
46+
tempRulesName = getTempFilename()
47+
4848
# Inject rules into temporary txt file
49-
with open(ruleFile, "w") as tempRules:
50-
tempRules.write(input_txt.value)
51-
inputParameter.value = ruleFile
52-
alg.parameters.remove(input_txt)
53-
54-
# exclude output for from_output
55-
output = alg.getOutputFromName('output')
56-
alg.removeOutputFromName('output')
57-
58-
alg.processCommand()
59-
alg.addOutput(output)
60-
if input_txt.value:
61-
inputParameter.value = None
62-
alg.addParameter(input_txt)
49+
with open(tempRulesName, "w") as tempRules:
50+
tempRules.write(txtRules)
51+
alg.removeParameter('input_txt')
52+
parameters['input'] = tempRulesName
53+
54+
alg.processCommand(parameters, context, True)
6355

6456

65-
def processOutputs(alg):
57+
def processOutputs(alg, parameters, context):
6658
# We need to add the from layer to outputs:
67-
out = alg.exportedLayers[alg.getParameterValue('map')]
68-
from_out = alg.getOutputValue('output')
69-
command = u"v.out.ogr -s -e input={} output=\"{}\" format=ESRI_Shapefile output_layer={}".format(
70-
out, os.path.dirname(from_out),
71-
os.path.splitext(os.path.basename(from_out))[0]
72-
)
73-
alg.commands.append(command)
74-
alg.outputCommands.append(command)
59+
fileName = alg.parameterAsOutputLayer(parameters, 'output', context)
60+
grassName = alg.exportedLayers['map']
61+
dataType = 'auto'
62+
alg.exportVectorLayer(grassName, fileName, dataType)

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

Lines changed: 0 additions & 39 deletions
This file was deleted.

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@
2626
__revision__ = '$Format:%H$'
2727

2828

29-
def processOutputs(alg):
29+
def processOutputs(alg, parameters, context):
3030
# add some export commands
3131
command = 'v.build.all'
3232
alg.commands.append(command)
3333

3434
# export the SQLite table to CSV
35-
rstable = alg.getOutputValue('rstable')
36-
# I don't use db.out.ogr because it doesn't work
37-
command = 'db.select table={} separator=comma output=\"{}\" --overwrite'.format(
38-
alg.exportedLayers[rstable],
39-
rstable
40-
)
41-
alg.commands.append(command)
42-
command = 'echo \"Integer\",\"Integer\",\"Integer\",\"Real\",\"Real\",\"Real\",\"Real\",\"Real\",\"Real\",\"Real\" > \"{}t\"'.format(rstable)
43-
alg.commands.append(command)
44-
alg.processOutputs()
35+
# rstable = alg.getOutputValue('rstable')
36+
# # I don't use db.out.ogr because it doesn't work
37+
# command = 'db.select table={} separator=comma output=\"{}\" --overwrite'.format(
38+
# alg.exportedLayers[rstable],
39+
# rstable
40+
# )
41+
# alg.commands.append(command)
42+
# command = 'echo \"Integer\",\"Integer\",\"Integer\",\"Real\",\"Real\",\"Real\",\"Real\",\"Real\",\"Real\",\"Real\" > \"{}t\"'.format(rstable)
43+
# alg.commands.append(command)
44+
alg.processOutputs(parameters, context)

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

Lines changed: 61 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,52 +30,67 @@
3030
__revision__ = '$Format:%H$'
3131

3232
import os
33-
from copy import deepcopy
33+
from qgis.core import QgsProcessingException
34+
from processing.tools.system import getTempFilename
3435

35-
36-
def incorporatePoints(alg, parameters, context, pointLayerName=u'points', networkLayerName=u'input'):
36+
def incorporatePoints(alg, parameters, context, pointLayerName='points', networkLayerName='input'):
3737
"""
3838
incorporate points with lines to form a GRASS network
3939
"""
40-
new_parameters = deepcopy(parameters)
41-
42-
# Create an intermediate GRASS layer which is the combination of network + centers
43-
intLayer = alg.getTempFilename()
4440

45-
# Grab the point layer and delete this parameter (not used by v.net.alloc)
46-
pointLayer = new_parameters[pointLayerName]
41+
# Grab the point layer and delete this parameter
42+
pointLayer = alg.parameterAsVectorLayer(parameters, pointLayerName, context)
4743
if pointLayer:
48-
pointLayer = alg.exportedLayers[pointLayer]
49-
new_parameters['points'] = pointLayer
44+
# Create an intermediate GRASS layer which is the combination of network + centers
45+
intLayer = 'net' + os.path.basename(getTempFilename())
46+
47+
pointLayer = alg.exportedLayers[pointLayerName]
48+
49+
# Grab the network layer
50+
lineLayer = alg.parameterAsVectorLayer(parameters, networkLayerName, context)
51+
if lineLayer:
52+
lineLayer = alg.exportedLayers[networkLayerName]
53+
else:
54+
raise QgsProcessingException(
55+
alg.tr('GRASS GIS 7 v.net requires a lines layer!'))
56+
57+
threshold = alg.parameterAsDouble(parameters, 'threshold', context)
5058

51-
# Grab the network layer and tell to v.net.alloc to use the temp layer instead
52-
lineLayer = new_parameters[networkLayerName]
53-
if lineLayer:
54-
lineLayer = alg.exportedLayers[lineLayer]
55-
new_parameters[networkLayerName] = lineLayer
59+
# Create the v.net connect command for point layer integration
60+
command = u"v.net input={} points={} output={} operation=connect threshold={}".format(
61+
lineLayer, pointLayer, intLayer, threshold)
62+
alg.commands.append(command)
5663

57-
threshold = parameters['threshold']
64+
# Connect the point layer database to the layer 2 of the network
65+
command = u"v.db.connect -o map={} table={} layer=2".format(intLayer, pointLayer)
66+
alg.commands.append(command)
5867

59-
# Create the v.net connect command for point layer integration
60-
command = u"v.net -s input={} points={} out={} op=connect threshold={}".format(
61-
lineLayer, pointLayer, intLayer, threshold)
62-
alg.commands.append(command)
68+
# remove undesired parameters
69+
alg.removeParameter(pointLayerName)
6370

64-
# Connect the point layer database to the layer 2 of the network
65-
command = u"v.db.connect -o map={} table={} layer=2".format(intLayer, pointLayer)
66-
alg.commands.append(command)
71+
# Use temp layer for input
72+
alg.exportedLayers[networkLayerName] = intLayer
6773

68-
alg.processCommand(new_parameters, context)
74+
# Process the command
75+
if 'threshold' in parameters:
76+
alg.removeParameter('threshold')
77+
78+
alg.processCommand(parameters, context)
6979

7080

7181
def variableOutput(alg, layers, parameters, context, nocats=True):
7282
""" Handle variable data output for v.net modules:
7383
:param layers:
74-
layers is like:
75-
{ 'output': ['point', 1], # One output of type point from layer 1
76-
'output2': ['line', 1], # One output of type line from layer 1
77-
'output3': ['point', 2] # one output of type point from layer 2
84+
layers is a dict of outputs:
85+
{ 'outputName': ['srcLayer', 'output_type', output_layer_number, nocats],
86+
...
7887
}
88+
where:
89+
- outputName is the name of the output in the description file.
90+
- srcLayer is the grass name of the layer to export.
91+
- output_type is the GRASS datatype (point/line/area/etc.).
92+
- output_layer_number is the GRASS layer number for multiple layers datasets.
93+
- nocats indicates weither we need to also export without categories items.
7994
:param parameters:
8095
:param context:
8196
:param nocats: do not add categories.
@@ -85,7 +100,21 @@ def variableOutput(alg, layers, parameters, context, nocats=True):
85100
continue
86101

87102
fileName = alg.parameterAsOutputLayer(parameters, outputName, context)
88-
grassName = '{}{}'.format(outputName, alg.uniqueSuffix)
103+
grassName = '{}{}'.format(typeList[0], alg.uniqueSuffix)
89104
alg.exportVectorLayer(
90-
grassName, fileName, typeList[0], typeList[1],
91-
False if typeList[0] == u"line" and nocats else nocats)
105+
grassName, fileName, typeList[1], typeList[2],
106+
typeList[3])
107+
108+
109+
def processOutputs(alg, parameters, context):
110+
idx = alg.parameterAsInt(parameters, 'operation', context)
111+
operations = alg.parameterDefinition('operation').options()
112+
operation = operations[idx]
113+
114+
if operation == 'nodes':
115+
outputParameter = {'output': ['output', 'point', 2, True]}
116+
elif operation == 'connect':
117+
outputParameter = {'output': ['output', 'line', 1, False]}
118+
elif operation == 'arcs':
119+
outputParameter = {'output': ['output', 'line', 1, True]}
120+
variableOutput(alg, outputParameter, parameters, context)

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
__revision__ = '$Format:%H$'
2727

28-
2928
from .v_net import incorporatePoints, variableOutput
3029

3130

@@ -34,5 +33,5 @@ def processCommand(alg, parameters, context):
3433

3534

3635
def processOutputs(alg, parameters, context):
37-
outputParameter = {'output': ['line', 1]}
38-
variableOutput(alg, outputParameter, parameters, context, False)
36+
outputParameter = {'output': ['output', 'line', 1, False]}
37+
variableOutput(alg, outputParameter, parameters, context)

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

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

2828

29-
from .v_net import incorporatePoints
29+
from .v_net import incorporatePoints, variableOutput
3030

3131

3232
def processCommand(alg, parameters, context):
3333
incorporatePoints(alg, parameters, context)
34+
35+
def processOutputs(alg, parameters, context):
36+
outputParameter = {'output': ['output', 'line', 1, True]}
37+
variableOutput(alg, outputParameter, parameters, context)

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,20 @@
2525

2626
__revision__ = '$Format:%H$'
2727

28-
from .v_net import variableOutput
28+
from .v_net import incorporatePoints, variableOutput
29+
30+
31+
def processCommand(alg, parameters, context):
32+
incorporatePoints(alg, parameters, context)
2933

3034

3135
def processOutputs(alg, parameters, context):
32-
outputParameter = {'output': ['line', 1]}
36+
idx = alg.parameterAsInt(parameters, 'method', context)
37+
operations = alg.parameterDefinition('method').options()
38+
operation = operations[idx]
39+
40+
if operation == 'articulation':
41+
outputParameter = {'output': ['output', 'point', 2, True]}
42+
elif operation == 'bridge':
43+
outputParameter = {'output': ['output', 'line', 1, False]}
3344
variableOutput(alg, outputParameter, parameters, context)

‎python/plugins/processing/algs/grass7/ext/v_net_articulation.py renamed to ‎python/plugins/processing/algs/grass7/ext/v_net_centrality.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
"""
44
***************************************************************************
5-
v_net_articulation.py
6-
---------------------
7-
Date : December 2015
8-
Copyright : (C) 2015 by Médéric Ribreux
5+
v_net_centrality.py
6+
-------------------
7+
Date : December 2017
8+
Copyright : (C) 2017 by Médéric Ribreux
99
Email : medspx at medspx dot fr
1010
***************************************************************************
1111
* *
@@ -18,16 +18,20 @@
1818
"""
1919

2020
__author__ = 'Médéric Ribreux'
21-
__date__ = 'December 2015'
22-
__copyright__ = '(C) 2015, Médéric Ribreux'
21+
__date__ = 'December 2017'
22+
__copyright__ = '(C) 2017, Médéric Ribreux'
2323

2424
# This will get replaced with a git SHA1 when you do a git archive
2525

2626
__revision__ = '$Format:%H$'
2727

28-
from .v_net import variableOutput
28+
from .v_net import incorporatePoints, variableOutput
29+
30+
31+
def processCommand(alg, parameters, context):
32+
incorporatePoints(alg, parameters, context)
2933

3034

3135
def processOutputs(alg, parameters, context):
32-
outputParameter = {'output': ['point', 1]}
36+
outputParameter = {'output': ['output', 'point', 1, False]}
3337
variableOutput(alg, outputParameter, parameters, context)

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,19 @@
2525

2626
__revision__ = '$Format:%H$'
2727

28-
from .v_net import variableOutput
28+
from .v_net import incorporatePoints, variableOutput
29+
from qgis.core import QgsProcessingParameterDefinition
2930

31+
def processCommand(alg, parameters, context):
32+
# We need to disable only output_point parameter
33+
outPoint = alg.parameterDefinition('output_point')
34+
outPoint.setFlags(outPoint.flags() | QgsProcessingParameterDefinition.FlagHidden)
35+
incorporatePoints(alg, parameters, context)
36+
outPoint.setFlags(outPoint.flags() | QgsProcessingParameterDefinition.FlagHidden)
3037

31-
def processCommand(alg, parameters):
32-
# remove the output for point
33-
outLine = alg.getOutputFromName(u'output')
34-
outPoint = alg.getOutputFromName(u'output_point')
35-
alg.exportedLayers[outPoint.value] = outLine.name + alg.uniqueSuffix
36-
alg.removeOutputFromName(u'output_point')
3738

38-
alg.processCommand()
39+
def processOutputs(alg, parameters, context):
40+
outputParameter = {'output': ['output', 'line', 1, True],
41+
'output_point': ['output', 'point', 2, True]}
42+
variableOutput(alg, outputParameter, parameters, context)
3943

40-
# Re-add output for point
41-
alg.addOutput(outPoint)
42-
43-
44-
def processOutputs(alg):
45-
outputParameter = {u"output": [u"line", 1],
46-
u"output_point": [u"point", 2]}
47-
variableOutput(alg, outputParameter)

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

Lines changed: 0 additions & 33 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,5 @@ def processCommand(alg, parameters, context):
5353

5454

5555
def processOutputs(alg, parameters, context):
56-
outputParameter = {'output': ['point', 2]}
56+
outputParameter = {'output': ['output', 'point', 2, True]}
5757
variableOutput(alg, outputParameter, parameters, context)

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

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -26,55 +26,56 @@
2626
__revision__ = '$Format:%H$'
2727

2828

29-
from processing.core.parameters import getParameterFromString
30-
from copy import deepcopy
29+
import os
30+
from .v_net import variableOutput
31+
from processing.tools.system import getTempFilename
32+
from qgis.core import QgsProcessingParameterString
3133

32-
33-
def processCommand(alg, parameters):
34+
def processCommand(alg, parameters, context):
3435
""" Handle data preparation for v.net.distance:
3536
* Integrate point layers into network vector map.
3637
* Make v.net.distance use those layers.
3738
* Delete the threshold parameter.
3839
* If where statement, connect to the db
3940
"""
40-
new_parameters = deepcopy(parameters)
41-
42-
# Grab the threshold value for our v.net connect command
43-
threshold = alg.getParameterValue(u'threshold')
44-
if threshold:
45-
del new_parameters['threshold']
46-
47-
# Grab the network layer and tell to v.net.alloc to use the temp layer instead
48-
line_layer = alg.getParameterValue(u'input')
49-
if line_layer:
50-
line_layer = alg.exportedLayers[line_layer]
51-
52-
# import the two point layers into the network
53-
for i, layer in enumerate([u'from', u'to']):
54-
# Get a temp layer name
55-
intLayer = alg.getTempFilename()
56-
57-
# Grab the from point layer and delete this parameter (not used by v.net.distance)
58-
point_layer = alg.getParameterValue(layer + u'_points')
59-
if point_layer:
60-
point_layer = alg.exportedLayers[point_layer]
61-
del new_parameters[layer + u'_points']
62-
63-
# Create the v.net connect command for point layer integration
64-
command = u"v.net -s input={} points={} out={} op=connect threshold={} arc_layer=1 node_layer={}".format(line_layer, point_layer, intLayer, threshold, i + 2)
65-
alg.commands.append(command)
66-
line_layer = intLayer
67-
68-
# Add the parameter to the algorithm
69-
parameter = alg.getParameterFromName(u'{}_layer'.format(layer))
70-
if not parameter:
71-
parameter = getParameterFromString(u'ParameterNumber|{0}_layer|{0} layer number|1|3|2|False'.format(layer))
72-
alg.addParameter(parameter)
73-
new_parameters[parameter.name()] = i + 2
74-
75-
# Make the connection with attribute table
76-
command = u"v.db.connect -o map={} table={} layer={}".format(line_layer, point_layer, i + 2)
77-
alg.commands.append(command)
78-
79-
new_parameters['input'] = line_layer
80-
alg.processCommand(new_parameters, context)
41+
# Grab the point layer and delete this parameter
42+
lineLayer = alg.exportedLayers['input']
43+
fromLayer = alg.exportedLayers['flayer']
44+
toLayer = alg.exportedLayers['tlayer']
45+
intLayer = 'bufnet' + os.path.basename(getTempFilename())
46+
netLayer = 'net' + os.path.basename(getTempFilename())
47+
threshold = alg.parameterAsDouble(parameters, 'threshold', context)
48+
49+
# Create the v.net connect command for from_layer integration
50+
command = u"v.net input={} points={} output={} operation=connect threshold={} arc_layer=1 node_layer=2".format(
51+
lineLayer, fromLayer, intLayer, threshold)
52+
alg.commands.append(command)
53+
54+
# Do it again with to_layer
55+
command = u"v.net input={} points={} output={} operation=connect threshold={} arc_layer=1 node_layer=3".format(
56+
intLayer, toLayer, netLayer, threshold)
57+
alg.commands.append(command)
58+
59+
# Connect the point layer database to the layer 2 of the network
60+
command = u"v.db.connect -o map={} table={} layer=2".format(netLayer, fromLayer)
61+
alg.commands.append(command)
62+
63+
command = u"v.db.connect -o map={} table={} layer=3".format(netLayer, toLayer)
64+
alg.commands.append(command)
65+
66+
# remove undesired parameters
67+
alg.removeParameter('flayer')
68+
alg.removeParameter('tlayer')
69+
alg.removeParameter('threshold')
70+
alg.exportedLayers['input'] = netLayer
71+
72+
# Add the two new parameters
73+
fLayer = QgsProcessingParameterString('from_layer', None, 2, False, False)
74+
alg.addParameter(fLayer)
75+
tLayer = QgsProcessingParameterString('to_layer', None, 3, False, False)
76+
alg.addParameter(tLayer)
77+
alg.processCommand(parameters, context)
78+
79+
def processOutputs(alg, parameters, context):
80+
outputParameter = {'output': ['output', 'line', 1, True]}
81+
variableOutput(alg, outputParameter, parameters, context)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from .v_net import incorporatePoints, variableOutput
3030

3131

32-
def checkParameterValuesBeforeExecuting(alg):
32+
def checkParameterValuesBeforeExecuting(alg, parameters, context):
3333
""" Verify if we have the right parameters """
3434
params = [u'where', u'cats']
3535
values = []
@@ -54,6 +54,6 @@ def processCommand(alg, parameters, context):
5454

5555

5656
def processOutputs(alg, parameters, context):
57-
outputParameter = {'output': ['line', 1],
58-
'cut': ['line', 1]}
57+
outputParameter = {'output': ['output', 'line', 1, True],
58+
'cut': ['cut', 'line', 1, True]}
5959
variableOutput(alg, outputParameter, parameters, context)

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@
2525

2626
__revision__ = '$Format:%H$'
2727

28-
from .v_net import incorporatePoints
28+
from .v_net import incorporatePoints, variableOutput
2929

3030

3131
def processCommand(alg, parameters, context):
3232
incorporatePoints(alg, parameters, context)
33+
34+
35+
def processOutputs(alg, parameters, context):
36+
outputParameter = {'output': ['output', 'line', 1, True]}
37+
variableOutput(alg, outputParameter, parameters, context)

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

Lines changed: 0 additions & 33 deletions
This file was deleted.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@
2525

2626
__revision__ = '$Format:%H$'
2727

28-
from .v_net import incorporatePoints
28+
from .v_net import incorporatePoints, variableOutput
2929

3030

3131
def processCommand(alg, parameters, context):
3232
incorporatePoints(alg, parameters, context)
33+
34+
35+
def processOutputs(alg, parameters, context):
36+
outputParameter = {'output': ['output', 'line', 1, False]}
37+
variableOutput(alg, outputParameter, parameters, context)

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

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,13 @@
2525

2626
__revision__ = '$Format:%H$'
2727

28-
from processing.core.parameters import getParameterFromString
29-
from .v_net import incorporatePoints
30-
from copy import deepcopy
28+
from .v_net import incorporatePoints, variableOutput
29+
from qgis.core import QgsProcessingParameterDefinition
3130

31+
def processCommand(alg, parameters, context):
32+
incorporatePoints(alg, parameters, context)
3233

33-
def processCommand(alg, parameters):
34-
# We temporary remove the output 'sequence'
35-
new_parameters = deepcopy(parameters)
36-
sequence = alg.getOutputFromName(u'sequence')
37-
sequenceFile = alg.getOutputValue(u'sequence')
38-
alg.exportedLayers[sequence.value] = sequence.name + alg.uniqueSuffix
39-
alg.removeOutputFromName(u'sequence')
4034

41-
# We create a new parameter with the same name
42-
param = getParameterFromString(u"ParameterString|sequence|sequence|None|False|False")
43-
new_parameters[param.name()] = sequenceFile
44-
45-
# Let's do the incorporation and command generation
46-
incorporatePoints(alg, new_parameters, context)
47-
48-
# then we delete the input parameter and add the old output
49-
alg.addOutput(sequence)
35+
def processOutputs(alg, parameters, context):
36+
outputParameter = {'output': ['output', 'line', 1, True]}
37+
variableOutput(alg, outputParameter, parameters, context)

‎python/plugins/processing/algs/grass7/ext/v_net_arcs.py renamed to ‎python/plugins/processing/algs/grass7/ext/v_net_spanningtree.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
"""
44
***************************************************************************
5-
v_net_arcs.py
5+
v_net_spanningtree.py
66
---------------------
7-
Date : December 2015
8-
Copyright : (C) 2015 by Médéric Ribreux
7+
Date : December 2017
8+
Copyright : (C) 2017 by Médéric Ribreux
99
Email : medspx at medspx dot fr
1010
***************************************************************************
1111
* *
@@ -18,16 +18,20 @@
1818
"""
1919

2020
__author__ = 'Médéric Ribreux'
21-
__date__ = 'December 2015'
22-
__copyright__ = '(C) 2015, Médéric Ribreux'
21+
__date__ = 'December 2017'
22+
__copyright__ = '(C) 2017, Médéric Ribreux'
2323

2424
# This will get replaced with a git SHA1 when you do a git archive
2525

2626
__revision__ = '$Format:%H$'
2727

28-
from .v_net import variableOutput
28+
from .v_net import incorporatePoints, variableOutput
29+
30+
31+
def processCommand(alg, parameters, context):
32+
incorporatePoints(alg, parameters, context)
2933

3034

3135
def processOutputs(alg, parameters, context):
32-
outputParameter = {'output': ['line', 1]}
36+
outputParameter = {'output': ['output', 'line', 1, True]}
3337
variableOutput(alg, outputParameter, parameters, context)

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@
2525

2626
__revision__ = '$Format:%H$'
2727

28-
from .v_net import incorporatePoints
28+
from .v_net import incorporatePoints, variableOutput
2929

3030

3131
def processCommand(alg, parameters, context):
3232
incorporatePoints(alg, parameters, context)
33+
34+
35+
def processOutputs(alg, parameters, context):
36+
outputParameter = {'output': ['output', 'line', 1, False]}
37+
variableOutput(alg, outputParameter, parameters, context)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@
2929

3030

3131
def processOutputs(alg, parameters, context):
32-
outputParameter = {'output': ['line', 1]}
33-
variableOutput(alg, outputParameter, parameters, context, False)
32+
outputParameter = {'output': ['output', 'line', 1, True]}
33+
variableOutput(alg, outputParameter, parameters, context)

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

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626
__revision__ = '$Format:%H$'
2727

28-
from processing.core.parameters import getParameterFromString
29-
28+
import os
29+
from processing.algs.grass7.Grass7Utils import Grass7Utils
3030

3131
def checkParameterValuesBeforeExecuting(alg, parameters, context):
3232
""" Verify if we have the right parameters """
@@ -38,31 +38,17 @@ def checkParameterValuesBeforeExecuting(alg, parameters, context):
3838

3939

4040
def processCommand(alg, parameters, context):
41-
# handle inline add data
42-
input_txt = alg.parameterAsString(parameters, 'inline_points', context)
43-
inputParameter = alg.parametersAsString(parameters, 'points', context)
44-
if input_txt.value:
41+
# handle inline points
42+
inlinePoints = alg.parameterAsString(parameters, 'inline_points', context)
43+
if inlinePoints:
4544
# Creates a temporary txt file
46-
ruleFile = alg.getTempFilename()
47-
45+
pointsName = getTempFilename()
46+
4847
# Inject rules into temporary txt file
49-
with open(ruleFile, "w") as tempRules:
50-
tempRules.write(input_txt.value)
51-
inputParameter.value = ruleFile
52-
alg.parameters.remove(input_txt)
53-
54-
# exclude output for from_output
55-
output = alg.getOutputFromName('rmsfile')
56-
alg.removeOutputFromName('rmsfile')
57-
58-
# Create a false input parameter for rmsfile
59-
param = getParameterFromString(u"ParameterString|rmsfile|the file|None|False|False")
60-
param.value = output.value
61-
alg.addParameter(param)
48+
with open(pointsName, "w") as tempPoints:
49+
tempPoints.write(inlinePoints)
50+
alg.removeParameter('inline_points')
51+
parameters['points'] = tempPoints
6252

63-
alg.processCommand(parameters, context)
64-
alg.parameters.remove(param)
65-
alg.addOutput(output)
66-
if input_txt.value:
67-
inputParameter.value = None
68-
alg.addParameter(input_txt)
53+
alg.processCommand(parameters, context, True)
54+

0 commit comments

Comments
 (0)
Please sign in to comment.