/usr/share/sumo/tools/net/patchNetFiles.py is in sumo-tools 0.15.0~dfsg-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | #!/usr/bin/env python
"""
@file patchNetFiles.py
@author Daniel Krajzewicz
@author Michael Behrisch
@date 2008-08-13
@version $Id: patchNetFiles.py 11671 2012-01-07 20:14:30Z behrisch $
Reads in a file where junctions controlled by
tls are stored and one which contains correct
lane numbers. Applies the information on
the given edge and node file and saves them.
todo:
- make this read XML-files using an XML-API
SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
Copyright (C) 2008-2012 DLR (http://www.dlr.de/) and contributors
All rights reserved
"""
import os, sys
from optparse import OptionParser
def getAttr(source, what):
mbeg = source.find(what + "=")
mbeg = source.find('"', mbeg) + 1
mend = source.find('"', mbeg)
return source[mbeg:mend]
optParser = OptionParser()
optParser.add_option("-v", "--verbose", action="store_true", dest="verbose",
default=False, help="tell me what you are doing")
optParser.add_option("-t", "--tls-file", dest="lsas",
help="File with tls nodes", metavar="FILE")
optParser.add_option("-l", "--lanes-file", dest="lanes",
help="File with lane number patched", metavar="FILE")
optParser.add_option("-e", "--edges-file", dest="edges",
help="File with XML-edges", metavar="FILE")
optParser.add_option("-n", "--nodes-file", dest="nodes",
help="File with XML-nodes", metavar="FILE")
(options, args) = optParser.parse_args()
# read in lsa definitions
lsas = {}
if options.lsas:
index = 0
fd = open(options.lsas)
for line in fd:
line = line.strip();
if line=="" or line[0]=='#':
continue
(id, tls) = line.split(":")
tls = tls.split(",")
if id=="tls":
if len(tls)>1:
id = "j_" + str(index)
index = index + 1
else:
id = tls[0]
for t in tls:
if t in lsas:
print "Junction's '" + t + "' TLS already defined"
lsas[t] = id
fd.close()
# read in lane number patches
lanes = {}
if options.lanes:
fd = open(options.lanes)
for line in fd:
line = line.strip();
if line=="" or line[0]=='#':
continue
(edge, laneNo) = line.split(":")
if edge in lanes:
print "Edge's '" + edge + "' lane number already defined"
lanes[edge] = int(laneNo)
fd.close()
# patch
# edges
fdi = open(options.edges)
fdo = open(options.edges + ".new.xml", "w")
for line in fdi:
if line.find("<edge ")>=0:
id = getAttr(line, "id")
if id in lanes:
indexB = line.find("nolanes")
indexB = line.find('"', indexB)+1
indexE = line.find('"', indexB)
line = line[:indexB] + str(lanes[id]) + line[indexE:]
fdo.write(line)
fdo.close()
fdi.close()
# nodes
fdi = open(options.nodes)
fdo = open(options.nodes + ".new.xml", "w")
for line in fdi:
if line.find("<node ")>=0:
id = getAttr(line, "id")
if id in lsas:
indexE = line.find("/>")
line = line[:indexE] + " type=\"traffic_light\" tl=\"" + lsas[id] + "\"/>";
fdo.write(line)
fdo.close()
fdi.close()
|