Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/net/net2sel.py
169673 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2007-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 net2sel.py
15
# @author Jakob Erdmann
16
# @date 2025-07-16
17
18
"""
19
This script converts the network to a selection file of junctions and edges
20
"""
21
from __future__ import absolute_import
22
from __future__ import print_function
23
import os
24
import sys
25
26
if 'SUMO_HOME' in os.environ:
27
sys.path.append(os.path.join(os.environ['SUMO_HOME'], 'tools'))
28
import sumolib # noqa
29
30
31
def parse_args():
32
USAGE = "Usage: " + sys.argv[0] + " -n <net> <options>"
33
argParser = sumolib.options.ArgumentParser(usage=USAGE)
34
argParser.add_argument("-n", "--net-file", dest="netFile", required=True,
35
category="input", type=argParser.net_file, help="The .net.xml file to convert")
36
argParser.add_argument("-o", "--output-file", dest="outFile", category="output",
37
type=argParser.file, help="The polygon output file name")
38
argParser.add_argument("-l", "--lanes", action="store_true", default=False,
39
category="processing", help="Write lanes to selection instead of edges")
40
return argParser.parse_args()
41
42
43
if __name__ == "__main__":
44
options = parse_args()
45
net = sumolib.net.readNet(options.netFile)
46
47
with open(options.outFile, 'w') as outf:
48
for junction in net.getNodes():
49
outf.write("junction:%s\n" % junction.getID())
50
for edge in net.getEdges():
51
if options.lanes:
52
for lane in edge.getLanes():
53
outf.write("lane:%s\n" % lane.getID())
54
else:
55
outf.write("edge:%s\n" % edge.getID())
56
57