Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/shapes/poi_atTLS.py
193884 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_atTLS.py
15
# @author Daniel Krajzewicz
16
# @author Michael Behrisch
17
# @date 2010-02-20
18
19
"""
20
Generates a PoI-file containing a PoI for each tls controlled intersection
21
from the given net.
22
"""
23
from __future__ import absolute_import
24
from __future__ import print_function
25
26
import os
27
import sys
28
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
29
import sumolib.net # noqa
30
31
32
if len(sys.argv) < 2:
33
print("Usage: " + sys.argv[0] + " <NET>", file=sys.stderr)
34
sys.exit()
35
36
print("Reading net...")
37
try:
38
net1 = sumolib.net.readNet(sys.argv[1], withPrograms=True)
39
except Exception as e:
40
print(e, file=sys.stderr)
41
sys.exit()
42
43
print("Writing output...")
44
fdo = open('pois.add.xml', 'w')
45
print('<?xml version="1.0"?>', file=fdo)
46
print('<!-- poi_atTLS %s -->' % sys.argv, file=fdo)
47
print('<additional>', file=fdo)
48
for tlsID in net1._id2tls:
49
tls = net1._id2tls[tlsID]
50
nodes = set()
51
for c in tls._connections:
52
iLane = c[0]
53
iEdge = iLane.getEdge()
54
nodes.add(iEdge._to)
55
if len(sys.argv) > 2 and sys.argv[2] != "nojoin":
56
c = [0, 0]
57
for n in nodes:
58
c[0] += n._coord[0]
59
c[1] += n._coord[1]
60
if len(nodes) > 1:
61
c[0] = c[0] / float(len(nodes))
62
c[1] = c[1] / float(len(nodes))
63
print(' <poi id="%s" type="default" color="1,0,0" layer="0" x="%s" y="%s"/>' % (
64
tlsID, c[0], c[1]), file=fdo)
65
else:
66
for n in nodes:
67
print(' <poi id="%s_at_%s" type="default" color="1,0,0" layer="0" x="%s" y="%s"/>' % (
68
tlsID, n._id, n._coord[0], n._coord[1]), file=fdo)
69
70
print('</additional>', file=fdo)
71
fdo.close()
72
73