Skip to content

Commit 9551ca7

Browse files
committed
Merge pull request #2628 from medspx/work_vnet_processing
[Feature][Processing] GRASS v.net modules
2 parents ea92e11 + 89a1ad5 commit 9551ca7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1106
-82
lines changed

python/plugins/processing/algs/grass7/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ FILE(GLOB PY_FILES *.py)
22
FILE(GLOB OTHER_FILES grass7.txt)
33
FILE(GLOB DESCR_FILES description/*.txt)
44

5+
ADD_SUBDIRECTORY(ext)
6+
57
PLUGIN_INSTALL(processing algs/grass7 ${PY_FILES} ${OTHER_FILES})
68
PLUGIN_INSTALL(processing algs/grass7/description ${DESCR_FILES})

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

Lines changed: 111 additions & 82 deletions
Large diffs are not rendered by default.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
v.net.alloc
2+
Allocates subnets for nearest centers (direction from center)
3+
Vector (v.*)
4+
ParameterVector|input|Input vector line layer (arcs)|1|False
5+
ParameterVector|points|Centers point layer (nodes)|0|False
6+
ParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|0.0|None|50.0|False
7+
*ParameterString|center_cats|Category values|1-100000|False|False
8+
*ParameterSelection|arc_type|Arc type|line;boundary;line,boundary|2
9+
*ParameterTableField|arc_column|Arc forward/both direction(s) cost column (number)|input|0|True
10+
*ParameterTableField|arc_backward_column|Arc backward direction cost column (number)|input|0|True
11+
*ParameterTableField|node_column|Node cost column (number)|points|0|True
12+
*ParameterBoolean|-g|Use geodesic calculation for longitude-latitude locations|False|True
13+
OutputVector|output|Network_Alloc
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
v.net.allpairs
2+
Computes the shortest path between all pairs of nodes in the network
3+
Vector (v.*)
4+
ParameterVector|input|Input vector line layer (arcs)|1|False
5+
ParameterVector|points|Centers point layer (nodes)|0|False
6+
ParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|0.0|None|50.0|False
7+
*ParameterString|cats|Category values|1-10000|False|False
8+
*ParameterString|where|WHERE condition of SQL statement without 'where' keyword'||True|False
9+
*ParameterTableField|arc_column|Arc forward/both direction(s) cost column (number)|input|0|True
10+
*ParameterTableField|arc_backward_column|Arc backward direction cost column (number)|input|0|True
11+
*ParameterTableField|node_column|Node cost column (number)|points|0|True
12+
*ParameterBoolean|-g|Use geodesic calculation for longitude-latitude locations|False|True
13+
OutputVector|output|Network_Allpairs
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
v.net.bridge
2+
Computes bridges in the network.
3+
Vector (v.*)
4+
ParameterVector|input|Input vector line layer (network)|1|False
5+
Hardcoded|method=bridge
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|Bridge
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
v.net.centrality
2+
Computes degree, centrality, betweeness, closeness and eigenvector centrality measures in the network.
3+
Vector (v.*)
4+
ParameterVector|input|Input vector line layer (network)|1|False
5+
ParameterString|degree|Name of degree centrality column|degree|False|True
6+
ParameterString|closeness|Name of closeness centrality column|closeness|False|True
7+
ParameterString|betweenness|Name of betweenness centrality column||False|True
8+
ParameterString|eigenvector|Name of eigenvector centrality column||False|True
9+
*ParameterNumber|iterations|Maximum number of iterations to compute eigenvector centrality|1|None|1000|True
10+
*ParameterNumber|error|Cumulative error tolerance for eigenvector centrality|0.001|None|0.1|True
11+
*ParameterString|cats|Category values||False|True
12+
*ParameterString|where|WHERE conditions of SQL statement without 'where' keyword||True|True
13+
*ParameterTableField|arc_column|Arc forward/both direction(s) cost column (number)|input|0|True
14+
*ParameterTableField|arc_backward_column|Arc backward direction cost column (number)|input|0|True
15+
*ParameterBoolean|-a|Add points on nodes|True|True
16+
*ParameterBoolean|-g|Use geodesic calculation for longitude-latitude locations|False|True
17+
OutputVector|output|Network_Centrality
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
v.net.components
2+
Computes strongly and weakly connected components in the network.
3+
Vector (v.*)
4+
ParameterVector|input|Input vector line layer (network)|1|False
5+
ParameterSelection|method|Type of components|weak;strong|0|False
6+
*ParameterTableField|arc_column|Arc forward/both direction(s) cost column (number)|input|0|True
7+
*ParameterTableField|arc_backward_column|Arc backward direction cost column (number)|input|0|True
8+
*ParameterBoolean|-a|Add points on nodes|True|True
9+
OutputVector|output|Network_Components_Line
10+
OutputVector|output_point|Network_Components_Point
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
v.net.connectivity
2+
Computes vertex connectivity between two sets of nodes in the network.
3+
Vector (v.*)
4+
ParameterVector|input|Input vector line layer (network)|1|False
5+
ParameterVector|points|Input vector point layer (first set of nodes)|0|False
6+
ParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|0.0|None|50.0|False
7+
ParameterString|set1_cats|Set1 Category values||False|True
8+
ParameterString|set1_where|Set1 WHERE conditions of SQL statement without 'where' keyword||True|True
9+
ParameterString|set2_cats|Set2 Category values||False|True
10+
ParameterString|set2_where|Set2 WHERE conditions of SQL statement without 'where' keyword||True|True
11+
*ParameterTableField|arc_column|Arc forward/both direction(s) cost column (number)|input|0|True
12+
*ParameterTableField|arc_backward_column|Arc backward direction cost column (number)|input|0|True
13+
*ParameterTableField|node_column|Node cost column (number)|points|0|True
14+
OutputVector|output|Network_Connectivity
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
v.net.distance
2+
Computes shortest distance via the network between the given sets of features.
3+
Vector (v.*)
4+
ParameterVector|input|Input vector line layer (network)|1|False
5+
ParameterVector|from_points|Input vector point layer (from)|0|False
6+
ParameterVector|to_points|Input vector point layer (to)|0|False
7+
ParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|0.0|None|50.0|False
8+
*ParameterSelection|arc_type|Arc type|line;boundary;line,boundary|2
9+
*ParameterString|from_cats|From Category values||False|True
10+
*ParameterString|from_where|From WHERE conditions of SQL statement without 'where' keyword||True|True
11+
*ParameterSelection|to_type|To feature type|point;line;boundary|0
12+
*ParameterString|to_cats|To Category values||False|True
13+
*ParameterString|to_where|To WHERE conditions of SQL statement without 'where' keyword||True|True
14+
*ParameterTableField|arc_column|Arc forward/both direction(s) cost column (number)|input|0|True
15+
*ParameterTableField|arc_backward_column|Arc backward direction cost column (number)|input|0|True
16+
*ParameterTableField|node_column|Node cost column (number)|from_points|0|True
17+
*ParameterBoolean|-g|Use geodesic calculation for longitude-latitude locations|False|True
18+
OutputVector|output|Network_Distance
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
v.net.flow
2+
Computes the maximum flow between two sets of nodes in the network.
3+
Vector (v.*)
4+
ParameterVector|input|Input vector line layer (network)|1|False
5+
ParameterVector|points|Input vector point layer (flow nodes)|0|False
6+
ParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|0.0|None|50.0|False
7+
ParameterString|source_cats|Source Category values||False|True
8+
ParameterString|source_where|Source WHERE conditions of SQL statement without 'where' keyword||True|True
9+
ParameterString|sink_cats|Sink Category values||False|True
10+
ParameterString|sink_where|Sink WHERE conditions of SQL statement without 'where' keyword||True|True
11+
*ParameterTableField|arc_column|Arc forward/both direction(s) cost column (number)|input|0|True
12+
*ParameterTableField|arc_backward_column|Arc backward direction cost column (number)|input|0|True
13+
*ParameterTableField|node_column|Node cost column (number)|points|0|True
14+
OutputVector|output|Network_Flow
15+
OutputVector|cut|Network_Cut
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
v.net.iso
2+
Splits network by cost isolines.
3+
Vector (v.*)
4+
ParameterVector|input|Input vector line layer (arcs)|1|False
5+
ParameterVector|points|Centers point layer (nodes)|0|False
6+
ParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|0.0|None|50.0|False
7+
*ParameterSelection|arc_type|Arc type|line;boundary;line,boundary|2
8+
*ParameterString|center_cats|Category values|1-100000|False|False
9+
ParameterString|costs|Costs for isolines|1000,2000,3000|False|False
10+
*ParameterTableField|arc_column|Arc forward/both direction(s) cost column (number)|input|0|True
11+
*ParameterTableField|arc_backward_column|Arc backward direction cost column (number)|input|0|True
12+
*ParameterTableField|node_column|Node cost column (number)|points|0|True
13+
*ParameterBoolean|-g|Use geodesic calculation for longitude-latitude locations|False|True
14+
OutputVector|output|Network_Iso
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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
v.net.path
2+
Finds shortest path on vector network
3+
Vector (v.*)
4+
ParameterVector|input|Input vector line layer (arcs)|1|False
5+
ParameterVector|points|Centers point layer (nodes)|0|False
6+
ParameterFile|file|Name of file containing start and end points|False|False
7+
ParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|0.0|None|50.0|False
8+
*ParameterSelection|type|Arc type|line;boundary;line,boundary|2
9+
*ParameterTableField|arc_column|Arc forward/both direction(s) cost column (number)|input|0|True
10+
*ParameterTableField|arc_backward_column|Arc backward direction cost column (number)|input|0|True
11+
*ParameterTableField|node_column|Node cost column (number)|points|0|True
12+
*ParameterNumber|dmax|Maximum distance to the network|None|None|1000.0|True
13+
*ParameterBoolean|-g|Use geodesic calculation for longitude-latitude locations|False|True
14+
*ParameterBoolean|-s|Write output as original input segments, not each path as one line|False|True
15+
OutputVector|output|Network_Path
16+
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+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
v.net.salesman
2+
Creates a cycle connecting given nodes (Traveling salesman problem)
3+
Vector (v.*)
4+
ParameterVector|input|Input vector line layer (arcs)|1|False
5+
ParameterVector|points|Centers point layer (nodes)|0|False
6+
ParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|0.0|None|50.0|False
7+
*ParameterSelection|arc_type|Arc type|line;boundary;line,boundary|2
8+
*ParameterString|center_cats|Category values|1-100000|False|False
9+
*ParameterTableField|arc_column|Arc forward/both direction(s) cost column (number)|input|0|True
10+
*ParameterTableField|arc_backward_column|Arc backward direction cost column (number)|input|0|True
11+
*ParameterBoolean|-g|Use geodesic calculation for longitude-latitude locations|False|True
12+
OutputVector|output|Network_Salesman
13+
OutputTable|sequence|Salesman_Nodes_Sequence
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
v.net.spanningtree
2+
Computes minimum spanning tree for the network.
3+
Vector (v.*)
4+
ParameterVector|input|Input vector line layer (arcs)|1|False
5+
*ParameterTableField|arc_column|Arc forward/both direction(s) cost column (number)|input|0|True
6+
*ParameterBoolean|-g|Use geodesic calculation for longitude-latitude locations|False|True
7+
OutputVector|output|SpanningTree
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
v.net.steiner
2+
Creates Steiner tree for the network and given terminals
3+
Vector (v.*)
4+
ParameterVector|input|Input vector line layer (arcs)|1|False
5+
ParameterVector|points|Centers point layer (nodes)|0|False
6+
ParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|0.0|None|50.0|False
7+
*ParameterSelection|arc_type|Arc type|line;boundary;line,boundary|2
8+
*ParameterString|terminal_cats|Category values|1-100000|False|False
9+
*ParameterTableField|acolumn|Arc forward/both direction(s) cost column (number)|input|0|True
10+
*ParameterNumber|npoints|Maximum distance to the network|None|None|-1|True
11+
*ParameterBoolean|-g|Use geodesic calculation for longitude-latitude locations|False|True
12+
OutputVector|output|Network_Steiner
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
v.net.visibility
2+
Performs visibility graph construction.
3+
Vector (v.*)
4+
ParameterVector|input|Input vector line layer (arcs)|-1|False
5+
*ParameterString|coordinates|Coordinates||False|True
6+
*ParameterVector|visibility|Input vector line layer containing visable points|1|True
7+
OutputVector|output|Network_Visibility
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FILE(GLOB PY_FILES *.py)
2+
3+
PLUGIN_INSTALL(processing algs/grass7/ext ${PY_FILES})
File renamed without changes.
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
v_net.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+
This Python module handles pre-treatment operations for v.net.* GRASS7 modules.
20+
Before using a v.net module you often have to incorporate a points layer into
21+
the network vector map.
22+
"""
23+
24+
__author__ = 'Médéric Ribreux'
25+
__date__ = 'December 2015'
26+
__copyright__ = '(C) 2015, Médéric Ribreux'
27+
28+
# This will get replaced with a git SHA1 when you do a git archive
29+
30+
__revision__ = '$Format:%H$'
31+
32+
import os
33+
from processing.core.parameters import getParameterFromString, ParameterVector, ParameterNumber, ParameterBoolean, ParameterString
34+
35+
36+
def incorporatePoints(alg, pointLayerName=u'points', networkLayerName=u'input'):
37+
"""
38+
incorporate points with lines to form a GRASS network
39+
"""
40+
paramsToDelete = []
41+
42+
# Create an intermediate GRASS layer which is the combination of network + centers
43+
intLayer = alg.getTempFilename()
44+
45+
# Grab the point layer and delete this parameter (not used by v.net.alloc)
46+
pointLayer = alg.getParameterValue(pointLayerName)
47+
if pointLayer:
48+
pointLayer = alg.exportedLayers[pointLayer]
49+
paramsToDelete.append(alg.getParameterFromName(u'points'))
50+
51+
# Grab the network layer and tell to v.net.alloc to use the temp layer instead
52+
lineLayer = alg.getParameterValue(networkLayerName)
53+
if lineLayer:
54+
lineLayer = alg.exportedLayers[lineLayer]
55+
alg.setParameterValue(networkLayerName, intLayer)
56+
57+
threshold = alg.getParameterValue(u'threshold')
58+
paramsToDelete.append(alg.getParameterFromName(u'threshold'))
59+
60+
# Create the v.net connect command for point layer integration
61+
command = u"v.net -s input={} points={} out={} op=connect threshold={}".format(
62+
lineLayer, pointLayer, intLayer, threshold)
63+
alg.commands.append(command)
64+
65+
# Connect the point layer database to the layer 2 of the network
66+
command = u"v.db.connect -o map={} table={} layer=2".format(intLayer, pointLayer)
67+
alg.commands.append(command)
68+
69+
# Delete some unnecessary parameters
70+
for param in paramsToDelete:
71+
alg.parameters.remove(param)
72+
73+
alg.processCommand()
74+
75+
# Bring back the parameters:
76+
for param in paramsToDelete:
77+
alg.parameters.append(param)
78+
79+
80+
def variableOutput(alg, params, nocats=True):
81+
""" Handle variable data output for v.net modules:
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
86+
}
87+
88+
"""
89+
90+
# Build the v.out.ogr commands
91+
for outputName, typeList in params.iteritems():
92+
if not isinstance(typeList, list):
93+
continue
94+
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],
100+
alg.exportedLayers[out],
101+
os.path.dirname(out),
102+
os.path.basename(out)[:-4]
103+
)
104+
alg.commands.append(command)
105+
alg.outputCommands.append(command)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
v_net_alloc.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+
29+
from v_net import incorporatePoints, variableOutput
30+
31+
32+
def processCommand(alg):
33+
incorporatePoints(alg)
34+
35+
36+
def processOutputs(alg):
37+
outputParameter = {u"output": [u"line", 1]}
38+
variableOutput(alg, outputParameter, False)

0 commit comments

Comments
 (0)