Gpx-Addons-Filter

 view release on metacpan or  search on metacpan

lib/Gpx/Addons/Filter.pm  view on Meta::CPAN

            	   croak("Start- and end-time must be unix-epoche-seconds!\n")
            	}
                if ($start > $end) {
            	   croak("hmh - you passed an end-time greater than the start-time - this can not work\n")
            	}
            	if ($start < 915148800 or $end < 915148800) {
            	   carp("You are working on track-points dated before Jan 1, 1999 - strange. (Tip: this function accepts epoch-seconds only)")
            	}
            	
            	
            	# Comparing the timeframe with the segments start- and endpoint
				if ( ($first_point < $start) and ($last_point < $start) ) {
					##### Segment is completely outside of time-frame (before)
					next SEGMENT;
				} elsif (($first_point > $end) and ($last_point > $end)) {
					##### Segment is completely outside of time-frame (after)
					next SEGMENT;
				} else {
					##### Segment is inside of timeframe (at least a part of it)
					push @{$filtered->{segments}}, $seg;
				} 

t/050-filter_trk.t  view on Meta::CPAN

                        time => 1234530005,
                        pos  => 'out',
                    },
                    {
                        lat  => '54.6016296784874',
                        lon  => '-3.40418920968631',
                        time => 1234565000,
                        pos  => 'in',
                    }
                ],
                cmt => 'Segment C with endpoint within the timeframe',
                pos1 => 'in',
                pos2 => 'in',
                pos3 => 'in',
            },

            # Single Point Segments
            {
                'points' => [
                    {
                        lat  => '54.6862790450185',

t/050-filter_trk.t  view on Meta::CPAN

                        time => 1234565005,
                        pos  => 'in',
                    },
                    {
                        lat  => '54.6016296784874',
                        lon  => '-3.40418920968631',
                        time => 1234568000,
                        pos  => 'in',
                    }
                ],
                cmt => 'Segment D with startpoint touching the beginning and endpoint within timeframe',
                pos1 => 'in',
                pos2 => 'in',
                pos3 => 'in',
            },
            {
                'points' => [
                    {
                        lat  => '54.5182217145253',
                        lon  => '-2.62191579018834',
                        time => 1234560000,

t/050-filter_trk.t  view on Meta::CPAN

    },
    # =====================
    # = Confused Segments =
    # =====================
    # 
    # Segments with enpoints earlier than the startpoint (reversed or confused) 
    # should be ignored from fiter_trk (if later versions of this functian can cope wuth such
    # a segement, just remove the ignore-key completely, to include them again into the test)
    #
    # Note: As long as both start- and end-time were given, the present version of this function still
    # selected the right segments. But with seting start- or endpoint to undef, the confusin began. So I 
    # removed the "feature" of processing reversed segments.
    
    {
        'name'     => 'Track with Special-Segments',
        'segments' => [
            {
                'points' => [
                    {
                        lat  => '54.5182217145253',
                        lon  => '-2.62191579018834',

t/050-filter_trk.t  view on Meta::CPAN

                        time => 1234565005,
                        pos  => 'in',
                    },
                    {
                        lat  => '54.6016296784874',
                        lon  => '-3.40418920968631',
                        time => 1234510000,
                        pos  => 'out',
                    }
                ],
                cmt => 'Confused Segment (time is inversed) with endpoints out of timeframe',
                pos1 => 'in',
                pos2 => 'in',
                pos3 => 'in',
                ignore  => '',
            },
            {
                'points' => [
                    {
                        lat  => '54.5182217145253',
                        lon  => '-2.62191579018834',

t/050-filter_trk.t  view on Meta::CPAN

if ( $DEBUG > 1 ) {
    my $xml = $gpx->xml('1.1');
    print {*STDERR} "$xml\n";
}

# ================================================================
# = Calculate the number of segments inside the different frames =
# ================================================================
# 1 .. start and end point
# 2 .. startpoint only
# 3 .. endpoint only
my ($inside_seg1, $inside_seg2, $inside_seg3) = 0;
foreach my $trk (@{$tracks}) {
    foreach my $seg (@{$trk->{segments}}) {
        next if defined $seg->{ignore};
        $inside_seg1++ if $seg->{pos1} eq 'in';
        $inside_seg2++ if $seg->{pos2} eq 'in';
        $inside_seg3++ if $seg->{pos3} eq 'in';
    }
}



( run in 2.325 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )