Subject: | Is there any way to build a track with Geo::Gpx? |
Date: | Wed, 27 Nov 2013 18:20:34 -0600 |
To: | bug-Geo-Gpx [...] rt.cpan.org |
From: | Doug McLaren <dougmc [...] frenzied.us> |
I'm using Geo::Gpx to make a gpx file and then convert it to a map,
and it was working great using the $gpx->add_waypoint($wpt) interface,
but I couldn't figure out why I was getting points rather than a track.
... and then it hit me -- I was adding waypoints, not a track.
Looks like Geo::Gpx doesn't have a way to create a track, only read
it. $gpx->tracks is read only, so I can't write a track to it.
Is there any way to create a track using it that I have missed? If
not, it might be a worthy feature to add.
As it stands, it looks like my best bet is to just write the gpx file
with waypoints, then use gpsbabel to convert them into track points.
Or just make the xml file myself.
Hmm, gpsbabel is being difficult. Looks like this is the easiest way
I found --
my $gpx = Geo::Gpx->new();
... repeat a lot of $gpx->add_waypoint($wpt) ...
my $xml = $gpx->xml ;
$xml =~ s!(<wpt )!<trk><trkseg>$1! ;
$xml =~ s!(</gpx>)!</trkseg></trk>$1! ;
$xml =~ s!<wpt !<trkpt !g ;
$xml =~ s!</wpt>!</trkpt>!g ;
... and boy, is that nasty!
--
Doug McLaren, dougmc@frenzied.us