TangoGPS/track conversion

From OpenStreetMap Wiki
Jump to: navigation, search

TangoGPS for OpenMoko can record tracklogs and display OSM maps.

Conversion from its CSV logfile format to GPX

#!/usr/bin/perl
#
# (c)2008 Marcus Bauer - License GPLv2
#
# Convert a tangoGPS logfile to GPX
# 
# usage:  ./convert2gpx.pl logfile*.log  > outfile.gpx
#

print <<EOT
<?xml version="1.0" encoding="UTF-8"?>
<gpx	version="1.0"
	creator="convert2gpx.pl http://www.tangogps.org"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://www.topografix.com/GPX/1/0"
	xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">

<trk>
<trkseg>

EOT
;

while(<>)
{

@arr = split(',',$_);
chop @arr[6];

print <<EOT
<trkpt lat="@arr[0]" lon="@arr[1]">
  <ele>@arr[2]</ele>
  <speed>@arr[3]</speed>
  <course>@arr[4]</course>
  <fix>3d</fix>
  <hdop>@arr[5]</hdop>
  <time>@arr[6]</time>
</trkpt>

EOT
;

}


print <<EOT

</trkseg>
</trk>
</gpx>

EOT
;

[OLD]Conversion from its CSV logfile format to GPX

#!/usr/bin/perl
print <<HEADER;
<?xml version="1.0"?>
<gpx
 version="1.0"
creator="Converted from tangogps log"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.topografix.com/GPX/1/0"
xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">
<trk>
  <name>ACTIVE LOG</name>
  <trkseg>
HEADER

open(IN, shift()) || die("Can't open file\n");

while($Line = <IN>)
{
  chomp $Line;
  
  ($Lat, $Lon, $A, $B, $C, $D, $Time) = split(/,/, $Line);
  # 52.143131,-0.481063,22.9,0.1,276.8,4.4,2008-08-03T12:36:42Z

  printf("<trkpt lat=\"%s\" lon=\"%s\">\n<time>%s</time>\n</trkpt>\n",
    $Lat,
    $Lon,
    $Time);
}

print <<FOOTER;
</trkseg>
</trk>
</gpx>
FOOTER