Various mods to allow querying for nearest airport (with optional ability to
only query those stations with metar weather available.) Metar availability is determined on the fly for now.
This commit is contained in:
parent
969fbe4601
commit
4606f96e13
2 changed files with 59 additions and 13 deletions
|
@ -52,6 +52,8 @@ operator >> ( istream& in, FGAirport& a )
|
||||||
in.getline( name, 256 );
|
in.getline( name, 256 );
|
||||||
a.name = name;
|
a.name = name;
|
||||||
|
|
||||||
|
a.has_metar = true; // assume true
|
||||||
|
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,18 +72,42 @@ FGAirportList::FGAirportList( const string& file ) {
|
||||||
in >> skipeol;
|
in >> skipeol;
|
||||||
|
|
||||||
FGAirport a;
|
FGAirport a;
|
||||||
|
int size = 0;
|
||||||
while ( in ) {
|
while ( in ) {
|
||||||
in >> a;
|
in >> a;
|
||||||
airports[a.id] = a;
|
airports_by_id[a.id] = a;
|
||||||
airports2.push_back(&airports[a.id]);
|
airports_array.push_back( &airports_by_id[a.id] );
|
||||||
|
size++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// search for the specified id
|
// search for the specified id
|
||||||
FGAirport FGAirportList::search( const string& id) {
|
FGAirport FGAirportList::search( const string& id) {
|
||||||
return airports[id];
|
|
||||||
|
return airports_by_id[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// search for the airport nearest the specified position
|
||||||
|
FGAirport FGAirportList::search( double lon_deg, double lat_deg,
|
||||||
|
bool with_metar ) {
|
||||||
|
int closest = 0;
|
||||||
|
double min_dist = 360.0;
|
||||||
|
unsigned int i;
|
||||||
|
for ( i = 0; i < airports_array.size(); ++i ) {
|
||||||
|
// crude manhatten distance based on lat/lon difference
|
||||||
|
double d = fabs(lon_deg - airports_array[i]->longitude)
|
||||||
|
+ fabs(lat_deg - airports_array[i]->latitude);
|
||||||
|
if ( d < min_dist ) {
|
||||||
|
if ( !with_metar || (with_metar && airports_array[i]->has_metar) ) {
|
||||||
|
closest = i;
|
||||||
|
min_dist = d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return *airports_array[closest];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -92,11 +118,18 @@ FGAirportList::~FGAirportList( void ) {
|
||||||
int
|
int
|
||||||
FGAirportList::size () const
|
FGAirportList::size () const
|
||||||
{
|
{
|
||||||
return airports2.size();
|
return airports_array.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
const FGAirport *
|
const FGAirport FGAirportList::getAirport( int index ) const
|
||||||
FGAirportList::getAirport (int index) const
|
|
||||||
{
|
{
|
||||||
return airports2[index];
|
return *airports_array[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark the specified airport record as not having metar
|
||||||
|
*/
|
||||||
|
void FGAirportList::no_metar( const string &id ) {
|
||||||
|
airports_by_id[id].has_metar = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ struct FGAirport {
|
||||||
double elevation;
|
double elevation;
|
||||||
string code;
|
string code;
|
||||||
string name;
|
string name;
|
||||||
|
bool has_metar;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef map < string, FGAirport > airport_map;
|
typedef map < string, FGAirport > airport_map;
|
||||||
|
@ -69,8 +69,8 @@ class FGAirportList {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
airport_map airports;
|
airport_map airports_by_id;
|
||||||
airport_list airports2;
|
airport_list airports_array;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -86,16 +86,29 @@ public:
|
||||||
// "airport" is not changed if "apt" is not found.
|
// "airport" is not changed if "apt" is not found.
|
||||||
FGAirport search( const string& id );
|
FGAirport search( const string& id );
|
||||||
|
|
||||||
|
// search for the airport closest to the specified position
|
||||||
|
// (currently a linear inefficient search so it's probably not
|
||||||
|
// best to use this at runtime.) If with_metar is true, then only
|
||||||
|
// return station id's marked as having metar data.
|
||||||
|
FGAirport search( double lon_deg, double lat_deg, bool with_metar );
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the number of airports in the list.
|
* Return the number of airports in the list.
|
||||||
*/
|
*/
|
||||||
int size () const;
|
int size() const;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a specific airport, by position.
|
* Return a specific airport, by position.
|
||||||
*/
|
*/
|
||||||
const FGAirport * getAirport (int index) const;
|
const FGAirport getAirport( int index ) const;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark the specified airport record as not having metar
|
||||||
|
*/
|
||||||
|
void no_metar( const string &id );
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue