Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/shapes/CSV2polyconvertXML.py
193745 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2008-2026 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 CSV2polyconvertXML.py
15
# @author Daniel Krajzewicz
16
# @author Michael Behrisch
17
# @date 2008-07-17
18
19
"""
20
Converts a given CSV-file that contains a list of pois to
21
an XML-file that may be read by POLYCONVERT.
22
"""
23
from __future__ import absolute_import
24
from __future__ import print_function
25
26
import sys
27
28
if len(sys.argv) < 4:
29
print("Error: Missing argument(s)")
30
print(
31
"Call: CSV2polyconvertXML.py <CSV_FILE> <OUTPUT_FILE> <VALUENAME>[,<VALUENAME>]*")
32
print(" The values within the csv-file are supposed to be divided by ';'.")
33
print(
34
" <VALUENAME>s give the attribute names in order of their appearance within the csv-file .")
35
exit()
36
37
38
names = sys.argv[3].split(',')
39
inpf = open(sys.argv[1])
40
outf = open(sys.argv[2], "w")
41
outf.write("<pois>\n")
42
for line in inpf:
43
if len(line) == 0 or line[0] == '#':
44
continue
45
vals = line.strip().split(';')
46
outf.write(" <poi")
47
for i, n in enumerate(names):
48
outf.write(' ' + n + '="' + vals[i] + '"')
49
outf.write("/>\n")
50
outf.write("</pois>\n")
51
inpf.close()
52
outf.close()
53
54