sumolib.output.convert.gpx
This module includes functions for converting SUMO's fcd-output into GPX format (http://en.wikipedia.org/wiki/GPS_eXchange_Format)
1# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 2# Copyright (C) 2014-2026 German Aerospace Center (DLR) and others. 3# This program and the accompanying materials are made available under the 4# terms of the Eclipse Public License 2.0 which is available at 5# https://www.eclipse.org/legal/epl-2.0/ 6# This Source Code may also be made available under the following Secondary 7# Licenses when the conditions for such availability set forth in the Eclipse 8# Public License 2.0 are satisfied: GNU General Public License, version 2 9# or later which is available at 10# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html 11# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later 12 13# @file gpx.py 14# @author Jakob Erdmann 15# @author Laura Bieker 16# @date 2014-02-13 17 18""" 19This module includes functions for converting SUMO's fcd-output into 20GPX format (http://en.wikipedia.org/wiki/GPS_eXchange_Format) 21""" 22from __future__ import absolute_import 23from collections import defaultdict 24 25 26def fcd2gpx(inpFCD, outSTRM, ignored): 27 tracks = defaultdict(list) 28 for timestep in inpFCD: 29 for v in timestep.vehicle: 30 tracks[v.id].append((timestep.time, v.x, v.y)) 31 32 outSTRM.write('<?xml version="1.0" encoding="UTF-8"?>\n') 33 outSTRM.write('<gpx version="1.0">\n') 34 for vehicle in sorted(tracks): 35 outSTRM.write(" <trk><name>%s</name><trkseg>\n" % vehicle) 36 for timestamp, lon, lat in tracks[vehicle]: 37 outSTRM.write(' <trkpt lon="%s" lat="%s"><time>%s</time></trkpt>\n' % ( 38 lon, lat, timestamp)) 39 outSTRM.write(" </trkseg></trk>\n") 40 outSTRM.write('</gpx>\n')
def
fcd2gpx(inpFCD, outSTRM, ignored):
27def fcd2gpx(inpFCD, outSTRM, ignored): 28 tracks = defaultdict(list) 29 for timestep in inpFCD: 30 for v in timestep.vehicle: 31 tracks[v.id].append((timestep.time, v.x, v.y)) 32 33 outSTRM.write('<?xml version="1.0" encoding="UTF-8"?>\n') 34 outSTRM.write('<gpx version="1.0">\n') 35 for vehicle in sorted(tracks): 36 outSTRM.write(" <trk><name>%s</name><trkseg>\n" % vehicle) 37 for timestamp, lon, lat in tracks[vehicle]: 38 outSTRM.write(' <trkpt lon="%s" lat="%s"><time>%s</time></trkpt>\n' % ( 39 lon, lat, timestamp)) 40 outSTRM.write(" </trkseg></trk>\n") 41 outSTRM.write('</gpx>\n')