UKHAS Wiki

UK High Altitude Society

User Tools

Site Tools


projects:ukhas_glider_project:filter_code
#!usr/bin/perl
# Code originally based on code here: http://awayfromthebench.blogspot.com/2007/09/perl-scripting-for-google-earth.html
#use strict;
 
sub latitude {
    my ($deg, $min) = unpack "a2a*", $_[0];
    my $lat = $deg + $min / 60;
    $lat = - $lat if $_[1] =~ /[Ss]/;
    return $lat;
}
sub longitude {
    my ($deg, $min) = unpack "a3a*", $_[0];
    my $long = $deg + $min / 60;
    $long = - $long if $_[1] =~ /[Ww]/;
    return $long;
}
 
my $filename = 'radio.log';
 
chomp $filename;
 
unless (-e $filename){
    print "Cannot find file \"$filename\"\n";
    exit;
}
 
# Getting input into working file
 
unless (open(INFILE, $filename)){
    print "Cannot open file \"$filename\"\n";
    exit;
}
 
my $separator = ',';
my $kml_outfile = "outfile";
$kml_feature .= '<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://earth.google.com/kml/2.0"><Document><Placemark><name>Google Earth - Pegasus I Flight Path</name><Style><LineStyle><color>ff0000ff</color></LineStyle></Style><LineString><extrude>1</extrude><tessellate>1</tessellate><altitudeMode>absolute</altitudeMode><coordinates>';
 
my $lat;
my $long;
my $alt;
 
foreach my $line (<INFILE>){
    if ($line=~/<(.+)N/){
        $lat = $1;
        my @split = split(undef,$lat);
        my $lat_deg = $split[0].$split[1];
        my $lat_min = $split[2].$split[3];
        $lat_min = $lat_min.$split[4].$split[5].$split[6].$split[7].$split[8];
        my $lat_deg_min = $lat_min / 60;
        $lat = $lat_deg + $lat_deg_min;
    }
    if ($line=~/N(.+)W/){
        $long = $1;
        my @split = split(undef,$long);
        my $long_deg = $split[1].$split[2];
        my $long_min = $split[3].$split[4];
        $long_min = $long_min.$split[5].$split[6].$split[7].$split[8].$split[9];
        my $long_deg_min = $long_min / 60;
        $long = $long_deg + $long_deg_min;
        $long = $long * -1;
    }
    if ($line=~/W(.+?),/){
        $alt = $1;
    }
 $kml_feature .= "$long,$lat,$alt\n";
 
}
close INFILE;
$kml_feature .= "</coordinates></LineString></Placemark></Document></kml>";
 
 
print "$kml_feature\n";
 
exit;
projects/ukhas_glider_project/filter_code.txt ยท Last modified: 2008/07/19 23:33 (external edit)