|
|
| version 1.3, 2013/12/26 19:59:00 | version 1.4, 2017/09/10 03:14:30 |
|---|---|
| Line 3 | Line 3 |
| use XML::Simple; | use XML::Simple; |
| use strict; | use strict; |
| my $strips; | my $strips = XMLin('OmLand.gpx'); |
| my $xml = "OmLand.xml"; | |
| if ( defined $xml ){ | |
| $strips = XMLin($xml, KeyAttr => {strip => 'id'}); | |
| } | |
| open CUP, "> OmLand.cup" or die "Couldn't open OmLand.cup: $!\n"; | open CUP, "> OmLand.cup" or die "Couldn't open OmLand.cup: $!\n"; |
| open GO, "> OmBook.cup" or die "Couldn't open OmBook.cup: $!\n"; | |
| print CUP "name,code,country,lat,lon,elev,style,rwdir,rwlen,freq,desc,userdata,pics\n"; | #name,code,country,lat,lon,elev,style,rwdir,rwlen,freq,desc,userdata,pics |
| #"Ahuriri",0002,NZ,4414.000S,16936.000E,756.0m,1,,,,"Mouth of Canyon Creek",, | #"Ahuriri",0002,NZ,4414.000S,16936.000E,756.0m,1,,,,"Mouth of Canyon Creek",, |
| # Style is | # Style is |
| Line 36 print CUP "name,code,country,lat,lon,ele | Line 32 print CUP "name,code,country,lat,lon,ele |
| my %strips; | my %strips; |
| foreach my $stripnum ( keys %{$strips->{strip}} ){ | foreach my $stripnum ( keys %{$strips->{'wpt'}} ){ |
| print CUP qq["$strips->{strip}->{$stripnum}->{name}",]; | if ( defined $strips->{'wpt'}->{$stripnum}->{comment} ) { |
| print CUP qq["$stripnum",NZ,]; | if ( $strips->{'wpt'}->{$stripnum}->{comment} =~ m/Danger/ ){ |
| $strips->{strip}->{$stripnum}->{lat} =~ s/://; | next; |
| print CUP $strips->{strip}->{$stripnum}->{lat} . ","; | } |
| $strips->{strip}->{$stripnum}->{lng} =~ s/://; | } |
| print CUP $strips->{strip}->{$stripnum}->{lng} . ","; | print CUP cupstr($stripnum); |
| print CUP $strips->{strip}->{$stripnum}->{elev} . "f,3,,,,"; | if ( $strips->{'wpt'}->{$stripnum}->{'extensions'}->{gobook} eq "yes" ){ |
| if ( defined $strips->{strip}->{$stripnum}->{location} ) { | #addtocup($stripnum); |
| print CUP qq{"$strips->{strip}->{$stripnum}->{location}"}; | print GO cupstr($stripnum); |
| } | } |
| print CUP ",,\r\n"; | |
| } | } |
| close GO; | |
| close CUP; | close CUP; |
| exit; | |
| sub addtocup { | |
| my $stripnum = shift(@_); | |
| print qq["$strips->{'wpt'}->{$stripnum}->{'desc'}",]; | |
| print qq["L$stripnum",NZ,]; | |
| $strips->{'wpt'}->{$stripnum}->{'lat'} =~ s/://; | |
| print $strips->{'wpt'}->{$stripnum}->{'lat'} . ","; | |
| $strips->{'wpt'}->{$stripnum}->{'lon'} =~ s/://; | |
| print $strips->{'wpt'}->{$stripnum}->{'lon'} . ","; | |
| print $strips->{'wpt'}->{$stripnum}->{'ele'} . "m,3,,,,"; | |
| if ( defined $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'location'} ) { | |
| print qq{"$strips->{'wpt'}->{$stripnum}->{'extensions'}->{'location'}"}; | |
| } | |
| print ",,\r\n"; | |
| } | |
| sub cupstr { | |
| my $stripnum = shift(@_); | |
| my $location = ""; | |
| if ( defined $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'location'} ) { | |
| $location = $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'location'}; | |
| } | |
| return sprintf( qq{"%s","L%s",NZ,%s,%s,%0.1fm,3,,,,"%s",,\r\n}, | |
| $strips->{'wpt'}->{$stripnum}->{'desc'}, | |
| $stripnum, | |
| printlat($strips->{'wpt'}->{$stripnum}->{'lat'}), | |
| printlon($strips->{'wpt'}->{$stripnum}->{'lon'}), | |
| $strips->{'wpt'}->{$stripnum}->{'ele'}, | |
| $location); | |
| } | |
| sub printlat { | |
| my $latitude = shift(@_); | |
| my $minutes = 0; | |
| my $degrees = 0; | |
| my $northing = ""; | |
| if ($latitude < 0) { | |
| $northing = "S"; | |
| $latitude = 0 - $latitude; | |
| } | |
| else{ | |
| $northing = "N"; | |
| } | |
| $degrees = int($latitude); | |
| $minutes = ($latitude - $degrees) * 60; | |
| return sprintf("%d:%06.3f%s",$degrees,$minutes,$northing); | |
| } | |
| sub printlon { | |
| my $longitude = shift(@_); | |
| my $minutes = 0; | |
| my $degrees = 0; | |
| my $westing = ""; | |
| if ($longitude < 0) { | |
| $westing = "W"; | |
| $longitude = 0 - $longitude; | |
| } | |
| else{ | |
| $westing = "E"; | |
| } | |
| $degrees = int($longitude); | |
| $minutes = ($longitude - $degrees) * 60; | |
| return sprintf("%d:%06.3f%s",$degrees,$minutes,$westing); | |
| } | |