Basic query routine now working.
This commit is contained in:
parent
96a8cc0fff
commit
ce86c83222
5 changed files with 69 additions and 26 deletions
|
@ -5,6 +5,6 @@ noinst_PROGRAMS = testnavs
|
||||||
libNavAids_a_SOURCES = navaid.hxx navaids.hxx navaids.cxx
|
libNavAids_a_SOURCES = navaid.hxx navaids.hxx navaids.cxx
|
||||||
|
|
||||||
testnavs_SOURCES = testnavs.cxx
|
testnavs_SOURCES = testnavs.cxx
|
||||||
testnavs_LDADD = libNavAids.a -lsgdebug -lsgmisc -lz
|
testnavs_LDADD = libNavAids.a -lsgdebug -lsgmath -lsgmisc -lz
|
||||||
|
|
||||||
INCLUDES += -I$(top_builddir) -I$(top_builddir)/src
|
INCLUDES += -I$(top_builddir) -I$(top_builddir)/src
|
||||||
|
|
|
@ -43,7 +43,7 @@ FG_USING_STD(istream);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
class FGNavAid {
|
class FGNavaid {
|
||||||
|
|
||||||
char type;
|
char type;
|
||||||
double lon, lat;
|
double lon, lat;
|
||||||
|
@ -55,8 +55,8 @@ class FGNavAid {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
inline FGNavAid(void) {}
|
inline FGNavaid(void) {}
|
||||||
inline ~FGNavAid(void) {}
|
inline ~FGNavaid(void) {}
|
||||||
|
|
||||||
inline char get_type() const { return type; }
|
inline char get_type() const { return type; }
|
||||||
inline double get_lon() const { return lon; }
|
inline double get_lon() const { return lon; }
|
||||||
|
@ -76,16 +76,16 @@ public:
|
||||||
inline void set_dme( bool b ) { dme = b; }
|
inline void set_dme( bool b ) { dme = b; }
|
||||||
inline void set_ident( char *i ) { strncpy( ident, i, 5 ); }
|
inline void set_ident( char *i ) { strncpy( ident, i, 5 ); }
|
||||||
|
|
||||||
friend istream& operator>> ( istream&, FGNavAid& );
|
friend istream& operator>> ( istream&, FGNavaid& );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
inline istream&
|
inline istream&
|
||||||
operator >> ( istream& in, FGNavAid& n )
|
operator >> ( istream& in, FGNavaid& n )
|
||||||
{
|
{
|
||||||
double f;
|
double f;
|
||||||
char c;
|
char c;
|
||||||
in >> n.type >> n.lon >> n.lat >> n.elev >> f >> n.range
|
in >> n.type >> n.lat >> n.lon >> n.elev >> f >> n.range
|
||||||
>> c >> n.ident;
|
>> c >> n.ident;
|
||||||
|
|
||||||
n.freq = (int)(f * 100.0);
|
n.freq = (int)(f * 100.0);
|
||||||
|
|
|
@ -21,25 +21,26 @@
|
||||||
// $Id$
|
// $Id$
|
||||||
|
|
||||||
|
|
||||||
#include <simgear/misc/fgstream.hxx>
|
|
||||||
#include <simgear/debug/logstream.hxx>
|
#include <simgear/debug/logstream.hxx>
|
||||||
|
#include <simgear/misc/fgstream.hxx>
|
||||||
|
#include <simgear/math/fg_geodesy.hxx>
|
||||||
|
|
||||||
#include "navaids.hxx"
|
#include "navaids.hxx"
|
||||||
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
FGNavAids::FGNavAids( void ) {
|
FGNavaids::FGNavaids( void ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
FGNavAids::~FGNavAids( void ) {
|
FGNavaids::~FGNavaids( void ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// load the navaids and build the map
|
// load the navaids and build the map
|
||||||
bool FGNavAids::init( FGPath path ) {
|
bool FGNavaids::init( FGPath path ) {
|
||||||
FGNavAid n;
|
FGNavaid n;
|
||||||
|
|
||||||
navaids.erase( navaids.begin(), navaids.end() );
|
navaids.erase( navaids.begin(), navaids.end() );
|
||||||
|
|
||||||
|
@ -87,3 +88,32 @@ bool FGNavAids::init( FGPath path ) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// query the database for the specified frequency, lon and lat are in
|
||||||
|
// degrees, elev is in meters
|
||||||
|
bool FGNavaids::query( double lon, double lat, double elev, double freq,
|
||||||
|
FGNavaid *n, double *heading, double *dist )
|
||||||
|
{
|
||||||
|
nav_list_type stations = navaids[(int)(freq*100.0)];
|
||||||
|
|
||||||
|
nav_list_iterator current = stations.begin();
|
||||||
|
nav_list_iterator last = stations.end();
|
||||||
|
|
||||||
|
double az1, az2, s;
|
||||||
|
for ( ; current != last ; ++current ) {
|
||||||
|
// cout << "testing " << current->get_ident() << endl;
|
||||||
|
geo_inverse_wgs_84( elev, lat, lon,
|
||||||
|
current->get_lat(), current->get_lon(),
|
||||||
|
&az1, &az2, &s );
|
||||||
|
// cout << " dist = " << s << endl;
|
||||||
|
if ( s < ( current->get_range() * NM_TO_METER ) ) {
|
||||||
|
*n = *current;
|
||||||
|
*heading = az2;
|
||||||
|
*dist = s;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
|
@ -37,29 +37,31 @@ FG_USING_STD(map);
|
||||||
FG_USING_STD(vector);
|
FG_USING_STD(vector);
|
||||||
|
|
||||||
|
|
||||||
// convenience types
|
class FGNavaids {
|
||||||
typedef vector < FGNavAid > nav_list_type;
|
|
||||||
typedef nav_list_type::iterator nav_list_iterator;
|
|
||||||
typedef nav_list_type::const_iterator nav_list_const_iterator;
|
|
||||||
|
|
||||||
typedef map < int, nav_list_type, less<int> > nav_map_type;
|
// convenience types
|
||||||
typedef nav_map_type::iterator nav_map_iterator;
|
typedef vector < FGNavaid > nav_list_type;
|
||||||
typedef nav_map_type::const_iterator nav_map_const_iterator;
|
typedef nav_list_type::iterator nav_list_iterator;
|
||||||
|
typedef nav_list_type::const_iterator nav_list_const_iterator;
|
||||||
|
|
||||||
class FGNavAids {
|
typedef map < int, nav_list_type, less<int> > nav_map_type;
|
||||||
|
typedef nav_map_type::iterator nav_map_iterator;
|
||||||
|
typedef nav_map_type::const_iterator nav_map_const_iterator;
|
||||||
|
|
||||||
nav_map_type navaids;
|
nav_map_type navaids;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
FGNavAids();
|
FGNavaids();
|
||||||
~FGNavAids();
|
~FGNavaids();
|
||||||
|
|
||||||
// load the navaids and build the map
|
// load the navaids and build the map
|
||||||
bool init( FGPath path );
|
bool init( FGPath path );
|
||||||
|
|
||||||
// query the database for the specified frequency
|
// query the database for the specified frequency, lon and lat are
|
||||||
FGNavAid query( double lon, double lat, int freq );
|
// in degrees, elev is in meters
|
||||||
|
bool query( double lon, double lat, double elev, double freq,
|
||||||
|
FGNavaid *n, double *heading, double *dist);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,20 @@
|
||||||
#include "navaids.hxx"
|
#include "navaids.hxx"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
FGNavAids navs;
|
FGNavaids navs;
|
||||||
|
|
||||||
FGPath p( "/home/curt/FlightGear/Navaids/default.nav.gz" );
|
FGPath p( "/export/data2/curt/FlightGear/Navaids/default.nav" );
|
||||||
|
|
||||||
navs.init( p );
|
navs.init( p );
|
||||||
|
|
||||||
|
FGNavaid n;
|
||||||
|
double heading, dist;
|
||||||
|
if ( navs.query( -93.2, 45.14, 3000, 117.30,
|
||||||
|
&n, &heading, &dist) ) {
|
||||||
|
cout << "Found a station in range" << endl;
|
||||||
|
cout << " id = " << n.get_ident() << endl;
|
||||||
|
cout << " heading = " << heading << " dist = " << dist << endl;
|
||||||
|
} else {
|
||||||
|
cout << "not picking anything up. :-(" << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue