Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/net/net2poly.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 net2poly.py
15
# @author Michael Behrisch
16
# @author Jakob Erdmann
17
# @date 2022-03-06
18
19
"""
20
This script converts the edge geometries of a sumo network to an additional file with polygons
21
"""
22
from __future__ import absolute_import
23
from __future__ import print_function
24
import os
25
import sys
26
27
if 'SUMO_HOME' in os.environ:
28
sys.path.append(os.path.join(os.environ['SUMO_HOME'], 'tools'))
29
import sumolib # noqa
30
31
32
def parse_args():
33
USAGE = "Usage: " + sys.argv[0] + " -n <net> <options>"
34
argParser = sumolib.options.ArgumentParser(usage=USAGE)
35
argParser.add_argument("-n", "--net-file", dest="netFile", required=True,
36
category="input", type=argParser.net_file, help="The .net.xml file to convert")
37
argParser.add_argument("-o", "--output-file", dest="outFile", category="output",
38
type=argParser.file, help="The polygon output file name")
39
argParser.add_argument("-l", "--lanes", action="store_true", default=False,
40
category="processing", help="Export lane geometries instead of edge geometries")
41
argParser.add_argument("-i", "--internal", action="store_true", default=False,
42
category="processing", help="Export internal geometries")
43
argParser.add_argument("--layer", default="10", category="processing", type=str, help="Layer for normal edges")
44
argParser.add_argument("--color", default="red", category="processing", type=str, help="Color for normal edges")
45
argParser.add_argument("--internal-color", dest="iColor", default="orange",
46
category="processing", type=str, help="Color for internal edges")
47
return argParser.parse_args()
48
49
50
if __name__ == "__main__":
51
options = parse_args()
52
net = sumolib.net.readNet(options.netFile, withInternal=options.internal)
53
geomType = 'lane' if options.lanes else 'edge'
54
55
with open(options.outFile, 'w') as outf:
56
sumolib.xml.writeHeader(outf, root="additional")
57
for id, geometry, width in net.getGeometries(options.lanes):
58
color = options.iColor if id[0] == ":" else options.color
59
shape = ["%.6f,%.6f" % net.convertXY2LonLat(x, y) for x, y in geometry]
60
outf.write(' <poly id="%s" color="%s" layer="%s" lineWidth="%s" shape="%s" geo="1"/>\n' %
61
(id, color, options.layer, width, " ".join(shape)))
62
outf.write('</additional>\n')
63
64