--- cup.perl 2017/09/10 03:14:30 1.4 +++ cup.perl 2025/05/18 05:59:20 1.6 @@ -1,12 +1,18 @@ #! /usr/bin/perl -w -# $Id: cup.perl,v 1.4 2017/09/10 03:14:30 philip Exp $ -use XML::Simple; +# $Id: cup.perl,v 1.6 2025/05/18 05:59:20 philip Exp $ +use JSON; use strict; -my $strips = XMLin('OmLand.gpx'); +my $json = JSON->new; + +open my $fh, '<', 'OmLand.geojson' or die "error opening OmLand.geojson $!\n"; +my $text = do { local $/; <$fh> }; +close $fh; + +my $geojson = $json->decode( $text ); + open CUP, "> OmLand.cup" or die "Couldn't open OmLand.cup: $!\n"; -open GO, "> OmBook.cup" or die "Couldn't open OmBook.cup: $!\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",, @@ -32,52 +38,46 @@ open GO, "> OmBook.cup" or die "Couldn't my %strips; -foreach my $stripnum ( keys %{$strips->{'wpt'}} ){ - if ( defined $strips->{'wpt'}->{$stripnum}->{comment} ) { - if ( $strips->{'wpt'}->{$stripnum}->{comment} =~ m/Danger/ ){ - next; - } - } - print CUP cupstr($stripnum); - if ( $strips->{'wpt'}->{$stripnum}->{'extensions'}->{gobook} eq "yes" ){ - #addtocup($stripnum); - print GO cupstr($stripnum); +foreach my $feature ( @{$geojson->{'features'}} ){ + if ( ! defined $feature->{'properties'}->{'aip'} ) { + print CUP cupstr($feature); } } -close GO; + 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 $feature = 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'}, + my $rwlen = ""; + my $rwdir = ""; + my $freq = ""; + if ( defined $feature->{'properties'}->{'location'} ) { + $location = $feature->{'properties'}->{'location'}; + } + if ( defined $feature->{'properties'}->{'rwlen'} ) { + $rwlen = $feature->{'properties'}->{'rwlen'}; + } + if ( defined $feature->{'properties'}->{'rwdir'} ) { + $rwdir = $feature->{'properties'}->{'rwdir'}; + } + if ( defined $feature->{'properties'}->{'freq'} ) { + $freq = qq{"$feature->{'properties'}->{'freq'}"}; + } + return sprintf( qq{"%s","L%s",NZ,%s,%s,%0.1fm,3,%s,%s,%s,"%s",,\r\n}, + $feature->{'properties'}->{'name'}, + $feature->{'id'}, + printlat($feature->{'geometry'}->{'coordinates'}->[1]), + printlon($feature->{'geometry'}->{'coordinates'}->[0]), + $feature->{'geometry'}->{'coordinates'}->[2], + $rwlen, + $rwdir, + $freq, $location); } + sub printlat { my $latitude = shift(@_); my $minutes = 0; @@ -93,7 +93,7 @@ sub printlat { } $degrees = int($latitude); $minutes = ($latitude - $degrees) * 60; - return sprintf("%d:%06.3f%s",$degrees,$minutes,$northing); + return sprintf("%d%06.3f%s",$degrees,$minutes,$northing); } sub printlon { @@ -110,6 +110,6 @@ sub printlon { } $degrees = int($longitude); $minutes = ($longitude - $degrees) * 60; - return sprintf("%d:%06.3f%s",$degrees,$minutes,$westing); + return sprintf("%d%06.3f%s",$degrees,$minutes,$westing); }