#!/usr/bin/perl use strict; use POSIX qw(ceil floor); open(INPUT, $infile); my @lines = ; close(INPUT); open(OUTPUT, ">$outfile"); my $timeCounter = 0; my $seconds = 0; my $minutes = 0; my $hours = 0; my $comma = ","; my $space = " "; print OUTPUT ""."\n"; print OUTPUT ""."\n"; print OUTPUT ""."\n"; print OUTPUT "-0.4551.466666715007000650"."\n"; my @headers = split ' ', do{ my $raw = ; $raw =~ tr[",][ ]; $raw }; #" printf @headers; my %planes; foreach my $currentLine(@lines) { my @fields = split',', $currentLine; #--- At this point, we have the data from the current line. We need to convert this to appropriate kml elements my %row; @row{ @headers } = @fields; #--- Get all the elements my $rowid = $row{rowid}; my $aid = $row{aircraft_id}; my $actual_date_time = $row{actual_date_time}; my $latitude = $row{latitude}; my $longitude = $row{longitude}; my $radio_altitude = $row{radio_altitude}; my $ground_speed = $row{ground_speed}; my $thrust_engine_1 = $row{thrust_engine_1}; my $thrust_engine_2 = $row{thrust_engine_2}; my $nox_total = $row{nox_total}; my $co_total = $row{co_total}; #--- Now, convert start and end times into UTC my @timeString = split(my $space,$actual_date_time); $actual_date_time = @timeString[0]."T".@timeString[1]; #--- Determine the heading push @{ $planes{ $aid } }, \%row; if ( @{ $planes{ $aid} } > 1) { my $lat1 = $planes{ $aid }[ -2 ]{latitude}; my $lat2 = $planes{ $aid }[ -1 ]{latitude}; my $dlat = $lat2 - $lat1; my $lon1 = $planes{ $aid }[ -2 ]{longitude}; my $lon2 = $planes{ $aid }[ -1 ]{longitude}; my $dlon = $lon2 - $lon1; my $y = sin( $dlon / 180 ) * cos( $lat2 /180 ); my $x = cos( $lat1 /180 ) * sin( $lat2/180 ) - sin( $lat1/180 ) * cos( $lat2/180 ) * cos( $dlon/180 ); my $heading = atan2( $y, $x ) * 57.2957795; } else { my $heading= 0; } #--- (1) Determine the geometry my $icon = "./blue_plane.png"; print OUTPUT ""; print OUTPUT $longitude.$comma.$latitude.$comma.$radio_altitude; print OUTPUT "relativeToGround"; print OUTPUT "$actual_date_time"; print OUTPUT ""."ID:".$rowid."
"."time:".$actual_date_time."
"."Ground_speed:".$ground_speed."
"."Thrust_engine_1:".$thrust_engine_1."
"."thrust_engine_2:".$thrust_engine_2."
"."nox_total:".$nox_total."
"."co_total:".$co_total."
"."longitude:".$longitude."
"."latitude:".$latitude."
"."radio_altitude:".$radio_altitude."
"; print OUTPUT "
"."\n"; } print OUTPUT "
";