Skip to content

Commit 85b87d5

Browse files
author
Médéric RIBREUX
committedJan 9, 2016
Non variable output version. Adds:
* v.net.arcs for v.net 'arcs' operation. * v.net.articulation for v.net.brdige 'articulation' method. * v.net.connect for v.net 'connect' operation. * v.net.nodes for v.net 'nodes' operation. * v.net.nreport for v.net 'nreport' operation. * v.net.report for v.net 'report operation. * Some code simplification.
1 parent 14a6115 commit 85b87d5

21 files changed

+218
-125
lines changed
 
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
v.net
2+
v.net.arcs - Creates arcs from a file of points
3+
Vector (v.*)
4+
ParameterVector|points|Input vector point layer (nodes)|0|False
5+
ParameterFile|file|Name of input arcs file|False|False
6+
Hardcoded|operation=arcs
7+
OutputVector|output|Arcs
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
v.net.bridge
2+
v.net.articulation - Computes articulation points in the network
3+
Vector (v.*)
4+
ParameterVector|input|Input vector line layer (network)|1|False
5+
Hardcoded|method=articulation
6+
*ParameterTableField|arc_column|Arc forward/both direction(s) cost column (name)|input|0|True
7+
*ParameterTableField|arc_backward_column|Arc backward direction cost column (name)|input|0|True
8+
OutputVector|output|Articulation
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
v.net.bridge
2-
Computes bridges and articulation points in the network.
2+
Computes bridges in the network.
33
Vector (v.*)
44
ParameterVector|input|Input vector line layer (network)|1|False
5-
ParameterSelection|method|Operation to be performed|bridge;articulation|0|False
5+
Hardcoded|method=bridge
66
*ParameterTableField|arc_column|Arc forward/both direction(s) cost column (name)|input|0|True
77
*ParameterTableField|arc_backward_column|Arc backward direction cost column (name)|input|0|True
8-
OutputVector|output|Bridge_Or_Articulation
8+
OutputVector|output|Bridge
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
v.net
2+
v.net.connect - Connects points to nearest arcs in a network
3+
Vector (v.*)
4+
ParameterVector|input|Input vector line layer (arcs)|1|False
5+
ParameterVector|points|Input vector point layer (nodes)|0|False
6+
Hardcoded|operation=connect
7+
ParameterNumber|threshold|Threshold for connection distance|None|None|50.0
8+
*ParameterBoolean|-s|Snap points to network|False
9+
OutputVector|output|Network
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
v.net
2+
v.net.nodes - Creates points for each network arcs
3+
Vector (v.*)
4+
ParameterVector|input|Input vector line layer (arcs)|1|False
5+
Hardcoded|operation=nodes
6+
*ParameterBoolean|-c|Assign unique categories to new points (for operation 'nodes')|False
7+
OutputVector|output|Nodes
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
v.net
2+
v.net.nreport - Reports nodes information of a network
3+
Vector (v.*)
4+
ParameterVector|input|Input vector line layer (arcs)|1|False
5+
Hardcoded|operation=nreport
6+
OutputFile|output|NReport
7+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
v.net
2+
v.net.report - Reports lines information of a network
3+
Vector (v.*)
4+
ParameterVector|input|Input vector line layer (arcs)|1|False
5+
Hardcoded|operation=report
6+
OutputFile|output|Report
7+

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

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

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

