OpenStreetMap

convert osm offline viewer lg2 file to gpx

Posted by hungerburg on 3 December 2018 in English (English)

Below script converts tracks in lg2 format of Marek Baranowski's withdrawn IOS app to gpx

#!/usr/bin/perl
use POSIX qw(strftime);

my $name = shift or die "Usage: $0 filename\n";

open (FH, "<$name") or die 'No such file';
binmode(FH);

my $buf;
my $mul = 3600000;
my $fmt = "vVVvV";

print '<?xml version="1.0" encoding="UTF-8"?>
<gpx version="1.0">
    <time>'.strftime("%FT%X", localtime).'</time>
    <trk>
        <name>'.(split(/\./,$name))[0].'</name>
        <trkseg>';

while (my $got = read (FH, $buf, 16)) {
    my ($H, $B, $L, $X, $T) = unpack $fmt, $buf;
    print '
            <trkpt lat="'.$B/$mul.'" lon="'.$L/$mul.'"><ele>'.$H.'</ele><time>'.strftime("%FT%X", $T, 1, 1, 1, 0, 70).'</time></trkpt>' if $T > 100000;
}

print'
        </trkseg>
    </trk>
</gpx>
'

Login to leave a comment