Geo-TCX
view release on metacpan or search on metacpan
lib/Geo/TCX/Interactive.pm view on Meta::CPAN
$answer =~ s, *$,,;
if ($answer =~ m/^y|ye|yes$/i) {
$gpx->waypoints_add( $pt )
} elsif ($answer =~ m/^n|no*$/i) {
next
} else {
$pt->name( $answer );
$gpx->waypoints_add( $pt )
}
}
}
return 1
}
=over 4
=item gpx_save( )
Save the gpx file. The same options as C<Geo::Gpx->save()> are expected but will prompt the user whether to overwrite an existing file if C<$force> is false.
Returns true if the file was saved, false otherwise.
=back
=cut
sub gpx_save {
my ($o, %opts) = @_;
if (-f $o->gpx->set_filename and ! $opts{force} ) {
print "Overwrite " . $o->gpx->set_filename . ": ";
my $answer = _prompt_yes_no();
if ($answer =~ m/^y|ye|yes$/i) {
$opts{force} = 1
} else { return 0 }
}
$o->gpx->save( %opts );
return 1
}
=over 4
=item gpx( )
Returns the L<Geo::Gpx> instance currently referenced in the object. Croaks if none is found.
=back
=cut
sub gpx {
my $o = shift;
my $class = ref $o;
croak "no waypoint file loaded in $class object" unless defined $o->{gpx};
return $o->{gpx}
}
=over 4
=item way_clip( $name | $regex | LIST )
Sends the coordinates of waypoints whose name is either C<$name> or matches C<$regex> to the clipboard (all points found are sent to the clipboard). Returns an array of points found.
By default, the regex is case-sensitive; specify C<qr/(?i:...)/> to ignore case.
Alternatively, an array of C<Geo::GXP::Points> can be supplied such that we can call C<< $o->way_clip( $o->gpx->search_desc( qr/(?i:Sunset)/ ) >>.
This method is only supported on unix-based systems that have the C<xclip> utility installed (see BUGS AND LIMITATIONS).
=back
=cut
sub way_clip {
my $gpx = shift->gpx;
my @points;
if ( ref $_[0] and $_[0]->isa('Geo::Gpx::Point' )) {
@points = @_
} else {
my $first_arg = shift;
if ( ref( $first_arg ) eq 'Regexp' ) {
@points = $gpx->waypoints_search( name => $first_arg )
} else {
my $match = $gpx->waypoints( name => $first_arg );
push @points, $match if $match
}
croak 'no point matches the supplied regex' unless @points
}
my @points_reversed = reverse @points;
for my $pt (@points_reversed) {
croak 'way_clip() expects list of Geo::Gpx::Point objects' unless $pt->isa('Geo::Gpx::Point');
my $coords = $pt->lat . ', ';
$coords .= $pt->lon;
system("echo $coords | xclip -selection clipboard")
}
return @points
}
=over 4
=item way_device_send()
Send the waypoints to a GPS device, overwriting any existing file. The device must be plugged in.
Some devices have a limit of a 100 waypoints, it will keep the first 100 in the order that they appear in the file. Returns true.
=back
=cut
sub way_device_send {
my $clone = shift->gpx->clone;
croak "device_dir not defined" unless $clone->{device_dir};
# TODO: use proper method once they have been created
$clone->{tracks} = [];
$clone->{routes} = [];
$clone->set_wd( $clone->{device_dir} );
$clone->save( filename => 'Temp.GPX', force => 1 );
return 1
}
=over 4
=item lap_summary( # )
prints summary data for a given lap number. Returns true.
=back
=cut
sub lap_summary {
my ($o, $lap_i) = @_;
my $lap = $o->{Laps}[$lap_i-1];
print "----> Lap ", $lap_i, " <----:\n\n";
for my $key (sort keys %$lap) {
next if $key eq 'Track';
next if $key eq 'Temp'; # delete this one too
print $key, ":", $lap->{$key}, "\n"
}
print "\n";
return 1
}
our $FitConvertPl;
sub _convert_locations_to_gpx {
require Geo::FIT;
my ( $fname, $tmp_fname ) = @_;
if (!defined $FitConvertPl) {
for (split /:/, $ENV{PATH} ) {
$FitConvertPl = $_ . '/locations2gpx.pl';
last if -f $FitConvertPl
}
}
( run in 5.570 seconds using v1.01-cache-2.11-cpan-2398b32b56e )