Diff for /cup.perl between versions 1.4 and 1.6

version 1.4, 2017/09/10 03:14:30 version 1.6, 2025/05/18 05:59:20
Line 1 Line 1
 #! /usr/bin/perl -w  #! /usr/bin/perl -w
 # $Id$  # $Id$
 use XML::Simple;  use JSON;
 use strict;  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 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  #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",,
Line 32  open GO, "> OmBook.cup" or die "Couldn't Line 38  open GO, "> OmBook.cup" or die "Couldn't
   
 my %strips;  my %strips;
   
 foreach my $stripnum ( keys %{$strips->{'wpt'}} ){  foreach my $feature ( @{$geojson->{'features'}} ){
  if ( defined $strips->{'wpt'}->{$stripnum}->{comment} ) {   if ( ! defined $feature->{'properties'}->{'aip'} ) {
   if ( $strips->{'wpt'}->{$stripnum}->{comment} =~ m/Danger/ ){    print CUP cupstr($feature);
    next;  
   }  
  }  
  print CUP cupstr($stripnum);  
  if ( $strips->{'wpt'}->{$stripnum}->{'extensions'}->{gobook} eq "yes" ){  
   #addtocup($stripnum);  
   print GO cupstr($stripnum);  
  }   }
 }  }
 close GO;  
 close CUP;  close CUP;
   
 exit;  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 {  sub cupstr {
  my $stripnum = shift(@_);   my $feature = shift(@_);
  my $location = "";   my $location = "";
  if ( defined $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'location'} ) {   my $rwlen = "";
   $location = $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'location'};   my $rwdir = "";
  }   my $freq = "";
  return sprintf( qq{"%s","L%s",NZ,%s,%s,%0.1fm,3,,,,"%s",,\r\n},   if ( defined $feature->{'properties'}->{'location'} ) {
   $strips->{'wpt'}->{$stripnum}->{'desc'},    $location = $feature->{'properties'}->{'location'};
   $stripnum,   }
   printlat($strips->{'wpt'}->{$stripnum}->{'lat'}),   if ( defined $feature->{'properties'}->{'rwlen'} ) {
   printlon($strips->{'wpt'}->{$stripnum}->{'lon'}),    $rwlen = $feature->{'properties'}->{'rwlen'};
   $strips->{'wpt'}->{$stripnum}->{'ele'},   }
    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);    $location);
 }  }
   
 sub printlat {  sub printlat {
  my $latitude = shift(@_);   my $latitude = shift(@_);
  my $minutes = 0;   my $minutes = 0;
Line 93  sub printlat { Line 93  sub printlat {
  }   }
  $degrees = int($latitude);   $degrees = int($latitude);
  $minutes = ($latitude - $degrees) * 60;   $minutes = ($latitude - $degrees) * 60;
  return sprintf("%d:%06.3f%s",$degrees,$minutes,$northing);   return sprintf("%d%06.3f%s",$degrees,$minutes,$northing);
 }  }
   
 sub printlon {  sub printlon {
Line 110  sub printlon { Line 110  sub printlon {
  }   }
  $degrees = int($longitude);   $degrees = int($longitude);
  $minutes = ($longitude - $degrees) * 60;   $minutes = ($longitude - $degrees) * 60;
  return sprintf("%d:%06.3f%s",$degrees,$minutes,$westing);   return sprintf("%d%06.3f%s",$degrees,$minutes,$westing);
 }  }
   

Removed from v.1.4  
changed lines
  Added in v.1.6


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>