Path: blob/main/tools/import/visum/visum_parseZaehlstelle.py
169679 views
#!/usr/bin/env python1# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2# Copyright (C) 2008-2025 German Aerospace Center (DLR) and others.3# This program and the accompanying materials are made available under the4# terms of the Eclipse Public License 2.0 which is available at5# https://www.eclipse.org/legal/epl-2.0/6# This Source Code may also be made available under the following Secondary7# Licenses when the conditions for such availability set forth in the Eclipse8# Public License 2.0 are satisfied: GNU General Public License, version 29# or later which is available at10# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later1213# @file visum_parseZaehlstelle.py14# @author Daniel Krajzewicz15# @author Michael Behrisch16# @date 2008-11-301718"""1920This script reads "Zaehlstellen" from a given VISUM-network21and projects them onto a given SUMO-network.22The parsed "Zaehlstellen" are written as POIs.23"""24from __future__ import absolute_import25from __future__ import print_function2627import sys28import os29sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))30import sumolib # noqa3132# MAIN33if __name__ == '__main__':34op = sumolib.options.ArgumentParser()35op.add_option("sumoNet", category="input", type=op.file,36help="provide the SUMO net file including the path")37op.add_option("vissumNet", category="input", type=op.file,38help="provide the vissum net file including the path")39op.add_option("output", category="output", type=op.file,40help="provide the output file name including the path")41args = op.parse_args()4243print("Reading net...")44net = sumolib.net.readNet(args.sumoNet)4546print("Reading VISUM...")47fd = open(args.vissumNet)48fdo = open(args.output, "w")49fdo.write("<pois>\n")50parsingCounts = False51lastKnown = ""52for line in fd:53if parsingCounts:54if line[0] == '*' or line[0] == '$' or line.find(";") < 0:55parsingCounts = False56continue5758print(line)59vals = line.split(";")60id = vals[0] + ";" + vals[1]61fromNode = vals[3]62toNode = vals[4]63strID = vals[5]64rest = ";".join(vals[lastKnown + 1:]).strip()65fN = net.getID(fromNode)66me = None67for e in fN._outgoing:68if e._id == strID or e._id == "-" + strID:69me = e70if me is None:71print("Not found " + line)72else:73p = me._length * float(vals[6])74fdo.write(' <poi id="%s" type="%s" lane="%s_0" pos="%s" color="0,1,0" values="%s" layer="1"/>\n' %75(id, vals[7], me._id, p, rest))7677if line.find("$ZAEHLSTELLE") == 0:78parsingCounts = True79lastKnown = line.split(";").index("ISTINAUSWAHL")80fdo.write("</pois>\n")818283