Skip to content

Commit ecd306e

Browse files
authoredFeb 1, 2019
Merge pull request #9046 from alexbruy/grass-v-net
fix GRASS v.net modules (fix #19904) [processing]
2 parents f66d199 + 85e3b2d commit ecd306e

22 files changed

+1055
-22
lines changed
 

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -631,15 +631,13 @@ def processCommand(self, parameters, context, feedback, delOutputs=False):
631631
if outName in parameters and parameters[outName] is not None:
632632
# for HTML reports, we need to redirect stdout
633633
if out.defaultFileExtension().lower() == 'html':
634-
command += ' > "{}"'.format(
635-
self.parameterAsFileOutput(
636-
parameters, outName, context)
637-
)
634+
command += ' {}=- > "{}"'.format(
635+
outName,
636+
self.parameterAsFileOutput(parameters, outName, context))
638637
else:
639638
command += ' {}="{}"'.format(
640639
outName,
641-
self.parameterAsFileOutput(
642-
parameters, outName, context))
640+
self.parameterAsFileOutput(parameters, outName, context))
643641
# For folders destination
644642
elif isinstance(out, QgsProcessingParameterFolderDestination):
645643
# We need to add a unique temporary basename

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ v.net.nreport - Reports nodes information of a network
33
Vector (v.*)
44
QgsProcessingParameterFeatureSource|input|Input vector line layer (arcs)|1|None|False
55
Hardcoded|operation=nreport
6-
QgsProcessingParameterFileDestination|html|NReport|Html files (*.html)|None|False
6+
QgsProcessingParameterFileDestination|output|NReport|Html files (*.html)|None|False

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ v.net.report - Reports lines information of a network
33
Vector (v.*)
44
QgsProcessingParameterFeatureSource|input|Input vector line layer (arcs)|1|None|False
55
Hardcoded|operation=report
6-
QgsProcessingParameterFileDestination|html|Report|Html files (*.html)|None|False
6+
QgsProcessingParameterFileDestination|output|Report|Html files (*.html)|None|False

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ QgsProcessingParameterNumber|threshold|Threshold for connecting centers to the n
1010
*QgsProcessingParameterField|arc_backward_column|Arc backward direction cost column (number)|None|input|0|False|True
1111
*QgsProcessingParameterBoolean|-g|Use geodesic calculation for longitude-latitude locations|False|True
1212
QgsProcessingParameterVectorDestination|output|Network_Salesman
13-
QgsProcessingParameterFileDestination|sequence|Output file holding node sequence|Html files (*.html)|report.html|True
13+
QgsProcessingParameterFileDestination|sequence|Output file holding node sequence|CSV files (*.csv)|None|True
1414

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ def incorporatePoints(alg, parameters, context, feedback, pointLayerName='points
5858
threshold = alg.parameterAsDouble(parameters, 'threshold', context)
5959

6060
# Create the v.net connect command for point layer integration
61-
command = u"v.net input={} points={} output={} operation=connect threshold={}".format(
61+
command = 'v.net -s input={} points={} output={} operation=connect threshold={}'.format(
6262
lineLayer, pointLayer, intLayer, threshold)
6363
alg.commands.append(command)
6464

6565
# 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)
66+
command = 'v.db.connect -o map={} table={} layer=2'.format(intLayer, pointLayer)
6767
alg.commands.append(command)
6868

6969
# remove undesired parameters
@@ -111,7 +111,7 @@ def variableOutput(alg, layers, parameters, context, nocats=True):
111111
alg.exportVectorLayer(grassName=grass_name,
112112
fileName=file_name,
113113
layer=output_layer_number,
114-
nocats=no_cats,
114+
exportnocat=no_cats,
115115
dataType=output_type)
116116

117117

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

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

3131
def checkParameterValuesBeforeExecuting(alg, parameters, context):
3232
""" Verify if we have the right parameters """
33-
params = [u'where', u'cats']
33+
params = ['where', 'cats']
3434
values = []
3535
for param in params:
3636
for i in range(1, 3):
3737
values.append(
3838
alg.parameterAsString(
3939
parameters,
40-
u'set{}_{}'.format(i, param),
40+
'set{}_{}'.format(i, param),
4141
context
4242
)
4343
)
4444

4545
if (values[0] or values[2]) and (values[1] or values[3]):
4646
return True, None
4747

48-
return False, alg.tr("You need to set at least setX_where or setX_cats parameters for each set!")
48+
return False, alg.tr('You need to set at least setX_where or setX_cats parameters for each set!')
4949

5050

5151
def processCommand(alg, parameters, context, feedback):

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,20 @@ def processCommand(alg, parameters, context, feedback):
4848
threshold = alg.parameterAsDouble(parameters, 'threshold', context)
4949

5050
# Create the v.net connect command for from_layer integration
51-
command = u"v.net input={} points={} output={} operation=connect threshold={} arc_layer=1 node_layer=2".format(
51+
command = 'v.net -s input={} points={} output={} operation=connect threshold={} arc_layer=1 node_layer=2'.format(
5252
lineLayer, fromLayer, intLayer, threshold)
5353
alg.commands.append(command)
5454

5555
# Do it again with to_layer
56-
command = u"v.net input={} points={} output={} operation=connect threshold={} arc_layer=1 node_layer=3".format(
56+
command = 'v.net -s input={} points={} output={} operation=connect threshold={} arc_layer=1 node_layer=3'.format(
5757
intLayer, toLayer, netLayer, threshold)
5858
alg.commands.append(command)
5959

6060
# Connect the point layer database to the layer 2 of the network
61-
command = u"v.db.connect -o map={} table={} layer=2".format(netLayer, fromLayer)
61+
command = 'v.db.connect -o map={} table={} layer=2'.format(netLayer, fromLayer)
6262
alg.commands.append(command)
6363

64-
command = u"v.db.connect -o map={} table={} layer=3".format(netLayer, toLayer)
64+
command = 'v.db.connect -o map={} table={} layer=3'.format(netLayer, toLayer)
6565
alg.commands.append(command)
6666

6767
# remove undesired parameters

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131

3232
def checkParameterValuesBeforeExecuting(alg, parameters, context):
3333
""" Verify if we have the right parameters """
34-
params = [u'where', u'cats']
34+
params = ['where', 'cats']
3535
values = []
3636
for param in params:
37-
for i in [u'source', u'sink']:
37+
for i in ['source', 'sink']:
3838
values.append(
3939
alg.parameterAsString(
4040
parameters,
@@ -46,7 +46,7 @@ def checkParameterValuesBeforeExecuting(alg, parameters, context):
4646
if (values[0] or values[2]) and (values[1] or values[3]):
4747
return True, None
4848

49-
return False, alg.tr("You need to set at least source/sink_where or source/sink_cats parameters for each set!")
49+
return False, alg.tr('You need to set at least source/sink_where or source/sink_cats parameters for each set!')
5050

5151

5252
def processCommand(alg, parameters, context, feedback):
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ogr:FeatureCollection
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://ogr.maptools.org/ end_point.xsd"
5+
xmlns:ogr="http://ogr.maptools.org/"
6+
xmlns:gml="http://www.opengis.net/gml">
7+
<gml:boundedBy>
8+
<gml:Box>
9+
<gml:coord><gml:X>1003696.648020304</gml:X><gml:Y>6222370.049363472</gml:Y></gml:coord>
10+
<gml:coord><gml:X>1003696.648020304</gml:X><gml:Y>6222370.049363472</gml:Y></gml:coord>
11+
</gml:Box>
12+
</gml:boundedBy>
13+
14+
<gml:featureMember>
15+
<ogr:point_end fid="point_end.0">
16+
<ogr:geometryProperty><gml:Point srsName="EPSG:32733"><gml:coordinates>1003696.6480203,6222370.04936347</gml:coordinates></gml:Point></ogr:geometryProperty>
17+
</ogr:point_end>
18+
</gml:featureMember>
19+
</ogr:FeatureCollection>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xs:schema targetNamespace="http://ogr.maptools.org/" xmlns:ogr="http://ogr.maptools.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml" elementFormDefault="qualified" version="1.0">
3+
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
4+
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
5+
<xs:complexType name="FeatureCollectionType">
6+
<xs:complexContent>
7+
<xs:extension base="gml:AbstractFeatureCollectionType">
8+
<xs:attribute name="lockId" type="xs:string" use="optional"/>
9+
<xs:attribute name="scope" type="xs:string" use="optional"/>
10+
</xs:extension>
11+
</xs:complexContent>
12+
</xs:complexType>
13+
<xs:element name="point_end" type="ogr:point_end_Type" substitutionGroup="gml:_Feature"/>
14+
<xs:complexType name="point_end_Type">
15+
<xs:complexContent>
16+
<xs:extension base="gml:AbstractFeatureType">
17+
<xs:sequence>
18+
<xs:element name="geometryProperty" type="gml:PointPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
19+
</xs:sequence>
20+
</xs:extension>
21+
</xs:complexContent>
22+
</xs:complexType>
23+
</xs:schema>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ogr:FeatureCollection
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://ogr.maptools.org/ start_point.xsd"
5+
xmlns:ogr="http://ogr.maptools.org/"
6+
xmlns:gml="http://www.opengis.net/gml">
7+
<gml:boundedBy>
8+
<gml:Box>
9+
<gml:coord><gml:X>1000993.609479388</gml:X><gml:Y>6220361.983185438</gml:Y></gml:coord>
10+
<gml:coord><gml:X>1000993.609479388</gml:X><gml:Y>6220361.983185438</gml:Y></gml:coord>
11+
</gml:Box>
12+
</gml:boundedBy>
13+
14+
<gml:featureMember>
15+
<ogr:point_start fid="point_start.0">
16+
<ogr:geometryProperty><gml:Point srsName="EPSG:32733"><gml:coordinates>1000993.60947939,6220361.98318544</gml:coordinates></gml:Point></ogr:geometryProperty>
17+
</ogr:point_start>
18+
</gml:featureMember>
19+
</ogr:FeatureCollection>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xs:schema targetNamespace="http://ogr.maptools.org/" xmlns:ogr="http://ogr.maptools.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml" elementFormDefault="qualified" version="1.0">
3+
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
4+
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
5+
<xs:complexType name="FeatureCollectionType">
6+
<xs:complexContent>
7+
<xs:extension base="gml:AbstractFeatureCollectionType">
8+
<xs:attribute name="lockId" type="xs:string" use="optional"/>
9+
<xs:attribute name="scope" type="xs:string" use="optional"/>
10+
</xs:extension>
11+
</xs:complexContent>
12+
</xs:complexType>
13+
<xs:element name="point_start" type="ogr:point_start_Type" substitutionGroup="gml:_Feature"/>
14+
<xs:complexType name="point_start_Type">
15+
<xs:complexContent>
16+
<xs:extension base="gml:AbstractFeatureType">
17+
<xs:sequence>
18+
<xs:element name="geometryProperty" type="gml:PointPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
19+
</xs:sequence>
20+
</xs:extension>
21+
</xs:complexContent>
22+
</xs:complexType>
23+
</xs:schema>
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PROJCS["WGS_1984_UTM_Zone_33S",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",15],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",10000000],UNIT["Meter",1]]
Binary file not shown.
Binary file not shown.

‎python/plugins/processing/tests/testdata/expected/grass7/v_net_nodes.gml

Lines changed: 824 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xs:schema targetNamespace="http://ogr.maptools.org/" xmlns:ogr="http://ogr.maptools.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml" elementFormDefault="qualified" version="1.0">
3+
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
4+
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
5+
<xs:complexType name="FeatureCollectionType">
6+
<xs:complexContent>
7+
<xs:extension base="gml:AbstractFeatureCollectionType">
8+
<xs:attribute name="lockId" type="xs:string" use="optional"/>
9+
<xs:attribute name="scope" type="xs:string" use="optional"/>
10+
</xs:extension>
11+
</xs:complexContent>
12+
</xs:complexType>
13+
<xs:element name="output92cc7e710c1a480889ca8e439845035b" type="ogr:output92cc7e710c1a480889ca8e439845035b_Type" substitutionGroup="gml:_Feature"/>
14+
<xs:complexType name="output92cc7e710c1a480889ca8e439845035b_Type">
15+
<xs:complexContent>
16+
<xs:extension base="gml:AbstractFeatureType">
17+
<xs:sequence>
18+
<xs:element name="geometryProperty" type="gml:PointPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
19+
<xs:element name="cat" nillable="true" minOccurs="0" maxOccurs="1">
20+
<xs:simpleType>
21+
<xs:restriction base="xs:integer">
22+
<xs:totalDigits value="16"/>
23+
</xs:restriction>
24+
</xs:simpleType>
25+
</xs:element>
26+
</xs:sequence>
27+
</xs:extension>
28+
</xs:complexContent>
29+
</xs:complexType>
30+
</xs:schema>

‎python/plugins/processing/tests/testdata/expected/grass7/v_net_nreport.html

Whitespace-only changes.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><p>1 -1 -1
2+
</br>2 -1 -1
3+
</br>3 -1 -1
4+
</br>4 -1 -1
5+
</br>5 -1 -1
6+
</br>6 -1 -1
7+
</br>7 -1 -1
8+
</br>8 -1 -1
9+
</br>9 -1 -1
10+
</br>10 -1 -1
11+
</br>11 -1 -1
12+
</br>12 -1 -1
13+
</br>13 -1 -1
14+
</br>14 -1 -1
15+
</br>15 -1 -1
16+
</br>16 -1 -1
17+
</br>17 -1 -1
18+
</br>18 -1 -1
19+
</br>19 -1 -1
20+
</br>20 -1 -1
21+
</br>21 -1 -1
22+
</br>22 -1 -1
23+
</br>23 -1 -1
24+
</br>24 -1 -1
25+
</br>25 -1 -1
26+
</br>26 -1 -1
27+
</br></p></body></html>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
sequence;category;cost_to_next
2+
1;1;0.000
3+
2;2;0.000
4+
3;3;0.000

‎python/plugins/processing/tests/testdata/grass7_algorithms_vector_tests.yaml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,33 @@ tests:
141141
name: expected/grass7/v_vect_stats.shp
142142
type: vector
143143

144+
- algorithm: grass7:v.net
145+
name: v.net (extract nodes)
146+
params:
147+
-c: false
148+
-s: true
149+
GRASS_MIN_AREA_PARAMETER: 0.0001
150+
GRASS_OUTPUT_TYPE_PARAMETER: 0
151+
GRASS_SNAP_TOLERANCE_PARAMETER: -1.0
152+
GRASS_VECTOR_DSCO: ''
153+
GRASS_VECTOR_EXPORT_NOCAT: false
154+
GRASS_VECTOR_LCO: ''
155+
arc_type:
156+
- 0
157+
- 1
158+
input:
159+
name: roads.gml|layername=roads
160+
type: vector
161+
operation: 0
162+
threshold: 50.0
163+
results:
164+
output:
165+
name: expected/grass7/v_net_nodes.gml
166+
type: vector
167+
compare:
168+
fields:
169+
fid: skip
170+
144171
- algorithm: grass7:v.net.allpairs
145172
name: v.net.allpairs
146173
params:
@@ -194,6 +221,41 @@ tests:
194221
name: expected/grass7/v_net_centrality.shp
195222
type: vector
196223

224+
- algorithm: grass7:v.net.distance
225+
name: v.net.distance
226+
params:
227+
-g: false
228+
-l: false
229+
GRASS_MIN_AREA_PARAMETER: 0.0001
230+
GRASS_OUTPUT_TYPE_PARAMETER: 0
231+
GRASS_SNAP_TOLERANCE_PARAMETER: -1.0
232+
GRASS_VECTOR_DSCO: ''
233+
GRASS_VECTOR_EXPORT_NOCAT: false
234+
GRASS_VECTOR_LCO: ''
235+
arc_type:
236+
- 0
237+
- 1
238+
flayer:
239+
name: custom/grass7/point_start.gml|layername=point_start
240+
type: vector
241+
from_cats: ''
242+
from_where: ''
243+
input:
244+
name: roads.gml|layername=roads
245+
type: vector
246+
threshold: 50.0
247+
tlayer:
248+
name: custom/grass7/point_end.gml|layername=point_end
249+
type: vector
250+
to_cats: ''
251+
to_type:
252+
- 0
253+
to_where: ''
254+
results:
255+
output:
256+
name: expected/grass7/v_net_distance.shp
257+
type: vector
258+
197259
- algorithm: grass7:v.net.salesman
198260
name: v.net.salesman
199261
params:
@@ -218,6 +280,9 @@ tests:
218280
output:
219281
name: expected/grass7/v_net_salesman.shp
220282
type: vector
283+
sequence:
284+
name: expected/grass7/v_net_salesman_seq.csv
285+
type: file
221286

222287
- algorithm: grass7:v.net.steiner
223288
name: v.net.steiner

0 commit comments

Comments
 (0)
Please sign in to comment.