Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/purgatory/pois2inductionLoops.py
169674 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2010-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 pois2inductionLoops.py
15
# @author Daniel Krajzewicz
16
# @author Michael Behrisch
17
# @date 2010-02-18
18
19
"""
20
21
Converts a given pois located on lanes into induction loop detectors;
22
Each poi is replicated to cover all lanes of the road.
23
The detectors are named <POINAME>__l<LANE_INDEX>
24
25
Call: pois2inductionLoops.py <NET> <POIS> <OUTPUT>
26
"""
27
from __future__ import absolute_import
28
from __future__ import print_function
29
30
31
import os
32
import sys
33
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
34
import sumolib # noqa
35
36
37
if len(sys.argv) < 4:
38
print("Usage: " + sys.argv[0] + " <NET> <POIS> <OUTPUT>")
39
sys.exit()
40
41
print("Reading net...")
42
net = sumolib.net.readNet(sys.argv[1])
43
44
print("Reading PoIs...")
45
pois = sumolib.poi.readPois(sys.argv[2])
46
47
fdo = open(sys.argv[3], "w")
48
print('<additional>', file=fdo)
49
for poi in pois:
50
if not poi._lane:
51
print("Error: poi '%s' is not on a lane" % poi._id)
52
continue
53
edge = poi._lane[:poi._lane.rfind('_')]
54
edge = net._id2edge[edge]
55
for i, l in enumerate(edge._lanes):
56
print(' <e1Detector id="%s__l%s" lane="%s" pos="%s" freq="60" file="e1_output.xml"/>' % (
57
poi._id, i, l.getID(), poi._pos), file=fdo)
58
print('', file=fdo)
59
print('</additional>', file=fdo)
60
fdo.close()
61
62