In Python, i could use dictionary to do that
In Perl, a "dictionary" is called a hash.
As you have multiple aircraft, you cannot use the rowids to determine consecutive coordinates for a given aircraft (unless there are always and only 2), so I've used a hash of arrays of hashes to accumulate the data in:
$planes{ $aid }[ n ]{ ... };
This print the headings for each aircraft as it reads the data:
C:\test>junk53 Aircraft: 599 heading: 0.000 Aircraft: 591 heading: 90.000 Aircraft: 599 heading: 0.000 Aircraft: 591 heading: 90.000
Would've been nice if the sample contained some heading changes, and I'm somewhat suspicious of the exact 90° difference in the aircraft headings, so check the math. but this should get you started:
#! perl -slw use strict; use Data::Dump qw[ pp ]; my @headers = split ' ', do{ my $raw = <DATA>; $raw =~ tr[",][ ]; $raw + }; #" my %planes; while( my $line = <DATA> ) { $line =~ tr[",][ ]; #" my @fields = split ' ', $line; my $rowid = shift @fields; my $aid = shift @fields; my %row; @row{ @headers } = @fields; push @{ $planes{ $aid } }, \%row; next unless @{ $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 ); printf "Aircraft: %d heading: %6.3f\n", $aid, atan2( $y, $x ) * 57 +.2957795; } __DATA__ "rowid","aircraft_id","actual_date_time","latitude","longitude","radio +_altitude","ground_speed","thrust_engine_1","thrust_engine_2" 3828994,599,2012-11-04 14:00:00,51.47592545,-0.437049866,-9.0,2.0,0.04 +4653355,0.041778761,1.74208527619370935228499282740898271690901934191 +164070390564,15.22092881857486030932218666006017736321211426212568671 +811012 3828995,591,2012-11-04 14:00:00,51.47598267,-0.435331702,-0.875,0.0,0. +066208174,0.068682498,0.913095793953437657822846430541224159086453865 +40627114668956,4.8940906898850944664550883969746212941234464464906348 +3492349 3828996,599,2012-11-04 14:00:01,51.47592545,-0.437049866,-9.0,2.0,0.04 +4653355,0.041778761,1.74208527619370935228499282740898271690901934191 +164070390564,15.22092881857486030932218666006017736321211426212568671 +811012 3828997,591,2012-11-04 14:00:01,51.47598267,-0.435331702,-0.75,0.0,0.0 +64970428,0.068682498,0.9055060385715144395793861983988312690635603870 +3789731965392,4.92096836684002218971971504299700119099094370033875757 +916224 3828998,599,2012-11-04 14:00:02,51.47592545,-0.437049866,-9.0,2.0,0.04 +4653355,0.041778761,1.74208527619370935228499282740898271690901934191 +164070390564,15.22092881857486030932218666006017736321211426212568671 +811012 3828999,591,2012-11-04 14:00:02,51.47598267,-0.435331702,-0.625,0.0,0. +066208174,0.068682498,0.913095793953437657822846430541224159086453865 +40627114668956,4.8940906898850944664550883969746212941234464464906348 +3492349
In reply to Re^3: Calculate aircraft headings from GPS data for google kml display
by BrowserUk
in thread Calculate aircraft headings from GPS data for google kml display
by hujunsimon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |