Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/net/generateStationEdges.py
169673 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2012-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 generateStationEdges.py
15
# @author Jakob Erdmann
16
# @date 2018-08-07
17
18
"""
19
Generate pedestrian edges for every public transport stop to serve as access
20
edge in otherwise pure railway networks
21
"""
22
from __future__ import absolute_import
23
from __future__ import print_function
24
import sys
25
import os
26
27
if 'SUMO_HOME' in os.environ:
28
sys.path.append(os.path.join(os.environ['SUMO_HOME'], 'tools'))
29
import sumolib # noqa
30
from sumolib.options import ArgumentParser # noqa
31
32
33
def parse_args():
34
USAGE = "%(prog)s -n <netfile> -s <stopfile> -o <utput> [options]"
35
ap = ArgumentParser(usage=USAGE)
36
ap.add_option("-n", "--net-file", category="input", dest="netfile", required=True, type=ap.net_file,
37
help="input network file")
38
ap.add_option("-s", "--stop-file", category="input", dest="stopfile", required=True, type=ap.additional_file,
39
help="input network file")
40
ap.add_option("-o", "--output-prefix", category="output", dest="outfile", required=True, type=ap.file,
41
help="prefix of output files")
42
ap.add_option("-l", "--length", type=float, default=10.,
43
help="length of generated solitary edges")
44
ap.add_option("-w", "--width", type=float, default=8.,
45
help="width of generated solitary edges")
46
# optParser.add_option("-d", "--cluster-dist", type=float, default=500., help="length of generated edges")
47
options = ap.parse_args()
48
return options
49
50
51
def main(options):
52
net = sumolib.net.readNet(options.netfile, withConnections=False, withFoes=False)
53
l2 = options.length / 2
54
with open(options.outfile + ".edg.xml", 'w') as out_e:
55
with open(options.outfile + ".nod.xml", 'w') as out_n:
56
sumolib.writeXMLHeader(out_e, "$Id$") # noqa
57
sumolib.writeXMLHeader(out_n, "$Id$") # noqa
58
out_e.write('<edges>\n')
59
out_n.write('<nodes>\n')
60
for stop in sumolib.xml.parse(options.stopfile, ['busStop', 'trainStop'], heterogeneous=True):
61
edge_id = stop.id + "_access"
62
x, y = sumolib.geomhelper.positionAtShapeOffset(
63
net.getLane(stop.lane).getShape(),
64
(float(stop.startPos) + float(stop.endPos)) / 2)
65
from_id = edge_id + '_from'
66
to_id = edge_id + '_to'
67
out_n.write(' <node id="%s" x="%s" y="%s"/>\n' % (from_id, x - l2, y))
68
out_n.write(' <node id="%s" x="%s" y="%s"/>\n' % (to_id, x + l2, y))
69
out_e.write(' <edge id="%s" from="%s" to="%s" allow="pedestrian" width="%s"/>\n' % (
70
edge_id, from_id, to_id, options.width))
71
out_e.write('</edges>\n')
72
out_n.write('</nodes>\n')
73
74
75
if __name__ == "__main__":
76
options = parse_args()
77
main(options)
78
79