|
17 | 17 | ***************************************************************************
|
18 | 18 |
|
19 | 19 | 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. |
26 | 22 | """
|
27 | 23 |
|
28 | 24 | __author__ = 'Médéric Ribreux'
|
@@ -83,109 +79,27 @@ def incorporatePoints(alg, pointLayerName=u'points', networkLayerName=u'input'):
|
83 | 79 |
|
84 | 80 | def variableOutput(alg, params, nocats=True):
|
85 | 81 | """ 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 |
89 | 86 | }
|
| 87 | +
|
90 | 88 | """
|
91 | 89 |
|
92 | 90 | # 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): |
104 | 93 | continue
|
105 | 94 |
|
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], |
110 | 100 | alg.exportedLayers[out],
|
111 | 101 | os.path.dirname(out),
|
112 | 102 | os.path.basename(out)[:-4]
|
113 | 103 | )
|
114 | 104 | alg.commands.append(command)
|
115 | 105 | 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) |
0 commit comments