Skip to content
Permalink
Browse files

Merge pull request #9046 from alexbruy/grass-v-net

fix GRASS v.net modules (fix #19904) [processing]
  • Loading branch information
alexbruy committed Feb 1, 2019
2 parents f66d199 + 85e3b2d commit ecd306e0797a69da9573f6c5bcef7944462d9ff3
Showing with 1,055 additions and 22 deletions.
  1. +4 −6 python/plugins/processing/algs/grass7/Grass7Algorithm.py
  2. +1 −1 python/plugins/processing/algs/grass7/description/v.net.nreport.txt
  3. +1 −1 python/plugins/processing/algs/grass7/description/v.net.report.txt
  4. +1 −1 python/plugins/processing/algs/grass7/description/v.net.salesman.txt
  5. +3 −3 python/plugins/processing/algs/grass7/ext/v_net.py
  6. +3 −3 python/plugins/processing/algs/grass7/ext/v_net_connectivity.py
  7. +4 −4 python/plugins/processing/algs/grass7/ext/v_net_distance.py
  8. +3 −3 python/plugins/processing/algs/grass7/ext/v_net_flow.py
  9. +19 −0 python/plugins/processing/tests/testdata/custom/grass7/point_end.gml
  10. +23 −0 python/plugins/processing/tests/testdata/custom/grass7/point_end.xsd
  11. +19 −0 python/plugins/processing/tests/testdata/custom/grass7/point_start.gml
  12. +23 −0 python/plugins/processing/tests/testdata/custom/grass7/point_start.xsd
  13. BIN python/plugins/processing/tests/testdata/expected/grass7/v_net_distance.dbf
  14. +1 −0 python/plugins/processing/tests/testdata/expected/grass7/v_net_distance.prj
  15. BIN python/plugins/processing/tests/testdata/expected/grass7/v_net_distance.shp
  16. BIN python/plugins/processing/tests/testdata/expected/grass7/v_net_distance.shx
  17. +824 −0 python/plugins/processing/tests/testdata/expected/grass7/v_net_nodes.gml
  18. +30 −0 python/plugins/processing/tests/testdata/expected/grass7/v_net_nodes.xsd
  19. 0 python/plugins/processing/tests/testdata/expected/grass7/v_net_nreport.html
  20. +27 −0 python/plugins/processing/tests/testdata/expected/grass7/v_net_report.html
  21. +4 −0 python/plugins/processing/tests/testdata/expected/grass7/v_net_salesman_seq.csv
  22. +65 −0 python/plugins/processing/tests/testdata/grass7_algorithms_vector_tests.yaml
@@ -631,15 +631,13 @@ def processCommand(self, parameters, context, feedback, delOutputs=False):
if outName in parameters and parameters[outName] is not None:
# for HTML reports, we need to redirect stdout
if out.defaultFileExtension().lower() == 'html':
command += ' > "{}"'.format(
self.parameterAsFileOutput(
parameters, outName, context)
)
command += ' {}=- > "{}"'.format(
outName,
self.parameterAsFileOutput(parameters, outName, context))
else:
command += ' {}="{}"'.format(
outName,
self.parameterAsFileOutput(
parameters, outName, context))
self.parameterAsFileOutput(parameters, outName, context))
# For folders destination
elif isinstance(out, QgsProcessingParameterFolderDestination):
# We need to add a unique temporary basename
@@ -3,4 +3,4 @@ v.net.nreport - Reports nodes information of a network
Vector (v.*)
QgsProcessingParameterFeatureSource|input|Input vector line layer (arcs)|1|None|False
Hardcoded|operation=nreport
QgsProcessingParameterFileDestination|html|NReport|Html files (*.html)|None|False
QgsProcessingParameterFileDestination|output|NReport|Html files (*.html)|None|False
@@ -3,4 +3,4 @@ v.net.report - Reports lines information of a network
Vector (v.*)
QgsProcessingParameterFeatureSource|input|Input vector line layer (arcs)|1|None|False
Hardcoded|operation=report
QgsProcessingParameterFileDestination|html|Report|Html files (*.html)|None|False
QgsProcessingParameterFileDestination|output|Report|Html files (*.html)|None|False
@@ -10,5 +10,5 @@ QgsProcessingParameterNumber|threshold|Threshold for connecting centers to the n
*QgsProcessingParameterField|arc_backward_column|Arc backward direction cost column (number)|None|input|0|False|True
*QgsProcessingParameterBoolean|-g|Use geodesic calculation for longitude-latitude locations|False|True
QgsProcessingParameterVectorDestination|output|Network_Salesman
QgsProcessingParameterFileDestination|sequence|Output file holding node sequence|Html files (*.html)|report.html|True
QgsProcessingParameterFileDestination|sequence|Output file holding node sequence|CSV files (*.csv)|None|True