Lines changed: 14 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@
1717
***************************************************************************
1818
1919
This Python module handles pre-treatment operations for v.net.* GRASS7 modules.
20-
Before using v.net you often have to incorporate a points layer into the network
21-
vector map.
22-
23-
You also have different output depending on some parameters.
24-
25-
This file also contains dedicated ext functions for v.net module...
20+
Before using a v.net module you often have to incorporate a points layer into
21+
the network vector map.
2622
"""
2723

2824
__author__ = 'Médéric Ribreux'
@@ -83,109 +79,27 @@ def incorporatePoints(alg, pointLayerName=u'points', networkLayerName=u'input'):
8379

8480
def variableOutput(alg, params, nocats=True):
8581
""" Handle variable data output for v.net modules:
86-
parameters:
87-
{ u"output": { u"param" : { 0: u"line", 1: u"point" } }, # parametized output
88-
u"output3: u"line" # use this type for this output
82+
params is like:
83+
{ u"output": [u"point", 1], # One output of type point from layer 1
84+
u"output2": [u"line", 1], # One output of type line from layer 1
85+
u"output3: [u"point", 2] # one output of type point from layer 2
8986
}
87+
9088
"""
9189

9290
# Build the v.out.ogr commands
93-
for outName in params.keys():
94-
param = params[outName]
95-
# There is a dict parameter:
96-
if isinstance(param, dict):
97-
paramName = param.keys()[0]
98-
paramValue = alg.getParameterValue(paramName)
99-
paramDict = param[paramName]
100-
geomType = paramDict[paramValue]
101-
elif isinstance(param, unicode):
102-
geomType = param
103-
else:
91+
for outputName, typeList in params.iteritems():
92+
if not isinstance(typeList, list):
10493
continue
10594

106-
out = alg.getOutputValue(outName)
107-
command = u"v.out.ogr {} type={} -s -e input={} output=\"{}\" format=ESRI_Shapefile output_layer={}".format(
108-
u"" if geomType == u"line" and nocats else u"-c",
109-
geomType,
95+
out = alg.getOutputValue(outputName)
96+
command = u"v.out.ogr {} type={} layer={} -s -e input={} output=\"{}\" format=ESRI_Shapefile output_layer={}".format(
97+
u"" if typeList[0] == u"line" and nocats else u"-c",
98+
typeList[0],
99+
typeList[1],
110100
alg.exportedLayers[out],
111101
os.path.dirname(out),
112102
os.path.basename(out)[:-4]
113103
)
114104
alg.commands.append(command)
115105
alg.outputCommands.append(command)
116-
117-
118-
# v.net dedicated functions
119-
def checkParameterValuesBeforeExecuting(alg):
120-
""" Verify if we have the right parameters """
121-
operation = alg.getParameterValue(u'operation')
122-
pointLayer = alg.getParameterValue(u'points')
123-
threshold = alg.getParameterValue(u'threshold')
124-
fileName = alg.getParameterValue(u'file')
125-
if operation == 1:
126-
if not (pointLayer and threshold):
127-
return alg.tr("You need to set an input points layer and a threshold for operation 'connect' !")
128-
elif operation == 2:
129-
if not (fileName and pointLayer):
130-
return alg.tr("You need to set an input points layer and a file for operation 'arcs' !")
131-
132-
return None
133-
134-
135-
def processCommand(alg):
136-
""" Handle data preparation for v.net:
137-
* Integrate point layers into network vector map.
138-
* Make v.net.distance use those layers.
139-
* Delete the threshold parameter.
140-
"""
141-
paramsToDelete = []
142-
143-
# If we use the node operation, no need for threshold,
144-
operation = alg.getParameterValue(u'operation')
145-
if operation == 0:
146-
paramsToDelete.append(alg.getParameterFromName(u'threshold'))
147-
paramsToDelete.append(alg.getParameterFromName(u'file'))
148-
elif operation == 2:
149-
paramsToDelete.append(alg.getParameterFromName(u'threshold'))
150-
elif operation in [3, 4]:
151-
paramsToDelete.append(alg.getParameterFromName(u'threshold'))
152-
paramsToDelete.append(alg.getParameterFromName(u'points'))
153-
paramsToDelete.append(alg.getParameterFromName(u'file'))
154-
155-
# Grab the network layer and tell to v.net.alloc to use the temp layer instead
156-
lineLayer = alg.getParameterValue(u'input')
157-
if lineLayer:
158-
lineLayer = alg.exportedLayers[lineLayer]
159-
160-
# Delete some unnecessary parameters
161-
for param in paramsToDelete:
162-
alg.parameters.remove(param)
163-
164-
alg.processCommand()
165-
166-
# Bring back the parameters:
167-
for param in paramsToDelete:
168-
alg.parameters.append(param)
169-
170-
171-
def processOutputs(alg):
172-
""" Handle data output for v.net:
173-
* use v.out.ogr with type=line on node operation.
174-
* use v.out.ogr with type=point on articulation method.
175-
"""
176-
177-
# Find the method used
178-
operation = alg.getParameterValue(u'operation')
179-
180-
# Grab the name of the output
181-
out = alg.getOutputValue(u'output')
182-
183-
# Build the v.out.ogr command
184-
command = u"v.out.ogr -c type={} layer={} -e input={} output=\"{}\" format=ESRI_Shapefile output_layer={}".format(
185-
u"point" if operation == 0 else "line",
186-
u"2" if operation == 0 else u"1",
187-
alg.exportedLayers[out],
188-
os.path.dirname(out),
189-
os.path.basename(out)[:-4]
190-
)
191-
alg.commands.append(command)

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

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

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

28-
from v_net import incorporatePoints
28+
29+
from v_net import incorporatePoints, variableOutput
2930

3031

3132
def processCommand(alg):
3233
incorporatePoints(alg)
34+
35+
36+
def processOutputs(alg):
37+
outputParameter = {u"output": [u"line", 1]}
38+
variableOutput(alg, outputParameter, False)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

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

28+
2829
from v_net import incorporatePoints
2930

3031

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
v_net_arcs.py
6+
---------------------
7+
Date : December 2015
8+
Copyright : (C) 2015 by Médéric Ribreux
9+
Email : medspx at medspx dot fr
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Médéric Ribreux'
21+
__date__ = 'December 2015'
22+
__copyright__ = '(C) 2015, Médéric Ribreux'
23+
24+
# This will get replaced with a git SHA1 when you do a git archive
25+
26+
__revision__ = '$Format:%H$'
27+
28+
from v_net import variableOutput
29+
30+
31+
def processOutputs(alg):
32+
outputParameter = {u"output": [u"line", 1]}
33+
variableOutput(alg, outputParameter)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
v_net_articulation.py
6+
---------------------
7+
Date : December 2015
8+
Copyright : (C) 2015 by Médéric Ribreux
9+
Email : medspx at medspx dot fr
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Médéric Ribreux'
21+
__date__ = 'December 2015'
22+
__copyright__ = '(C) 2015, Médéric Ribreux'
23+
24+
# This will get replaced with a git SHA1 when you do a git archive
25+
26+
__revision__ = '$Format:%H$'
27+
28+
from v_net import variableOutput
29+
30+
31+
def processOutputs(alg):
32+
outputParameter = {u"output": [u"point", 1]}
33+
variableOutput(alg, outputParameter)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@
2929

3030

3131
def processOutputs(alg):
32-
outputParameter = {u"output": {u"method": {0: u"line", 1: u"point"}}}
32+
outputParameter = {u"output": [u"line", 1]}
3333
variableOutput(alg, outputParameter)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030

3131
def processCommand(alg):
3232
# remove the output for point
33-
outPoint = alg.getOutputFromName(u'output_point')
3433
outLine = alg.getOutputFromName(u'output')
34+
outPoint = alg.getOutputFromName(u'output_point')
3535
alg.exportedLayers[outPoint.value] = outLine.name + alg.uniqueSufix
3636
alg.removeOutputFromName(u'output_point')
3737

@@ -42,6 +42,6 @@ def processCommand(alg):
4242

4343

4444
def processOutputs(alg):
45-
outputParameter = {u"output": u"line",
46-
u"output_point": u"point"}
45+
outputParameter = {u"output": [u"line", 1],
46+
u"output_point": [u"point", 2]}
4747
variableOutput(alg, outputParameter)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
v_net_connect.py
6+
---------------------
7+
Date : December 2015
8+
Copyright : (C) 2015 by Médéric Ribreux
9+
Email : medspx at medspx dot fr
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Médéric Ribreux'
21+
__date__ = 'December 2015'
22+
__copyright__ = '(C) 2015, Médéric Ribreux'
23+
24+
# This will get replaced with a git SHA1 when you do a git archive
25+
26+
__revision__ = '$Format:%H$'
27+
28+
import os
29+
30+
31+
def processOutputs(alg):
32+
out = alg.getOutputValue(u"output")
33+
command = u"v.out.ogr -c type=line layer=1 -e input={} output=\"{}\" format=ESRI_Shapefile output_layer={}".format(
34+
alg.exportedLayers[out],
35+
os.path.dirname(out),
36+
os.path.basename(out)[:-4]
37+
)
38+
alg.commands.append(command)
39+
alg.outputCommands.append(command)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ def processCommand(alg):
4747

4848

4949
def processOutputs(alg):
50-
outputParameter = {u"output": u"point"}
50+
outputParameter = {u"output": [u"point", 2]}
5151
variableOutput(alg, outputParameter)

‎python/plugins/processing/algs/grass7/ext/v_net_distance.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

29-
from processing.core.parameters import getParameterFromString, ParameterVector, ParameterNumber, ParameterBoolean, ParameterString
29+
from processing.core.parameters import getParameterFromString
3030

3131

3232
def processCommand(alg):

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

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

2828

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

3131

3232
def checkParameterValuesBeforeExecuting(alg):
@@ -48,6 +48,6 @@ def processCommand(alg):
4848

4949

5050
def processOutputs(alg):
51-
outputParameter = {u"output": u"line",
52-
u"cut": u"line"}
51+
outputParameter = {u"output": [u"line", 1],
52+
u"cut": [u"line", 1]}
5353
variableOutput(alg, outputParameter)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
v_net_nodes.py
6+
---------------------
7+
Date : December 2015
8+
Copyright : (C) 2015 by Médéric Ribreux
9+
Email : medspx at medspx dot fr
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Médéric Ribreux'
21+
__date__ = 'December 2015'
22+
__copyright__ = '(C) 2015, Médéric Ribreux'
23+
24+
# This will get replaced with a git SHA1 when you do a git archive
25+
26+
__revision__ = '$Format:%H$'
27+
28+
from v_net import variableOutput
29+
30+
31+
def processOutputs(alg):
32+
outputParameter = {u"output": [u"point", 2]}
33+
variableOutput(alg, outputParameter)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@
2929

3030

3131
def processOutputs(alg):
32-
outputParameter = {u"output": u"line"}
32+
outputParameter = {u"output": [u"line", 1]}
3333
variableOutput(alg, outputParameter, False)

0 commit comments

Comments
 (0)
Please sign in to comment.