Add support for XML attribute based lat/lon values
[viking/guyou.git] / viking-remote
blob568357ffe067a4d0d821a37de2573e601af68fe6
1 #!/usr/bin/perl
4 # geo://wpname:cmnt@34.15,-118.15/topo=/somedir,aerial=/someotherdir
7 die "Usage: viking-remote uri\n" if ( $#ARGV < 0 );
9 if ( $ARGV[0] eq "debug" ) {
10 $DEBUG = 1;
11 shift @ARGV;
12 } else {
13 $DEBUG = 0;
16 ($ARGV[0] =~ m<(geo:)?/*([^/]*)(/(.*))?>) or die "Bad URI";
17 $loc = $2;
18 $extras = $4;
20 if ( $loc =~ /^(GC[0-9A-Z]+)$/ ) {
21 $gc = $loc;
22 $loc=`gcfetchtxt http://www.geocaching.com/seek/cache_details.aspx?wp=$loc|head -2|tail +2`;
25 # have a lot of fun...
26 ($loc =~ /^(([^:@]*)(:([^:@]*))?@)?N?(S?)\s*((([0-9'"`°o\-\.])|(° ))*)[, ]\s*E?(W?)\s*(([0-9'"`o\-\.]|(° ))*)(:([0-9\-\.]*))?$/)
27 or die "Bad URI";
29 $wp = $2 ? $2 : ( $gc ? $gc : "waypoint" );
30 $cmt = $4; $lat = $6; $lon = $11; $alt = $15;
32 $latfact = ($5 eq "S") ? -1 : 1;
33 $lonfact = ($10 eq "W") ? -1 : 1;
35 if ( $lat =~ /^(-?)(\d*)[°'"`o] *([\d.]*)$/ ) {
36 $lat = ($2 + ($3/60)) * ($1 ? -1 : 1);
38 if ( $lon =~ /^(-?)(\d*)[°'"`o] *([\d.]*)$/ ) {
39 $lon = ($2 + ($3/60)) * ($1 ? -1 : 1);
42 $lat *= $latfact;
43 $lon *= $lonfact;
45 if ( $extras =~ /^(auto)?street/ ) {
46 $mode = "latlon";
47 $zoom = 4.205;
48 } else {
49 $mode = "utm";
50 $zoom = 4.0;
53 if ( $DEBUG ) {
54 open(PIPE, "|cat");
55 } else {
56 open(PIPE, "|viking -- -");
59 print PIPE <<ENDDATA;
60 #VIKING GPS Data file http://gpsmaps.org/viking/
61 xmpp=$zoom;
62 ympp=$zoom;
63 lat=$lat
64 lon=$lon
65 mode=$mode
66 ENDDATA
68 @maps = split(',', $extras);
69 foreach $map (@maps) {
70 $maptype = -1;
71 $mapname = $map;
72 $mapdir = "";
73 $auto = "f";
74 if ( $map =~ /^auto/ ) {
75 $auto = "t";
76 $map = substr($map, 4, 999);
78 if ( $map =~ /^street/i ) {
79 $maptype = 9;
80 } elsif ( $map =~ /^expedia/i ) {
81 $maptype = 5;
82 } elsif ( $map =~ /^urban/ || $map =~ /^color/ ) {
83 $maptype = 4;
84 } elsif ( $map =~ /^topo/ || $map =~ /^terraserver/ ) {
85 $maptype = 2;
86 } elsif ( $map =~ /^ortho/ || $map =~ /^aerial/ ) {
87 $maptype = 1;
89 if ( $maptype != -1 ) {
90 @mapanddir = split('=', $map);
91 if ( $#mapanddir > 0 ) {
92 $mapname = $mapanddir[0];
93 $mapdir = $mapanddir[1];
95 print PIPE <<ENDDATA;
97 ~Layer Map
98 name=$mapname
99 mode=$maptype
100 directory=$mapdir
101 autodownload=$auto
102 ~EndLayer
103 ENDDATA
107 print PIPE <<ENDDATA;
109 ~Layer TrackWaypoint
110 name=$wp
111 tracks_visible=t
112 waypoints_visible=t
113 ~LayerData
114 type="waypoint" latitude="$lat" longitude="$lon" name="$wp" comment="$cmt" altitude="$alt"
115 ~EndLayerData
116 ~EndLayer
117 ENDDATA
120 close(PIPE);