Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 committed Jan 9, 2016
1 parent 14a6115 commit 85b87d5
Show file tree
Hide file tree
Showing 21 changed files with 218 additions and 125 deletions.
@@ -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

11 changes: 0 additions & 11 deletions python/plugins/processing/algs/grass7/description/v.net.txt

This file was deleted.

114 changes: 14 additions & 100 deletions python/plugins/processing/algs/grass7/ext/v_net.py
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
8 changes: 7 additions & 1 deletion python/plugins/processing/algs/grass7/ext/v_net_alloc.py
Expand Up @@ -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)
Expand Up @@ -25,6 +25,7 @@

__revision__ = '$Format:%H$'


from v_net import incorporatePoints


Expand Down
33 changes: 33 additions & 0 deletions python/plugins/processing/algs/grass7/ext/v_net_arcs.py
@@ -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)
33 changes: 33 additions & 0 deletions python/plugins/processing/algs/grass7/ext/v_net_articulation.py
@@ -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)
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/grass7/ext/v_net_bridge.py
Expand Up @@ -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)
6 changes: 3 additions & 3 deletions python/plugins/processing/algs/grass7/ext/v_net_components.py
Expand Up @@ -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')

Expand All @@ -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)
39 changes: 39 additions & 0 deletions python/plugins/processing/algs/grass7/ext/v_net_connect.py
@@ -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)
Expand Up @@ -47,5 +47,5 @@ def processCommand(alg):


def processOutputs(alg):
outputParameter = {u"output": u"point"}
outputParameter = {u"output": [u"point", 2]}
variableOutput(alg, outputParameter)
Expand Up @@ -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):
Expand Down

0 comments on commit 85b87d5

Please sign in to comment.