Skip to content

Commit 14709f5

Browse files
author
Médéric RIBREUX
committed
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

+16-5
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

+3-3
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

+2-2
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

-7
This file was deleted.

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

+1
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

+1
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

+1
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

-9
This file was deleted.

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

+3-4
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

-7
This file was deleted.

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

+1-1
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

+2-2
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
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

+1-1
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

+20-32
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

-39
This file was deleted.

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

+11-11
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)

0 commit comments

Comments
 (0)