Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/shapes/poi_at_stops.py
194024 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 poi_at_stops.py
15
# @author Jakob Erdmann
16
# @date 2018-08-31
17
18
"""
19
Generates a PoI-file containing a PoI for each bus stop in the given net.
20
"""
21
from __future__ import absolute_import
22
from __future__ import print_function
23
24
import os
25
import sys
26
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
27
import sumolib.net # noqa
28
from sumolib.xml import parse # noqa
29
30
31
if len(sys.argv) < 3:
32
print("Usage: " + os.path.basename(__file__) + " <NET> <STOPS>", file=sys.stderr)
33
sys.exit()
34
35
print("Reading net...")
36
try:
37
net = sumolib.net.readNet(sys.argv[1])
38
except IOError as e:
39
print(e, file=sys.stderr)
40
sys.exit()
41
stops = sys.argv[2]
42
43
44
print("Writing output...")
45
with open('pois.add.xml', 'w') as f:
46
f.write('<?xml version="1.0"?>\n')
47
f.write('<additional>\n')
48
for stop in parse(stops, 'busStop'):
49
lane = net.getLane(stop.lane)
50
pos = (float(stop.startPos) + float(stop.endPos)) / 2
51
xypos = sumolib.geomhelper.positionAtShapeOffset(lane.getShape(), pos)
52
lon, lat = net.convertXY2LonLat(xypos[0], xypos[1])
53
f.write(' <poi id="%s" type="%s" color="1,0,0" layer="100" lon="%s" lat="%s"/>\n' % (
54
stop.id, stop.name, lon, lat))
55
f.write('</additional>\n')
56
57