#!/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; my $file = $ARGV[0]; my $parser = XML::DOM::Parser->new(); my $doc = $parser->parsefile($file); # # From the file gpstrans-0.39/src/gps/sendgpsinfo.c getFileData (...) # Line must start with the word "Format:" (with the colon). # Column offset 8 -- must be the data format (DDD) # Column offset 25 -- time offset read with %lf # Column offset 43 -- must be the 3 digit datum type, read with %3hd, 100 for WGS 84 # # 012345678901234567890123456789012345678901234567890123 print "Format: DDD UTC Offset: 0.00 hrs Datum[100]: WGS 84\n"; #{ TYPE = 0, NAME, COMMENT, DATE, LAT, LON }; # each waypoint is a tab seperated record. # 0 - The line startes with "W" # 1 - The next 6 characters are the waypoint name # 2 - A comment, it is sent last -- used in eTrex as evevation (40 # characters) # 3 - 19 character date. mm/dd/yyyy hh:mm:ss # 4 - latitude # 5 - longitude # # Note I addded a couple of extra tabs at the end. gpstrans does not # bound check to see if it is reading past the end of the line. # # # Wnamecommentmm/dd/yyyy hh:mm:sslatlog foreach my $waypoint ($doc->getElementsByTagName('waypoint')){ print "W\t"; print $waypoint->getElementsByTagName('name') -> item(0) -> getAttribute('id'); print "\t0 meters\t12/31/1989 01:01:01\t"; printf "%.7f", $waypoint->getElementsByTagName('coord')->item(0)-> getAttribute('lat'); print "\t" ; printf "%.7f", $waypoint->getElementsByTagName('coord')->item(0)-> getAttribute('lon'); print "\t\t\t\n" ; }