@@ -58,12 +58,12 @@ def incorporatePoints(alg, parameters, context, feedback, pointLayerName='points
threshold = alg.parameterAsDouble(parameters, 'threshold', context)

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

# Connect the point layer database to the layer 2 of the network
command = u"v.db.connect -o map={} table={} layer=2".format(intLayer, pointLayer)
command = 'v.db.connect -o map={} table={} layer=2'.format(intLayer, pointLayer)
alg.commands.append(command)

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


@@ -30,22 +30,22 @@

def checkParameterValuesBeforeExecuting(alg, parameters, context):
""" Verify if we have the right parameters """
params = [u'where', u'cats']
params = ['where', 'cats']
values = []
for param in params:
for i in range(1, 3):
values.append(
alg.parameterAsString(
parameters,
u'set{}_{}'.format(i, param),
'set{}_{}'.format(i, param),
context
)
)

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

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


def processCommand(alg, parameters, context, feedback):
@@ -48,20 +48,20 @@ def processCommand(alg, parameters, context, feedback):
threshold = alg.parameterAsDouble(parameters, 'threshold', context)

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

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

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

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

# remove undesired parameters
@@ -31,10 +31,10 @@

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

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


def processCommand(alg, parameters, context, feedback):
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ogr.maptools.org/ end_point.xsd"
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>1003696.648020304</gml:X><gml:Y>6222370.049363472</gml:Y></gml:coord>
<gml:coord><gml:X>1003696.648020304</gml:X><gml:Y>6222370.049363472</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:point_end fid="point_end.0">
<ogr:geometryProperty><gml:Point srsName="EPSG:32733"><gml:coordinates>1003696.6480203,6222370.04936347</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:point_end>
</gml:featureMember>
</ogr:FeatureCollection>
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
<xs:complexType name="FeatureCollectionType">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureCollectionType">
<xs:attribute name="lockId" type="xs:string" use="optional"/>
<xs:attribute name="scope" type="xs:string" use="optional"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="point_end" type="ogr:point_end_Type" substitutionGroup="gml:_Feature"/>
<xs:complexType name="point_end_Type">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureType">
<xs:sequence>
<xs:element name="geometryProperty" type="gml:PointPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ogr.maptools.org/ start_point.xsd"
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>1000993.609479388</gml:X><gml:Y>6220361.983185438</gml:Y></gml:coord>
<gml:coord><gml:X>1000993.609479388</gml:X><gml:Y>6220361.983185438</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:point_start fid="point_start.0">
<ogr:geometryProperty><gml:Point srsName="EPSG:32733"><gml:coordinates>1000993.60947939,6220361.98318544</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:point_start>
</gml:featureMember>
</ogr:FeatureCollection>
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
<xs:complexType name="FeatureCollectionType">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureCollectionType">
<xs:attribute name="lockId" type="xs:string" use="optional"/>
<xs:attribute name="scope" type="xs:string" use="optional"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="point_start" type="ogr:point_start_Type" substitutionGroup="gml:_Feature"/>
<xs:complexType name="point_start_Type">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureType">
<xs:sequence>
<xs:element name="geometryProperty" type="gml:PointPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
Binary file not shown.
@@ -0,0 +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.

0 comments on commit ecd306e

Please sign in to comment.
You can’t perform that action at this time.