Geo-TCX
view release on metacpan or search on metacpan
lib/Geo/TCX.pm view on Meta::CPAN
$last_point_previous_lap = $lap->trackpoint(-1) if $i > 0;
$lap = Geo::TCX::Lap->new($lapstring, ++$i, $last_point_previous_lap);
push @{ $o->{Laps} }, $lap
}
}
if ( $o->{tag_course} ) {
# in Courses, data is structured as <Lap>...</Lap><Lap>...</Lap><Track>...</Track><Track>...</Track>
# actually, not sure just seem like it's one long ... track, not multiple ones, which complicates things
my $xml_str = $o->{tag_course};
my (@lap_tags, @lap_endpoints, @track_tags);
if ( $xml_str =~ m,(<Lap>.*</Lap>),s ) {
my $str = $1;
@lap_tags = split(/(?s)<\/Lap>\s*<Lap>/, $str );
if (@lap_tags == 0) { push @lap_tags, $str }
}
for my $i (0 .. $#lap_tags) {
my ($end_pos, $end_pt);
if ( $lap_tags[$i] =~ m,<EndPosition>(.*)</EndPosition>,s ) {
$end_pt = Geo::TCX::Trackpoint->new( $1 );
push @lap_endpoints, $end_pt
}
# since split removed tags sometimes at ^ of string for other at $
# let's remove them all and add back
$lap_tags[$i] =~ s,</?Lap>,,g;
$lap_tags[$i] =~ s,^,<Lap>,g;
$lap_tags[$i] =~ s,$,</Lap>,g
}
my $track_str;
if ( $xml_str =~ m,(<Track>.*</Track>),s ) {
$track_str = $1;
}
my $t = Geo::TCX::Track->new( $track_str );
if (@lap_tags ==1) { $track_tags[0] = $track_str }
else {
my ($t1, $t2);
for my $i (0 .. $#lap_tags ) {
if ($i < $#lap_tags) {
($t1, $t2) = $t->split_at_point_closest_to( $lap_endpoints[$i] );
push @track_tags, $t1->xml_string;
$t = $t2
} else { push @track_tags, $t->xml_string } # ie don't split the last track portion
}
}
my $lap;
for my $i (0 .. $#lap_tags) {
my ($lapstring, $last_point_previous_lap);
$lapstring = $lap_tags[$i] . $track_tags[$i];
lib/Geo/TCX/Interactive.pm view on Meta::CPAN
} 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;
script/tcx_interactive.pl view on Meta::CPAN
=item C<< --dev_dir=I<$dir> >>
the directory on the GPS device where the waypoints are stored. On recent devices, this tends to be a C<Locations> folder and older devices it is sometimes named C<GPX/current>.
If C<< way_add_device() >> is called and I<$dir> is not specified, the method will search where this directory might be (provided the GPS device is plugged in).
=item C<< --tolerance_meters => # >>
the distance below which waypoints at the beginning or end of a lap are to be ignored when comparing with the waypoints file read in the instance. The default is 10 meters.
This option is only relevant for C<< way_add_endpoints() >>. It is not considered by C<< way_add_device() >> under the assumption that if a user marked a particular location manually on their device, it has some degree of importance and should not be...
=back
=cut
my $o= Geo::TCX::Interactive->new( $src_dir, recent => $recent, work_dir => $wrk_dir );
$o->prompt_and_set_wd;
# $o->lap_summary($_) for ( 1 .. $o->laps );
$o->save_laps();
if ($wpt_dir) {
my $gpx = $o->gpx_load( $wpt_dir );
$o->way_add_device( $dev_dir );
$o->way_add_endpoints( tolerance_meters => $tolerance_meters );
$o->gpx_save();
}
=head1 DEPENDENCIES
This script is part of the L<Geo::TCX> module and relies on the L<Geo::TCX::Interactive> sub-class it provides.
L<Geo::FIT> is also required to parse FIT files and to add waypoints from a GPS device (except for some older models).
=head1 SEE ALSO
( run in 0.973 second using v1.01-cache-2.11-cpan-2b1a40005be )