/usr/share/sumo/tools/districts2poly.py is in sumo-tools 0.28.0+dfsg1-1.
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 | #!/usr/bin/env python
"""
@file districts2poly.py
@author Jakob Erdmann
@date 2015-07-31
@version $Id: districts2poly.py 20433 2016-04-13 08:00:14Z behrisch $
From a sumo network and a taz (district) file, this script colors each district
with a unique color (by creating a colored polygon for each edge in that
district)
These polygons can then be visualized in sumo-gui
SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
Copyright (C) 2012-2016 DLR (http://www.dlr.de/) and contributors
This file is part of SUMO.
SUMO is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
"""
from __future__ import absolute_import
import sys
import os
import itertools
import random
from optparse import OptionParser
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from sumolib.output import parse
from sumolib.net import readNet
from sumolib.miscutils import Colorgen
def parse_args():
USAGE = "Usage: " + sys.argv[0] + " <netfile> <routefile> [options]"
optParser = OptionParser()
optParser.add_option("-o", "--outfile", help="name of output file")
optParser.add_option("-u", "--hue", default="random",
help="hue for polygons (float from [0,1] or 'random')")
optParser.add_option("-s", "--saturation", default=1,
help="saturation for polygons (float from [0,1] or 'random')")
optParser.add_option("-b", "--brightness", default=1,
help="brightness for polygons (float from [0,1] or 'random')")
optParser.add_option(
"-l", "--layer", default=100, help="layer for generated polygons")
options, args = optParser.parse_args()
try:
options.net, options.routefile = args
options.colorgen = Colorgen(
(options.hue, options.saturation, options.brightness))
except:
sys.exit(USAGE)
if options.outfile is None:
options.outfile = options.routefile + ".poly.xml"
return options
def generate_poly(net, id, color, layer, edges, outf):
for edge in edges:
shape = net.getEdge(edge).getLane(0).getShape()
shapeString = ' '.join('%s,%s' % (x, y) for x, y in shape)
outf.write('<poly id="%s_%s" color="%s" layer="%s" type="taz_edge" shape="%s"/>\n' % (
id, net.getEdge(edge).getID(), color, layer, shapeString))
def main():
random.seed(42)
options = parse_args()
net = readNet(options.net)
with open(options.outfile, 'w') as outf:
outf.write('<polygons>\n')
for taz in parse(options.routefile, 'taz'):
generate_poly(net, taz.id, options.colorgen(),
options.layer, taz.edges.split(), outf)
outf.write('</polygons>\n')
if __name__ == "__main__":
main()
|