Diff for /cup.perl between versions 1.3 and 1.6

version 1.3, 2013/12/26 19:59:00 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;  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 );
   
 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";
   
 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 38  print CUP "name,code,country,lat,lon,ele
   
 my %strips;  my %strips;
   
 foreach my $stripnum ( keys %{$strips->{strip}} ){  foreach my $feature ( @{$geojson->{'features'}} ){
  print CUP qq["$strips->{strip}->{$stripnum}->{name}",];   if ( ! defined $feature->{'properties'}->{'aip'} ) {
  print CUP qq["$stripnum",NZ,];    print CUP cupstr($feature);
  $strips->{strip}->{$stripnum}->{lat} =~ s/://;  
  print CUP $strips->{strip}->{$stripnum}->{lat} . ",";  
  $strips->{strip}->{$stripnum}->{lng} =~ s/://;  
  print CUP $strips->{strip}->{$stripnum}->{lng} . ",";  
  print CUP $strips->{strip}->{$stripnum}->{elev} . "f,3,,,,";  
  if ( defined $strips->{strip}->{$stripnum}->{location} ) {  
   print CUP qq{"$strips->{strip}->{$stripnum}->{location}"};  
  }   }
  print CUP ",,\r\n";  
 }  }
   
 close CUP;  close CUP;
   
   exit;
   
   sub cupstr {
    my $feature = shift(@_);
    my $location = "";
    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;
    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);
   }
   

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


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