Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/import/vissim/vissim2poly.py
169679 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2009-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 vissim2poly.py
15
# @author Jakob Erdmann
16
# @date 2020-01-30
17
18
"""
19
Parses a vissim .inpx file and exports link geometrys as <poly> elements
20
Usage: vissim2poly.py inpxFile outputFile
21
"""
22
import os
23
import sys
24
sys.path.append(os.path.join(os.environ['SUMO_HOME'], 'tools'))
25
import sumolib # noqa
26
27
# MAIN
28
if __name__ == '__main__':
29
op = sumolib.options.ArgumentParser()
30
op.add_option("vissimNet", category="input", type=op.file,
31
help="provide the vissim file path")
32
op.add_option("outputFile", category="output", type=op.file,
33
help="provide the output file path")
34
args = op.parse_args()
35
36
vissimfile = args.vissimNet
37
outfile = args.outputFile
38
with open(outfile, 'w') as outf:
39
outf.write('<add>\n')
40
for link in sumolib.xml.parse(vissimfile, 'link'):
41
if link.geometry is None or link.geometry[0].linkPolyPts is None:
42
print("no polypoints for link %s" % link.no)
43
points = [(p.x, p.y, p.z) for p in link.geometry[0].linkPolyPts[0].linkPolyPoint]
44
shape = ' '.join([','.join(filter(None, xyz)) for xyz in points])
45
outf.write(' <poly id="%s" shape="%s" color="blue"/>\n' % (
46
link.no, shape))
47
outf.write('</add>\n')
48
49