"""
This script converts the network to a selection file of junctions and edges
"""
from __future__ import absolute_import
from __future__ import print_function
import os
import sys
if 'SUMO_HOME' in os.environ:
sys.path.append(os.path.join(os.environ['SUMO_HOME'], 'tools'))
import sumolib
def parse_args():
USAGE = "Usage: " + sys.argv[0] + " -n <net> <options>"
argParser = sumolib.options.ArgumentParser(usage=USAGE)
argParser.add_argument("-n", "--net-file", dest="netFile", required=True,
category="input", type=argParser.net_file, help="The .net.xml file to convert")
argParser.add_argument("-o", "--output-file", dest="outFile", category="output",
type=argParser.file, help="The polygon output file name")
argParser.add_argument("-l", "--lanes", action="store_true", default=False,
category="processing", help="Write lanes to selection instead of edges")
return argParser.parse_args()
if __name__ == "__main__":
options = parse_args()
net = sumolib.net.readNet(options.netFile)
with open(options.outFile, 'w') as outf:
for junction in net.getNodes():
outf.write("junction:%s\n" % junction.getID())
for edge in net.getEdges():
if options.lanes:
for lane in edge.getLanes():
outf.write("lane:%s\n" % lane.getID())
else:
outf.write("edge:%s\n" % edge.getID())