Skip to content

Commit 903a804

Browse files
author
Médéric RIBREUX
committedMar 12, 2016
Add v.lrs.segment algorithm
1 parent 1ebd768 commit 903a804

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed
 
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
v.lrs.segment
2+
Creates points/segments from input lines, linear reference system and positions read from stdin or a file.
3+
Vector (v.*)
4+
ParameterVector|input|Input vector map containing lines|1|False
5+
ParameterTable|rstable|Name of the reference system table|False
6+
ParameterString|in_file|Inline rules for segment|None|True|True
7+
ParameterFile|file|Name of file containing segment rules|False|True
8+
OutputVector|output|Segments
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
v_lrs_segment.py
6+
----------------
7+
Date : March 2016
8+
Copyright : (C) 2016 by Médéric Ribreux
9+
Email : medspx at medspx dot fr
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Médéric Ribreux'
21+
__date__ = 'March 2016'
22+
__copyright__ = '(C) 2016, Médéric Ribreux'
23+
24+
# This will get replaced with a git SHA1 when you do a git archive
25+
26+
__revision__ = '$Format:%H$'
27+
28+
29+
def checkParameterValuesBeforeExecuting(alg):
30+
""" Verify if we have the right parameters """
31+
if alg.getParameterValue('in_file') and alg.getParameterValue(u'file'):
32+
return alg.tr("You need to set either a segment rules file or write directly the rules!")
33+
34+
return None
35+
36+
37+
def processInputs(alg):
38+
# We need to import the rstable
39+
rstable = alg.getParameterValue('rstable')
40+
if rstable in alg.exportedLayers.keys():
41+
return
42+
alg.exportedLayers[rstable] = alg.getTempFilename()
43+
command = 'db.in.ogr input=\"{}\" output={} --overwrite'.format(
44+
rstable,
45+
alg.exportedLayers[rstable]
46+
)
47+
alg.commands.append(command)
48+
alg.processInputs()
49+
50+
51+
def processCommand(alg):
52+
in_file = alg.getParameterValue('in_file')
53+
if in_file:
54+
# Creates a temporary txt file
55+
ruleFile = alg.getTempFilename()
56+
57+
# Inject rules into temporary txt file
58+
with open(ruleFile, "w") as tempRules:
59+
tempRules.write(in_file)
60+
else:
61+
ruleFile = alg.getParameterValue('file')
62+
63+
output = alg.getOutputFromName(u'output')
64+
alg.exportedLayers[output.value] = output.name + alg.uniqueSufix
65+
66+
command = 'v.lrs.segment input={} file={} rstable={} output={} --overwrite'.format(
67+
alg.exportedLayers[alg.getParameterValue('input')],
68+
ruleFile,
69+
alg.exportedLayers[alg.getParameterValue('rstable')],
70+
alg.exportedLayers[output.value]
71+
)
72+
alg.commands.append(command)

0 commit comments

Comments
 (0)
Please sign in to comment.