Geo-TCX
view release on metacpan or search on metacpan
lib/Geo/TCX/Interactive.pm view on Meta::CPAN
}
}
croak "There are no folders to choose from in the current working directory" unless( @folders );
print "please select which folder to use (#): ";
my $folder = <STDIN>;
$folder = $folders[$folder-1];
return $o->set_wd( $wd . $folder )
}
=over 4
=item save_laps( %options )
is identical to C<< save_laps() >> in L<Geo::TCX> but will prompt the user to confirm the intention to save the laps before continuing. It expects the same I<%options> and returns the same value, except that it returns false if the user does not answ...
=back
=cut
sub save_laps {
my $o = shift;
print "Do you want to save the laps as individual files: ";
my $answer = _prompt_yes_no();
if ($answer =~ m/^y|ye|yes$/i) {
my $ret_val = $o->SUPER::save_laps(@_);
return $ret_val
}
return 0
}
=over 4
=item gpx_load( $file )
Loads a Gpx file into the TCX object. If a directory is specified instead of a file, prompts for a choice among the gpx files found in that directory.
Return a reference to the C<Geo::Gpx> object loaded.
=back
=cut
sub gpx_load {
my ($o, $file_or_dir) = (shift, shift);
$file_or_dir =~ s/~/$ENV{'HOME'}/ if $file_or_dir =~ /^~/;
my $fname;
if (-d $file_or_dir ) {
my $dir = $file_or_dir;
$dir =~ s,/*$,/,;
$fname = _select_file_from_dir( $dir, '.gpx' )
} elsif (-f $file_or_dir ) {
$fname = $file_or_dir;
my ($name,$path,$ext) = fileparse($fname,'\..*');
croak 'Gpx file must have a *.gpx extension' unless $ext eq '.gpx'
} else { croak 'first argument must be a filename or directory' };
return $o->{gpx} = Geo::Gpx->new( input => $fname );
}
=over 4
=item way_add_endpoints( tolerance_meters => # )
Compare the end points of each lap with all waypoints read in the L<Geo::Gpx> instance (by C<< gpx_load() >> and, if the distance is less than C<tolerance_meters>, prompts whether the waypoint should be added to it.
In the affirmative, prompts what name and description should be given to the new waypoint. Set C<tolerance_meters> to 0 to compare all start/end points of laps with waypoints, or to another desired value.
The default C<tolerance_meters> is 10. Returns true.
=back
=cut
sub way_add_endpoints {
my ($o, %opts) = @_;
$opts{tolerance_meters} = 10 unless defined $opts{tolerance_meters}; # could be zero
my $gpx = $o->gpx;
for my $i (1 .. $o->laps) {
my $pass = 0;
while ($pass++ < 2 ) {
my ($order, $index);
$order = ($pass == 1) ? 'first' : 'last';
$index = ($pass == 1) ? 1 : -1;
my $end_pt = $o->lap($i)->trackpoint( $index );
my $has_latitude = $end_pt->LatitudeDegrees;
my ($closest_wpt, $distance);
($closest_wpt, $distance) = $gpx->waypoint_closest_to( $end_pt ) if $has_latitude;
if ($distance > $opts{tolerance_meters} ) {
print "\n$order point of lap $i is ", sprintf('%.1f', $distance), " meters from Waypoint \'";
print $closest_wpt->name, "\'\n --> do you want to add that point ? ";
print "$order point of lap $i info:\n";
$end_pt->summ;
print $end_pt->LatitudeDegrees . " " . $end_pt->LongitudeDegrees;
print "\n\n";
print $closest_wpt->name, " info:\n";
$closest_wpt->summ;
print $closest_wpt->lat . " " . $closest_wpt->lon;
print "\n\n";
my $answer = _prompt_yes_no();
if ( $answer eq 'y' ) {
my $gpx_pt = $end_pt->to_gpx();
my ($name, $desc, $cmt) = _prompt_for_waypoint_fields(qw/ name desc cmt /);
$gpx_pt->desc( $desc ) if $desc;
$gpx_pt->cmt( $cmt ) if $cmt;
while ( ! $name ) {
print "Waypoint name is required\n";
$name = _prompt_for_waypoint_fields('name');
}
$gpx_pt->name( $name );
$gpx->waypoints_add($gpx_pt)
} else { next }
}
}
}
return 1
}
=over 4
=item way_add_device( $directory_on_device )
Prompts the user whether they wish to look for waypoints saved on a GPS device and compare them to the waypoints read in the C<Geo::TCX> instance by C<< gpx_load() >>. The device must be currently plugged in with a USB cable.
In the affirmative, compares each waypoint from the device to those in the instance and, if the distance is greater than 1 meter, prompts whether the waypoint should be added to the waypoints in the object.
If no directory is provided, tries to guess where that directory might be (provided the device is plugged in). Returns false if the directory or waypoints file cannot be found (does not die) or if the user responds no at the initial prompt. Otherwise...
( run in 1.365 second using v1.01-cache-2.11-cpan-39bf76dae61 )