#!/usr/bin/perl -w # Copywrite Lincoln W. Kliman, www.jbadger.org 2002 # usage: # loc2gps geocaching.loc > geocaching.way # gpstrans -uw geocaching.way use strict; use XML::DOM; use HTTP::Date; use POSIX qw(floor); use POSIX qw(strftime); use POSIX qw(localtime); use POSIX; my $file = $ARGV[0]; my $parser = XML::DOM::Parser->new(); my $doc = $parser->parsefile($file); my $formatstr = "symbol=%s\n"; #// \tGD108:class=|c!\tGD108:colour=~|Z\tGD108:attrs=`\tGD108:depth=QY|c%%|_i\tGD108:state=|cAA\tGD108:country=|cAA\n"; my $cachetime; my $logtime; my $tmtime; my $strtime; my $itemname; my $thiscache; my $cachetype; my $hints; sub stripted { local $_ = shift; # make the required escapes s/\t/_/g; s/\n/_/g; s/ /_/g; return $_; } print "!Format: DDD 0 WGS 84\n!Creation: yes\n\n!W:\n"; foreach my $waypoint ($doc->getElementsByTagName('wpt')){ $thiscache = $waypoint->getElementsByTagName('groundspeak:cache') -> item(0); if ($waypoint->getElementsByTagName('time')->item(0)) { $cachetime = str2time( $waypoint->getElementsByTagName('time')->item(0)-> getFirstChild->getNodeValue ); } else { $cachetime = str2time( "2004-04-04T00:02:36Z" ); } $itemname = $waypoint->getElementsByTagName('name')-> item(0) -> getFirstChild->getNodeValue; if ($thiscache) { $cachetype = substr($thiscache -> getElementsByTagName('groundspeak:container') -> item(0) -> getFirstChild->getNodeValue, 0, 1); substr( $itemname, 1, 1, $cachetype ); } if ($thiscache) { $hints = stripted($thiscache -> getElementsByTagName('groundspeak:encoded_hints') -> item(0) -> getFirstChild->getNodeValue); } if ($hints) { ; } else { $hints = ""; } printf "%-.8s\t \t%-.20s\t", $itemname, strftime( "%d-%b-%Y %H:%M:%S", localtime( $cachetime) ); # "10-Apr-2003 00:00:00"; # $waypoint->getElementsByTagName('time')-> item(0) -> getFirstChild->getNodeValue; if ($waypoint -> getAttribute('lat') < 0) { printf "S%.6f\t", -($waypoint -> getAttribute('lat')); } else { printf "N%.6f\t", $waypoint -> getAttribute('lat'); } if ($waypoint -> getAttribute('lon') < 0) { printf "W%.7f\t", -$waypoint -> getAttribute('lon'); } else { printf "E%.7f\t", $waypoint -> getAttribute('lon'); } if ( tolower( $waypoint->getElementsByTagName('sym')-> item(0) -> getFirstChild->getNodeValue) eq "geocache found") { printf $formatstr, "geocache_fnd"; } else { printf $formatstr, "geocache"; } }