From 2d03062b387628a6caeda5dd7ba6aadc3a88bdb2 Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 10 Sep 2004 21:21:34 +0000 Subject: [PATCH] First stab at a simple script that inputs a list of lon/lat coordinates via stdin, and outputs the coordinates with FG ground elevation. This requires a running copy of FlightGear with --fdm=null and the telnet server enabled. Of course you need to have scenery installed for all areas you are querying. This is not fast and the scenery load wait time may need to be tuned for individual systems. --- scripts/perl/examples/find_elevations.pl | 60 ++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 scripts/perl/examples/find_elevations.pl diff --git a/scripts/perl/examples/find_elevations.pl b/scripts/perl/examples/find_elevations.pl new file mode 100755 index 000000000..6b7093aef --- /dev/null +++ b/scripts/perl/examples/find_elevations.pl @@ -0,0 +1,60 @@ +#!/usr/bin/perl +# +# Written by Curtis L. Olson, started January 2003 +# +# This file is in the Public Domain and comes with no warranty. +# +# $Id$ +# ---------------------------------------------------------------------------- + + +# This script will calculate the flightgear ground elevation for a +# serious of lon/lat pairs, given one per line via stdin. Result it +# written to stdout. Lon/lat must be specified in decimal degrees, +# i.e. "-110.2324 39.872" +# +# This requires a copy of flightgear running with "--fdm=null" on the +# specified "$server" host name, at the specified "$port". + +use strict; + +use Time::HiRes qw( usleep ); + +require "telnet.pl"; + +my( $server ) = "localhost"; +my( $port ) = 5401; +my( $timeout ) = 10; + + +# open the connection to the running copy of flightgear +my( $fgfs ); +if ( !( $fgfs = &connect($server, $port, $timeout) ) ) { + die "Error: can't open socket\n"; +} +&send( $fgfs, "data" ); # switch to raw data mode + + +# elevate ourselves only to make the view more interesting, this +# doesn't affect the results +set_prop( $fgfs, "/position/altitude-ft", "5000" ); + +# iterate through the requested coordinates +while ( <> ) { + my( $lon, $lat ) = split; + set_prop( $fgfs, "/position/longitude-deg", $lon ); + set_prop( $fgfs, "/position/latitude-deg", $lat ); + + # wait 1 second for scenery to load + usleep(500000); + + # then fetch ground elevation + my( $elev ) = get_prop( $fgfs, "/position/ground-elev-m" ); + + print "$lon $lat $elev\n"; +} + + +# shutdown our connection (this leaves FG running) +&send( $fgfs, "quit"); +close $fgfs;