--- cup.perl 2023/12/26 01:23:11 1.5 +++ cup.perl 2025/05/18 05:59:20 1.6 @@ -1,10 +1,16 @@ #! /usr/bin/perl -w -# $Id: cup.perl,v 1.5 2023/12/26 01:23:11 philip Exp $ -use XML::Simple; +# $Id: cup.perl,v 1.6 2025/05/18 05:59:20 philip Exp $ +use JSON; use strict; -use Data::Dumper; -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"; @@ -32,44 +38,46 @@ open CUP, "> OmLand.cup" or die "Couldn' my %strips; -foreach my $stripnum ( sort keys %{$strips->{'wpt'}} ){ - if ( ! defined $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'aip'} ) { - print CUP cupstr($stripnum); +foreach my $feature ( @{$geojson->{'features'}} ){ + if ( ! defined $feature->{'properties'}->{'aip'} ) { + print CUP cupstr($feature); } } + close CUP; exit; sub cupstr { - my $stripnum = shift(@_); + my $feature = shift(@_); my $location = ""; my $rwlen = ""; my $rwdir = ""; my $freq = ""; - if ( defined $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'location'} ) { - $location = $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'location'}; + if ( defined $feature->{'properties'}->{'location'} ) { + $location = $feature->{'properties'}->{'location'}; } - if ( defined $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'rwlen'} ) { - $rwlen = $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'rwlen'}; + if ( defined $feature->{'properties'}->{'rwlen'} ) { + $rwlen = $feature->{'properties'}->{'rwlen'}; } - if ( defined $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'rwdir'} ) { - $rwdir = $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'rwdir'}; + if ( defined $feature->{'properties'}->{'rwdir'} ) { + $rwdir = $feature->{'properties'}->{'rwdir'}; } - if ( defined $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'freq'} ) { - $freq = qq{"$strips->{'wpt'}->{$stripnum}->{'extensions'}->{'freq'}"}; + 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}, - $strips->{'wpt'}->{$stripnum}->{'desc'}, - $stripnum, - printlat($strips->{'wpt'}->{$stripnum}->{'lat'}), - printlon($strips->{'wpt'}->{$stripnum}->{'lon'}), - $strips->{'wpt'}->{$stripnum}->{'ele'}, + $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;