Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/devel/ptlines2vehs.py
193728 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2010-2026 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 ptlines2vehs.py
15
# @author Jakob Erdmann
16
# @date 2026-01-22
17
18
19
"""convert a ptLine into a vehicle that validate route/stop consistency
20
"""
21
import sys
22
import os
23
24
if 'SUMO_HOME' in os.environ:
25
sys.path.append(os.path.join(os.environ['SUMO_HOME'], 'tools'))
26
sys.path.append(os.path.join(os.environ['SUMO_HOME'], 'tools', 'import', 'gtfs'))
27
import sumolib
28
from sumolib.xml import parse
29
from sumolib.miscutils import openz
30
from gtfs2osm import OSM2SUMO_MODES
31
32
infile, outfile = sys.argv[1:]
33
with openz(outfile, 'w') as outf:
34
sumolib.writeXMLHeader(outf, "$Id$", "routes")
35
types = set()
36
for ptLine in parse(infile, 'ptLine'):
37
types.add(ptLine.type)
38
for t in types:
39
outf.write(' <vType id="%s" vClass="%s"/>\n' % (t, OSM2SUMO_MODES[t]))
40
41
for ptLine in parse(infile, 'ptLine'):
42
outf.write(' <vehicle id="%s" type="%s" depart="0">\n' % (ptLine.id, ptLine.type))
43
outf.write(ptLine.route[0].toXML(initialIndent=' ' * 8))
44
for stop in ptLine.busStop:
45
outf.write(' ' * 8 + '<stop busStop="%s" duration="1"/> <!-- %s -->\n' % (
46
stop.id, stop.attr_name))
47
outf.write(' </vehicle>\n')
48
outf.write('</routes>\n')
49
50