Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/import/visum/visum_parseZaehlstelle.py
169679 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2008-2025 German Aerospace Center (DLR) and others.
4
# This program and the accompanying materials are made available under the
5
# terms of the Eclipse Public License 2.0 which is available at
6
# https://www.eclipse.org/legal/epl-2.0/
7
# This Source Code may also be made available under the following Secondary
8
# Licenses when the conditions for such availability set forth in the Eclipse
9
# Public License 2.0 are satisfied: GNU General Public License, version 2
10
# or later which is available at
11
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
14
# @file visum_parseZaehlstelle.py
15
# @author Daniel Krajzewicz
16
# @author Michael Behrisch
17
# @date 2008-11-30
18
19
"""
20
21
This script reads "Zaehlstellen" from a given VISUM-network
22
and projects them onto a given SUMO-network.
23
The parsed "Zaehlstellen" are written as POIs.
24
"""
25
from __future__ import absolute_import
26
from __future__ import print_function
27
28
import sys
29
import os
30
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
31
import sumolib # noqa
32
33
# MAIN
34
if __name__ == '__main__':
35
op = sumolib.options.ArgumentParser()
36
op.add_option("sumoNet", category="input", type=op.file,
37
help="provide the SUMO net file including the path")
38
op.add_option("vissumNet", category="input", type=op.file,
39
help="provide the vissum net file including the path")
40
op.add_option("output", category="output", type=op.file,
41
help="provide the output file name including the path")
42
args = op.parse_args()
43
44
print("Reading net...")
45
net = sumolib.net.readNet(args.sumoNet)
46
47
print("Reading VISUM...")
48
fd = open(args.vissumNet)
49
fdo = open(args.output, "w")
50
fdo.write("<pois>\n")
51
parsingCounts = False
52
lastKnown = ""
53
for line in fd:
54
if parsingCounts:
55
if line[0] == '*' or line[0] == '$' or line.find(";") < 0:
56
parsingCounts = False
57
continue
58
59
print(line)
60
vals = line.split(";")
61
id = vals[0] + ";" + vals[1]
62
fromNode = vals[3]
63
toNode = vals[4]
64
strID = vals[5]
65
rest = ";".join(vals[lastKnown + 1:]).strip()
66
fN = net.getID(fromNode)
67
me = None
68
for e in fN._outgoing:
69
if e._id == strID or e._id == "-" + strID:
70
me = e
71
if me is None:
72
print("Not found " + line)
73
else:
74
p = me._length * float(vals[6])
75
fdo.write(' <poi id="%s" type="%s" lane="%s_0" pos="%s" color="0,1,0" values="%s" layer="1"/>\n' %
76
(id, vals[7], me._id, p, rest))
77
78
if line.find("$ZAEHLSTELLE") == 0:
79
parsingCounts = True
80
lastKnown = line.split(";").index("ISTINAUSWAHL")
81
fdo.write("</pois>\n")
82
83