36
36
import os
37
37
from processing .core .parameters import getParameterFromString , ParameterVector , ParameterNumber , ParameterBoolean , ParameterString
38
38
39
+
39
40
def incorporatePoints (alg , pointLayerName = u'points' , networkLayerName = u'input' ):
40
41
"""
41
42
incorporate points with lines to form a GRASS network
42
43
"""
43
44
paramsToDelete = []
44
-
45
+
45
46
# Create an intermediate GRASS layer which is the combination of network + centers
46
47
intLayer = alg .getTempFilename ()
47
48
@@ -62,23 +63,24 @@ def incorporatePoints(alg, pointLayerName=u'points', networkLayerName=u'input'):
62
63
63
64
# Create the v.net connect command for point layer integration
64
65
command = u"v.net -s input={} points={} out={} op=connect threshold={}" .format (
65
- lineLayer , pointLayer , intLayer , threshold )
66
+ lineLayer , pointLayer , intLayer , threshold )
66
67
alg .commands .append (command )
67
68
68
69
# Connect the point layer database to the layer 2 of the network
69
70
command = u"v.db.connect -o map={} table={} layer=2" .format (intLayer , pointLayer )
70
71
alg .commands .append (command )
71
-
72
+
72
73
# Delete some unnecessary parameters
73
74
for param in paramsToDelete :
74
75
alg .parameters .remove (param )
75
-
76
+
76
77
alg .processCommand ()
77
78
78
79
# Bring back the parameters:
79
80
for param in paramsToDelete :
80
81
alg .parameters .append (param )
81
82
83
+
82
84
def variableOutput (alg , params , nocats = True ):
83
85
""" Handle variable data output for v.net modules:
84
86
parameters:
@@ -106,9 +108,9 @@ def variableOutput(alg, params, nocats=True):
106
108
u"" if geomType == u"line" and nocats else u"-c" ,
107
109
geomType ,
108
110
alg .exportedLayers [out ],
109
- os .path .dirname ( out ),
110
- os .path .basename ( out )[:- 4 ]
111
- )
111
+ os .path .dirname (out ),
112
+ os .path .basename (out )[:- 4 ]
113
+ )
112
114
alg .commands .append (command )
113
115
alg .outputCommands .append (command )
114
116
@@ -129,6 +131,7 @@ def checkParameterValuesBeforeExecuting(alg):
129
131
130
132
return None
131
133
134
+
132
135
def processCommand (alg ):
133
136
""" Handle data preparation for v.net:
134
137
* Integrate point layers into network vector map.
@@ -144,7 +147,7 @@ def processCommand(alg):
144
147
paramsToDelete .append (alg .getParameterFromName (u'file' ))
145
148
elif operation == 2 :
146
149
paramsToDelete .append (alg .getParameterFromName (u'threshold' ))
147
- elif operation in [3 ,4 ]:
150
+ elif operation in [3 , 4 ]:
148
151
paramsToDelete .append (alg .getParameterFromName (u'threshold' ))
149
152
paramsToDelete .append (alg .getParameterFromName (u'points' ))
150
153
paramsToDelete .append (alg .getParameterFromName (u'file' ))
@@ -159,7 +162,7 @@ def processCommand(alg):
159
162
alg .parameters .remove (param )
160
163
161
164
alg .processCommand ()
162
-
165
+
163
166
# Bring back the parameters:
164
167
for param in paramsToDelete :
165
168
alg .parameters .append (param )
@@ -170,7 +173,7 @@ def processOutputs(alg):
170
173
* use v.out.ogr with type=line on node operation.
171
174
* use v.out.ogr with type=point on articulation method.
172
175
"""
173
-
176
+
174
177
# Find the method used
175
178
operation = alg .getParameterValue (u'operation' )
176
179
@@ -182,7 +185,7 @@ def processOutputs(alg):
182
185
u"point" if operation == 0 else "line" ,
183
186
u"2" if operation == 0 else u"1" ,
184
187
alg .exportedLayers [out ],
185
- os .path .dirname ( out ),
186
- os .path .basename ( out )[:- 4 ]
187
- )
188
+ os .path .dirname (out ),
189
+ os .path .basename (out )[:- 4 ]
190
+ )
188
191
alg .commands .append (command )
0 commit comments