Skip to content

Instantly share code, notes, and snippets.

@hrpunio
Created April 21, 2013 11:28
Show Gist options
  • Save hrpunio/5429300 to your computer and use it in GitHub Desktop.
Save hrpunio/5429300 to your computer and use it in GitHub Desktop.
Search for $TSlimit timestamps from GPX track
#!/usr/bin/perl
# Wyszukuje $TSlimit punktów na śladzie GPX najbliższych latitude:longitude
# Ślad jest podany jako argument polecenia
#
use Geo::Distance;
use Getopt::Long;
my $geo = new Geo::Distance;
my $TSlimit = 20;
print "*** USAGE: My_GPX_nearest_timestamp.pl -c latitude:longitude ; np. 54.43175:18.479859 for rondo Osowa";
print "*** =====\n";
GetOptions( 'c=s' => \$coords, );
unless (defined ($coords)) { exit; }
print "*** Looking for $TSlimit points near: $coords (lat/lon) ***\n";
($latB, $lonB) = split(/:/, $coords);
my $qchars = "\042\047"; # znaki cytowania pojedynczy i podwojny
my $skip_hdr="Y" ;
while (<>) {
if ( /<trk>/ ) { $skip_hdr = "N" }
elsif ( /<\/trk>/ ) { $skip_hdr = "Y" }
if ($skip_hdr eq "Y") { next ; }
if (/<trkpt\s+lat\s*=\s*([$qchars])([^$qchars]+)\1\s+lon\s*=\s*([$qchars])([^$qchars]+)\3/) {
$lat=$2; $lon=$4;
$dist = $geo->distance( "meter", $lonB, $latB => $lon, $lat );
$trkpt++;
}
elsif ( /<time>([^<>]+)<\/time>/ ) { $time = $1; }
elsif ( /<\/trkpt/ ) {
$TimeStamps{$time} = "$lat:$lon";
$Distances{$time} = $dist;
###print "*** [$read_on] $time => $dist => [$lat:$lon]\n";
}
}
foreach $t ( sort {$Distances {$a} <=> $Distances {$b}} keys(%Distances) ) {
$limit++;
print "> $Distances{$t} $t $TimeStamps{$t}\n";
if ($limit >= $TSlimit ) { exit }
}
###
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment