GPX-PlotElevation
view release on metacpan or search on metacpan
lib/GPX/PlotElevation.pm view on Meta::CPAN
package GPX::PlotElevation;
# ABSTRACT: create elevation graphs from GPX files
=head1 NAME
GPX::PlotElevation - a perl module for creating elevation graphs
=head1 SYNOPSIS
use GPX::PlotElevation;
my $plot = GPX::PlotElevation->new(
'gpxfile' => $ARGV[0],
'output' => 'transalp-2009.png',
'width' => 40,
'height' => 10,
);
$plot->calc();
$plot->plot();
=head1 FUNCTIONS
=cut
use strict;
use warnings;
our $VERSION = '1.01'; # VERSION
use IO::File;
use Geo::Gpx;
use Geo::Distance;
use Chart::Gnuplot;
sub new {
my $invocant = shift();
my $class = ref($invocant) || $invocant;
my $self = {
gpxfile => undef,
gpxfh => undef,
gpx => undef,
title => "Hoehenprofil",
xlabel => 'Entfernung [km]',
ylabel => 'Hoehe [m]',
output => undef,
fileformat => 'png',
width => 10,
height => 7,
formula => 'hsin',
_points => [],
_wp_points => [],
_total_dist => 0,
_gpx => undef,
_geodist => Geo::Distance->new(),
@_
};
bless($self, $class);
$self->{'_geodist'}->formula($self->{'formula'});
$self->_load_gpx();
$self->fileformat($self->{'fileformat'});
return($self);
}
sub fileformat {
my $self = shift();
my $fileformat = shift();
if($fileformat !~ m/^(png)$/) {
die("unsupported output fileformat: ".$fileformat);
}
$self->{'fileformat'} = $fileformat;
}
sub _load_gpx {
my $self = shift();
my $infh;
if(defined $self->{'gpx'}) {
$self->{'_gpx'} = Geo::Gpx->new( xml => $self->{'gpx'});
return();
}
if(defined $self->{'gpxfile'}) {
$infh = IO::File->new("<".$self->{'gpxfile'});
$self->{'_gpx'} = Geo::Gpx->new( input => $infh );
$infh->close();
return();
}
if(defined $self->{'gpxfh'}) {
$self->{'_gpx'} = Geo::Gpx->new( input => $self->{'gpxfh'} );
return();
}
die('No GPX input given.');
}
=head2 calc()
Calculate the distance between points in tracks and assig
the waypoints to trackpoints.
=cut
sub calc {
my $self = shift();
$self->_calculate_distances();
$self->_assign_waypoints();
}
sub _calculate_distances {
my $self = shift();
my $tracks = $self->{'_gpx'}->tracks();
my $dist;
my $lastpoint = undef;
foreach my $track (@$tracks) {
my $segments = $track->{'segments'};
( run in 0.505 second using v1.01-cache-2.11-cpan-39bf76dae61 )