Skip to content
Permalink
Browse files

Non variable output version. Adds:

* v.net.arcs for v.net 'arcs' operation.
* v.net.articulation for v.net.brdige 'articulation' method.
* v.net.connect for v.net 'connect' operation.
* v.net.nodes for v.net 'nodes' operation.
* v.net.nreport for v.net 'nreport' operation.
* v.net.report for v.net 'report operation.
* Some code simplification.
  • Loading branch information
Médéric RIBREUX
Médéric RIBREUX committed Jan 9, 2016
1 parent 14a6115 commit 85b87d5d5c9bb944c4499bd26d009d89674062fb
Showing with 218 additions and 125 deletions.
  1. +7 −0 python/plugins/processing/algs/grass7/description/v.net.arcs.txt
  2. +8 −0 python/plugins/processing/algs/grass7/description/v.net.articulation.txt
  3. +3 −3 python/plugins/processing/algs/grass7/description/v.net.bridge.txt
  4. +9 −0 python/plugins/processing/algs/grass7/description/v.net.connect.txt
  5. +7 −0 python/plugins/processing/algs/grass7/description/v.net.nodes.txt
  6. +7 −0 python/plugins/processing/algs/grass7/description/v.net.nreport.txt
  7. +7 −0 python/plugins/processing/algs/grass7/description/v.net.report.txt
  8. +0 −11 python/plugins/processing/algs/grass7/description/v.net.txt
  9. +14 −100 python/plugins/processing/algs/grass7/ext/v_net.py
  10. +7 −1 python/plugins/processing/algs/grass7/ext/v_net_alloc.py
  11. +1 −0 python/plugins/processing/algs/grass7/ext/v_net_allpairs.py
  12. +33 −0 python/plugins/processing/algs/grass7/ext/v_net_arcs.py
  13. +33 −0 python/plugins/processing/algs/grass7/ext/v_net_articulation.py
  14. +1 −1 python/plugins/processing/algs/grass7/ext/v_net_bridge.py
  15. +3 −3 python/plugins/processing/algs/grass7/ext/v_net_components.py
  16. +39 −0 python/plugins/processing/algs/grass7/ext/v_net_connect.py
  17. +1 −1 python/plugins/processing/algs/grass7/ext/v_net_connectivity.py
  18. +1 −1 python/plugins/processing/algs/grass7/ext/v_net_distance.py
  19. +3 −3 python/plugins/processing/algs/grass7/ext/v_net_flow.py
  20. +33 −0 python/plugins/processing/algs/grass7/ext/v_net_nodes.py
  21. +1 −1 python/plugins/processing/algs/grass7/ext/v_net_visibility.py
@@ -0,0 +1,7 @@
v.net
v.net.arcs - Creates arcs from a file of points
Vector (v.*)
ParameterVector|points|Input vector point layer (nodes)|0|False
ParameterFile|file|Name of input arcs file|False|False
Hardcoded|operation=arcs
OutputVector|output|Arcs
@@ -0,0 +1,8 @@
v.net.bridge
v.net.articulation - Computes articulation points in the network
Vector (v.*)
ParameterVector|input|Input vector line layer (network)|1|False
Hardcoded|method=articulation
*ParameterTableField|arc_column|Arc forward/both direction(s) cost column (name)|input|0|True
*ParameterTableField|arc_backward_column|Arc backward direction cost column (name)|input|0|True
OutputVector|output|Articulation
@@ -1,8 +1,8 @@
v.net.bridge
Computes bridges and articulation points in the network.
Computes bridges in the network.
Vector (v.*)
ParameterVector|input|Input vector line layer (network)|1|False
ParameterSelection|method|Operation to be performed|bridge;articulation|0|False
Hardcoded|method=bridge
*ParameterTableField|arc_column|Arc forward/both direction(s) cost column (name)|input|0|True
*ParameterTableField|arc_backward_column|Arc backward direction cost column (name)|input|0|True
OutputVector|output|Bridge_Or_Articulation
OutputVector|output|Bridge
@@ -0,0 +1,9 @@
v.net
v.net.connect - Connects points to nearest arcs in a network
Vector (v.*)
ParameterVector|input|Input vector line layer (arcs)|1|False
ParameterVector|points|Input vector point layer (nodes)|0|False
Hardcoded|operation=connect
ParameterNumber|threshold|Threshold for connection distance|None|None|50.0
*ParameterBoolean|-s|Snap points to network|False
OutputVector|output|Network
@@ -0,0 +1,7 @@
v.net
v.net.nodes - Creates points for each network arcs
Vector (v.*)
ParameterVector|input|Input vector line layer (arcs)|1|False
Hardcoded|operation=nodes
*ParameterBoolean|-c|Assign unique categories to new points (for operation 'nodes')|False
OutputVector|output|Nodes
@@ -0,0 +1,7 @@
v.net
v.net.nreport - Reports nodes information of a network
Vector (v.*)
ParameterVector|input|Input vector line layer (arcs)|1|False
Hardcoded|operation=nreport
OutputFile|output|NReport

@@ -0,0 +1,7 @@
v.net
v.net.report - Reports lines information of a network
Vector (v.*)
ParameterVector|input|Input vector line layer (arcs)|1|False
Hardcoded|operation=report
OutputFile|output|Report

This file was deleted.

@@ -17,12 +17,8 @@
***************************************************************************
This Python module handles pre-treatment operations for v.net.* GRASS7 modules.
Before using v.net you often have to incorporate a points layer into the network
vector map.
You also have different output depending on some parameters.
This file also contains dedicated ext functions for v.net module...
Before using a v.net module you often have to incorporate a points layer into
the network vector map.
"""

__author__ = 'Médéric Ribreux'
@@ -83,109 +79,27 @@ def incorporatePoints(alg, pointLayerName=u'points', networkLayerName=u'input'):

def variableOutput(alg, params, nocats=True):
""" Handle variable data output for v.net modules:
parameters:
{ u"output": { u"param" : { 0: u"line", 1: u"point" } }, # parametized output
u"output3: u"line" # use this type for this output
params is like:
{ u"output": [u"point", 1], # One output of type point from layer 1
u"output2": [u"line", 1], # One output of type line from layer 1
u"output3: [u"point", 2] # one output of type point from layer 2
}
"""

# Build the v.out.ogr commands
for outName in params.keys():
param = params[outName]
# There is a dict parameter:
if isinstance(param, dict):
paramName = param.keys()[0]
paramValue = alg.getParameterValue(paramName)
paramDict = param[paramName]
geomType = paramDict[paramValue]
elif isinstance(param, unicode):
geomType = param
else:
for outputName, typeList in params.iteritems():
if not isinstance(typeList, list):
continue

out = alg.getOutputValue(outName)
command = u"v.out.ogr {} type={} -s -e input={} output=\"{}\" format=ESRI_Shapefile output_layer={}".format(
u"" if geomType == u"line" and nocats else u"-c",
geomType,
out = alg.getOutputValue(outputName)
command = u"v.out.ogr {} type={} layer={} -s -e input={} output=\"{}\" format=ESRI_Shapefile output_layer={}".format(
u"" if typeList[0] == u"line" and nocats else u"-c",
typeList[0],
typeList[1],
alg.exportedLayers[out],
os.path.dirname(out),
os.path.basename(out)[:-4]
)
alg.commands.append(command)
alg.outputCommands.append(command)


# v.net dedicated functions
def checkParameterValuesBeforeExecuting(alg):
""" Verify if we have the right parameters """
operation = alg.getParameterValue(u'operation')
pointLayer = alg.getParameterValue(u'points')
threshold = alg.getParameterValue(u'threshold')
fileName = alg.getParameterValue(u'file')
if operation == 1:
if not (pointLayer and threshold):
return alg.tr("You need to set an input points layer and a threshold for operation 'connect' !")
elif operation == 2:
if not (fileName and pointLayer):
return alg.tr("You need to set an input points layer and a file for operation 'arcs' !")

return None


def processCommand(alg):
""" Handle data preparation for v.net:
* Integrate point layers into network vector map.
* Make v.net.distance use those layers.
* Delete the threshold parameter.
"""
paramsToDelete = []

# If we use the node operation, no need for threshold,
operation = alg.getParameterValue(u'operation')
if operation == 0:
paramsToDelete.append(alg.getParameterFromName(u'threshold'))
paramsToDelete.append(alg.getParameterFromName(u'file'))
elif operation == 2:
paramsToDelete.append(alg.getParameterFromName(u'threshold'))
elif operation in [3, 4]:
paramsToDelete.append(alg.getParameterFromName(u'threshold'))
paramsToDelete.append(alg.getParameterFromName(u'points'))
paramsToDelete.append(alg.getParameterFromName(u'file'))

# Grab the network layer and tell to v.net.alloc to use the temp layer instead
lineLayer = alg.getParameterValue(u'input')
if lineLayer:
lineLayer = alg.exportedLayers[lineLayer]

# Delete some unnecessary parameters
for param in paramsToDelete:
alg.parameters.remove(param)

alg.processCommand()

# Bring back the parameters:
for param in paramsToDelete:
alg.parameters.append(param)


def processOutputs(alg):
""" Handle data output for v.net:
* use v.out.ogr with type=line on node operation.
* use v.out.ogr with type=point on articulation method.
"""

# Find the method used
operation = alg.getParameterValue(u'operation')

# Grab the name of the output
out = alg.getOutputValue(u'output')

# Build the v.out.ogr command
command = u"v.out.ogr -c type={} layer={} -e input={} output=\"{}\" format=ESRI_Shapefile output_layer={}".format(
u"point" if operation == 0 else "line",
u"2" if operation == 0 else u"1",
alg.exportedLayers[out],
os.path.dirname(out),
os.path.basename(out)[:-4]
)
alg.commands.append(command)
@@ -25,8 +25,14 @@

__revision__ = '$Format:%H$'

from v_net import incorporatePoints

from v_net import incorporatePoints, variableOutput


def processCommand(alg):
incorporatePoints(alg)


def processOutputs(alg):
outputParameter = {u"output": [u"line", 1]}
variableOutput(alg, outputParameter, False)
@@ -25,6 +25,7 @@

__revision__ = '$Format:%H$'


from v_net import incorporatePoints


@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
v_net_arcs.py
---------------------
Date : December 2015
Copyright : (C) 2015 by Médéric Ribreux
Email : medspx at medspx dot fr
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""

__author__ = 'Médéric Ribreux'
__date__ = 'December 2015'
__copyright__ = '(C) 2015, Médéric Ribreux'

# This will get replaced with a git SHA1 when you do a git archive

__revision__ = '$Format:%H$'

from v_net import variableOutput


def processOutputs(alg):
outputParameter = {u"output": [u"line", 1]}
variableOutput(alg, outputParameter)
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
v_net_articulation.py
---------------------
Date : December 2015
Copyright : (C) 2015 by Médéric Ribreux
Email : medspx at medspx dot fr
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""

__author__ = 'Médéric Ribreux'
__date__ = 'December 2015'
__copyright__ = '(C) 2015, Médéric Ribreux'

# This will get replaced with a git SHA1 when you do a git archive

__revision__ = '$Format:%H$'

from v_net import variableOutput


def processOutputs(alg):
outputParameter = {u"output": [u"point", 1]}
variableOutput(alg, outputParameter)
@@ -29,5 +29,5 @@


def processOutputs(alg):
outputParameter = {u"output": {u"method": {0: u"line", 1: u"point"}}}
outputParameter = {u"output": [u"line", 1]}
variableOutput(alg, outputParameter)
@@ -30,8 +30,8 @@

def processCommand(alg):
# remove the output for point
outPoint = alg.getOutputFromName(u'output_point')
outLine = alg.getOutputFromName(u'output')
outPoint = alg.getOutputFromName(u'output_point')
alg.exportedLayers[outPoint.value] = outLine.name + alg.uniqueSufix
alg.removeOutputFromName(u'output_point')

@@ -42,6 +42,6 @@ def processCommand(alg):


def processOutputs(alg):
outputParameter = {u"output": u"line",
u"output_point": u"point"}
outputParameter = {u"output": [u"line", 1],
u"output_point": [u"point", 2]}
variableOutput(alg, outputParameter)
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
v_net_connect.py
---------------------
Date : December 2015
Copyright : (C) 2015 by Médéric Ribreux
Email : medspx at medspx dot fr
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""

__author__ = 'Médéric Ribreux'
__date__ = 'December 2015'
__copyright__ = '(C) 2015, Médéric Ribreux'

# This will get replaced with a git SHA1 when you do a git archive

__revision__ = '$Format:%H$'

import os


def processOutputs(alg):
out = alg.getOutputValue(u"output")
command = u"v.out.ogr -c type=line layer=1 -e input={} output=\"{}\" format=ESRI_Shapefile output_layer={}".format(
alg.exportedLayers[out],
os.path.dirname(out),
os.path.basename(out)[:-4]
)
alg.commands.append(command)
alg.outputCommands.append(command)
@@ -47,5 +47,5 @@ def processCommand(alg):


def processOutputs(alg):
outputParameter = {u"output": u"point"}
outputParameter = {u"output": [u"point", 2]}
variableOutput(alg, outputParameter)
@@ -26,7 +26,7 @@
__revision__ = '$Format:%H$'


from processing.core.parameters import getParameterFromString, ParameterVector, ParameterNumber, ParameterBoolean, ParameterString
from processing.core.parameters import getParameterFromString


def processCommand(alg):

0 comments on commit 85b87d5

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