Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/devel/debug2shapes.py
169673 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2010-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 debug2shapes.py
15
# @author Jakob Erdmann
16
# @date 2016-02-20
17
18
19
"""build polygon/poi file from cmdline geometry input as generated by sumo debug output
20
"""
21
from __future__ import print_function
22
import sys
23
import os
24
from collections import defaultdict
25
26
COLORS = ["red", "green", "blue", "yellow", "cyan", "magenta", "orange"]
27
28
outfile = sys.argv[1]
29
if os.path.isfile(sys.argv[2]):
30
shapesParts = open(sys.argv[2]).read().split()
31
else:
32
shapesParts = sys.argv[2].split()
33
if len(sys.argv) == 4:
34
fill = bool(sys.argv[3])
35
else:
36
fill = False
37
38
shapes = []
39
shape = []
40
ids = defaultdict(lambda: 0)
41
id = ""
42
for p in shapesParts:
43
if "=" in p:
44
if shape:
45
shapes.append((id, shape))
46
shape = []
47
id, pos = p.split("=")
48
ids[id] += 1
49
if ids[id] > 1:
50
id += "_%s" % ids[id]
51
shape.append(pos)
52
else:
53
if ',' in p:
54
shape.append(p)
55
56
if shape:
57
shapes.append((id, shape))
58
59
60
with open(outfile, 'w') as outf:
61
numPoly = 0
62
numPoi = 0
63
if shapes:
64
outf.write("<shapes>\n")
65
for i, (id, shape) in enumerate(shapes):
66
if len(shape) > 1:
67
outf.write(' <poly id="%s" shape="%s" color="%s" fill="%s" layer="100" lineWidth="0.1"/>\n' % (
68
id, " ".join(shape), COLORS[i % len(COLORS)], fill))
69
numPoly += 1
70
else:
71
xyz = shape[0].split(',')
72
if len(xyz) >= 2:
73
x = xyz[0]
74
y = xyz[1]
75
outf.write(' <poi id="%s" x="%s" y="%s" color="%s"/>\n' % (
76
id, x, y, COLORS[i % len(COLORS)]))
77
numPoi += 1
78
outf.write("</shapes>\n")
79
print("wrote %s polygons and %s POIs to '%s'" % (numPoly, numPoi, outfile))
80
81