Skip to content

Instantly share code, notes, and snippets.

@hrpunio
Last active December 16, 2015 11:39
Show Gist options
  • Save hrpunio/5429346 to your computer and use it in GitHub Desktop.
Save hrpunio/5429346 to your computer and use it in GitHub Desktop.
Add sped to subtitle file created with gpsbabel
#!/usr/bin/perl
#
use Geo::Distance;
my $geo = new Geo::Distance;
my $trkpt = 0;
while(<>) {
if (/Lat=/ && /Lon=/) {##
$_ =~ m/([0-9]+:[0-9]+:[0-9]+)[ \t]*Lat=([0-9\.]+)[ \t]*Lon=([0-9\.]+)/;
$time = $1 ; $lat = $2; $lon = $3;
($h, $m, $s) = split /:/, $time;
$time_second_from_midnight = $h * 60 * 60 + $m * 60 + $s ;
unless ($trkpt < 1) {##
$dist = $geo->distance( "meter", $plon, $plat => $lon, $lat );
$total_dist += $dist ;
$time_diff = $time_second_from_midnight - $time_second_from_midnight_p;
### Dla odcinków 2s i mniej nie liczmy bo wychodzą dziwne rzeczy
if ($time_diff < 3) { $Speed[$trkpt - 1] = -99 }
else { $Speed[$trkpt - 1] = ($dist / $time_diff) * 60 * 60 / 1000 ;
}
}
chomp();
$Line[$trkpt] .= $_;
$trkpt++; $plat=$lat; $plon=$lon;
$time_second_from_midnight_p = $time_second_from_midnight;
} else {
$Line[$trkpt] .= $_;
}
}
for ($i=0; $i<=$trkpt; $i++) {
if ( length($Line[$i]) > 9 ) {
if ($Speed[$i] < 0) {
printf "%s (speed: ??.? km/h)\n", $Line[$i];
}
else {
printf "%s (speed: %3.1f km/h)\n", $Line[$i], $Speed[$i];
}
}
}
###print "Total Dist: $total_dist\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment