2 // simple.cxx -- a really simplistic class to manage airport ID,
3 // lat, lon of the center of one of it's runways, and
6 // Written by Curtis Olson, started April 1998.
7 // Updated by Durk Talsma, started December, 2004.
9 // Copyright (C) 1998 Curtis L. Olson - http://www.flightgear.org/~curt
11 // This program is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU General Public License as
13 // published by the Free Software Foundation; either version 2 of the
14 // License, or (at your option) any later version.
16 // This program is distributed in the hope that it will be useful, but
17 // WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // General Public License for more details.
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31 #include "airport.hxx"
35 #include <boost/foreach.hpp>
37 #include <simgear/misc/sg_path.hxx>
38 #include <simgear/props/props.hxx>
39 #include <simgear/props/props_io.hxx>
40 #include <simgear/debug/logstream.hxx>
41 #include <simgear/sg_inlines.h>
42 #include <simgear/structure/exception.hxx>
44 #include <Environment/environment_mgr.hxx>
45 #include <Environment/environment.hxx>
46 #include <Main/fg_props.hxx>
47 #include <Airports/runways.hxx>
48 #include <Airports/pavement.hxx>
49 #include <Airports/dynamics.hxx>
50 #include <Airports/xmlloader.hxx>
51 #include <Navaids/procedure.hxx>
52 #include <Navaids/waypoint.hxx>
53 #include <ATC/CommStation.hxx>
54 #include <Navaids/NavDataCache.hxx>
59 using namespace flightgear;
61 /***************************************************************************
63 ***************************************************************************/
65 AirportCache FGAirport::airportCache;
67 FGAirport::FGAirport( PositionedID aGuid,
68 const std::string &id,
69 const SGGeod& location,
70 const std::string &name,
73 FGPositioned(aGuid, aType, id, location),
75 _has_metar(has_metar),
77 mTowerDataLoaded(false),
78 mRunwaysLoaded(false),
79 mHelipadsLoaded(false),
80 mTaxiwaysLoaded(false),
81 mProceduresLoaded(false),
87 FGAirport::~FGAirport()
92 bool FGAirport::isAirport() const
94 return type() == AIRPORT;
97 bool FGAirport::isSeaport() const
99 return type() == SEAPORT;
102 bool FGAirport::isHeliport() const
104 return type() == HELIPORT;
107 bool FGAirport::isAirportType(FGPositioned* pos)
113 return (pos->type() >= AIRPORT) && (pos->type() <= SEAPORT);
116 FGAirportDynamics * FGAirport::getDynamics()
122 _dynamics = new FGAirportDynamics(this);
123 XMLLoader::load(_dynamics);
126 FGRunwayPreference rwyPrefs(this);
127 XMLLoader::load(&rwyPrefs);
128 _dynamics->setRwyUse(rwyPrefs);
133 //------------------------------------------------------------------------------
134 unsigned int FGAirport::numRunways() const
137 return mRunways.size();
140 //------------------------------------------------------------------------------
141 unsigned int FGAirport::numHelipads() const
144 return mHelipads.size();
147 //------------------------------------------------------------------------------
148 FGRunwayRef FGAirport::getRunwayByIndex(unsigned int aIndex) const
151 return loadById<FGRunway>(mRunways, aIndex);
154 //------------------------------------------------------------------------------
155 FGHelipadRef FGAirport::getHelipadByIndex(unsigned int aIndex) const
158 return loadById<FGHelipad>(mHelipads, aIndex);
161 //------------------------------------------------------------------------------
162 FGRunwayMap FGAirport::getRunwayMap() const
167 double minLengthFt = fgGetDouble("/sim/navdb/min-runway-length-ft");
169 BOOST_FOREACH(PositionedID id, mRunways)
171 FGRunway* rwy = loadById<FGRunway>(id);
173 // ignore unusably short runways
174 // TODO other methods don't check this...
175 if( rwy->lengthFt() >= minLengthFt )
176 map[ rwy->ident() ] = rwy;
182 //------------------------------------------------------------------------------
183 FGHelipadMap FGAirport::getHelipadMap() const
188 BOOST_FOREACH(PositionedID id, mHelipads)
190 FGHelipad* rwy = loadById<FGHelipad>(id);
191 map[ rwy->ident() ] = rwy;
197 //------------------------------------------------------------------------------
198 bool FGAirport::hasRunwayWithIdent(const std::string& aIdent) const
200 return flightgear::NavDataCache::instance()
201 ->airportItemWithIdent(guid(), FGPositioned::RUNWAY, aIdent) != 0;
204 //------------------------------------------------------------------------------
205 bool FGAirport::hasHelipadWithIdent(const std::string& aIdent) const
207 return flightgear::NavDataCache::instance()
208 ->airportItemWithIdent(guid(), FGPositioned::HELIPAD, aIdent) != 0;
211 //------------------------------------------------------------------------------
212 FGRunwayRef FGAirport::getRunwayByIdent(const std::string& aIdent) const
215 flightgear::NavDataCache::instance()
216 ->airportItemWithIdent(guid(), FGPositioned::RUNWAY, aIdent);
219 SG_LOG(SG_GENERAL, SG_ALERT, "no such runway '" << aIdent << "' at airport " << ident());
220 throw sg_range_exception("unknown runway " + aIdent + " at airport:" + ident(), "FGAirport::getRunwayByIdent");
223 return loadById<FGRunway>(id);
226 //------------------------------------------------------------------------------
227 FGHelipadRef FGAirport::getHelipadByIdent(const std::string& aIdent) const
229 PositionedID id = flightgear::NavDataCache::instance()->airportItemWithIdent(guid(), FGPositioned::HELIPAD, aIdent);
231 SG_LOG(SG_GENERAL, SG_ALERT, "no such helipad '" << aIdent << "' at airport " << ident());
232 throw sg_range_exception("unknown helipad " + aIdent + " at airport:" + ident(), "FGAirport::getRunwayByIdent");
235 return loadById<FGHelipad>(id);
238 //------------------------------------------------------------------------------
239 FGRunwayRef FGAirport::findBestRunwayForHeading(double aHeading) const
243 FGRunway* result = NULL;
244 double currentBestQuality = 0.0;
246 SGPropertyNode *param = fgGetNode("/sim/airport/runways/search", true);
247 double lengthWeight = param->getDoubleValue("length-weight", 0.01);
248 double widthWeight = param->getDoubleValue("width-weight", 0.01);
249 double surfaceWeight = param->getDoubleValue("surface-weight", 10);
250 double deviationWeight = param->getDoubleValue("deviation-weight", 1);
252 BOOST_FOREACH(PositionedID id, mRunways) {
253 FGRunway* rwy = loadById<FGRunway>(id);
254 // bug http://code.google.com/p/flightgear-bugs/issues/detail?id=1149
255 // (and probably some other issues besides).
256 if (rwy->type() == FGPositioned::HELIPAD) {
260 double good = rwy->score(lengthWeight, widthWeight, surfaceWeight);
261 double dev = aHeading - rwy->headingDeg();
262 SG_NORMALIZE_RANGE(dev, -180.0, 180.0);
263 double bad = fabs(deviationWeight * dev) + 1e-20;
264 double quality = good / bad;
266 if (quality > currentBestQuality) {
267 currentBestQuality = quality;
275 //------------------------------------------------------------------------------
276 FGRunwayRef FGAirport::findBestRunwayForPos(const SGGeod& aPos) const
280 FGRunway* result = NULL;
281 double currentLowestDev = 180.0;
283 BOOST_FOREACH(PositionedID id, mRunways) {
284 FGRunway* rwy = loadById<FGRunway>(id);
286 double inboundCourse = SGGeodesy::courseDeg(aPos, rwy->end());
287 double dev = inboundCourse - rwy->headingDeg();
288 SG_NORMALIZE_RANGE(dev, -180.0, 180.0);
291 if (dev < currentLowestDev) { // new best match
292 currentLowestDev = dev;
295 } // of runway iteration
301 //------------------------------------------------------------------------------
302 bool FGAirport::hasHardRunwayOfLengthFt(double aLengthFt) const
306 BOOST_FOREACH(PositionedID id, mRunways) {
307 FGRunway* rwy = loadById<FGRunway>(id);
308 if (rwy->isHardSurface() && (rwy->lengthFt() >= aLengthFt)) {
309 return true; // we're done!
311 } // of runways iteration
316 //------------------------------------------------------------------------------
317 FGRunwayList FGAirport::getRunwaysWithoutReciprocals() const
323 BOOST_FOREACH(PositionedID id, mRunways) {
324 FGRunway* rwy = loadById<FGRunway>(id);
325 FGRunway* recip = rwy->reciprocalRunway();
327 FGRunwayList::iterator it = std::find(r.begin(), r.end(), recip);
329 continue; // reciprocal already in result set, don't include us
339 //------------------------------------------------------------------------------
340 unsigned int FGAirport::numTaxiways() const
343 return mTaxiways.size();
346 //------------------------------------------------------------------------------
347 FGTaxiwayRef FGAirport::getTaxiwayByIndex(unsigned int aIndex) const
350 return loadById<FGTaxiway>(mTaxiways, aIndex);
353 //------------------------------------------------------------------------------
354 FGTaxiwayList FGAirport::getTaxiways() const
357 return loadAllById<FGTaxiway>(mTaxiways);
360 //------------------------------------------------------------------------------
361 unsigned int FGAirport::numPavements() const
364 return mPavements.size();
367 //------------------------------------------------------------------------------
368 FGPavementRef FGAirport::getPavementByIndex(unsigned int aIndex) const
371 return loadById<FGPavement>(mPavements, aIndex);
374 //------------------------------------------------------------------------------
375 FGPavementList FGAirport::getPavements() const
378 return loadAllById<FGPavement>(mPavements);
381 //------------------------------------------------------------------------------
382 FGRunwayRef FGAirport::getActiveRunwayForUsage() const
384 FGEnvironmentMgr* envMgr = (FGEnvironmentMgr *) globals->get_subsystem("environment");
386 // This forces West-facing rwys to be used in no-wind situations
387 // which is consistent with Flightgear's initial setup.
391 FGEnvironment stationWeather(envMgr->getEnvironment(mPosition));
393 double windSpeed = stationWeather.get_wind_speed_kt();
394 if (windSpeed > 0.0) {
395 hdg = stationWeather.get_wind_from_heading_deg();
399 return findBestRunwayForHeading(hdg);
402 //------------------------------------------------------------------------------
403 FGAirportRef FGAirport::findClosest( const SGGeod& aPos,
407 AirportFilter aptFilter;
411 return static_pointer_cast<FGAirport>
413 FGPositioned::findClosest(aPos, aCuttofNm, filter)
417 FGAirport::HardSurfaceFilter::HardSurfaceFilter(double minLengthFt) :
418 mMinLengthFt(minLengthFt)
420 if (minLengthFt < 0.0) {
421 mMinLengthFt = fgGetDouble("/sim/navdb/min-runway-length-ft", 0.0);
425 bool FGAirport::HardSurfaceFilter::passAirport(FGAirport* aApt) const
427 return aApt->hasHardRunwayOfLengthFt(mMinLengthFt);
430 //------------------------------------------------------------------------------
431 FGAirport::TypeRunwayFilter::TypeRunwayFilter():
432 _type(FGPositioned::AIRPORT),
433 _min_runway_length_ft( fgGetDouble("/sim/navdb/min-runway-length-ft", 0.0) )
438 //------------------------------------------------------------------------------
439 bool FGAirport::TypeRunwayFilter::fromTypeString(const std::string& type)
441 if( type == "heliport" ) _type = FGPositioned::HELIPORT;
442 else if( type == "seaport" ) _type = FGPositioned::SEAPORT;
443 else if( type == "airport" ) _type = FGPositioned::AIRPORT;
449 //------------------------------------------------------------------------------
450 bool FGAirport::TypeRunwayFilter::pass(FGPositioned* pos) const
452 FGAirport* apt = static_cast<FGAirport*>(pos);
453 if( (apt->type() == FGPositioned::AIRPORT)
454 && !apt->hasHardRunwayOfLengthFt(_min_runway_length_ft)
461 //------------------------------------------------------------------------------
462 FGAirportRef FGAirport::findByIdent(const std::string& aIdent)
464 AirportCache::iterator it = airportCache.find(aIdent);
465 if (it != airportCache.end())
469 FGAirportRef r = static_pointer_cast<FGAirport>
471 FGPositioned::findFirstWithIdent(aIdent, &filter)
474 // add airport to the cache (even when it's NULL, so we don't need to search in vain again)
475 airportCache[aIdent] = r;
477 // we don't warn here when r==NULL, let the caller do that
481 //------------------------------------------------------------------------------
482 FGAirportRef FGAirport::getByIdent(const std::string& aIdent)
484 FGAirportRef r = findByIdent(aIdent);
486 throw sg_range_exception("No such airport with ident: " + aIdent);
490 char** FGAirport::searchNamesAndIdents(const std::string& aFilter)
492 return NavDataCache::instance()->searchAirportNamesAndIdents(aFilter);
495 // find basic airport location info from airport database
496 const FGAirport *fgFindAirportID( const std::string& id)
502 return FGAirport::findByIdent(id);
505 void FGAirport::loadRunways() const
507 if (mRunwaysLoaded) {
508 return; // already loaded, great
511 loadSceneryDefinitions();
513 mRunwaysLoaded = true;
514 mRunways = flightgear::NavDataCache::instance()->airportItemsOfType(guid(), FGPositioned::RUNWAY);
517 void FGAirport::loadHelipads() const
519 if (mHelipadsLoaded) {
520 return; // already loaded, great
523 loadSceneryDefinitions();
525 mHelipadsLoaded = true;
526 mHelipads = flightgear::NavDataCache::instance()->airportItemsOfType(guid(), FGPositioned::HELIPAD);
529 void FGAirport::loadTaxiways() const
531 if (mTaxiwaysLoaded) {
532 return; // already loaded, great
535 mTaxiwaysLoaded = true;
536 mTaxiways = flightgear::NavDataCache::instance()->airportItemsOfType(guid(), FGPositioned::TAXIWAY);
539 void FGAirport::loadProcedures() const
541 if (mProceduresLoaded) {
545 mProceduresLoaded = true;
547 if (!XMLLoader::findAirportData(ident(), "procedures", path)) {
548 SG_LOG(SG_GENERAL, SG_INFO, "no procedures data available for " << ident());
552 SG_LOG(SG_GENERAL, SG_INFO, ident() << ": loading procedures from " << path.str());
553 RouteBase::loadAirportProcedures(path, const_cast<FGAirport*>(this));
556 void FGAirport::loadSceneryDefinitions() const
558 NavDataCache* cache = NavDataCache::instance();
559 if (cache->isReadOnly()) {
564 if (!XMLLoader::findAirportData(ident(), "threshold", path)) {
565 return; // no XML threshold data
568 if (!cache->isCachedFileModified(path)) {
569 // cached values are correct, we're all done
573 flightgear::NavDataCache::Transaction txn(cache);
574 SGPropertyNode_ptr rootNode = new SGPropertyNode;
575 readProperties(path.str(), rootNode);
576 const_cast<FGAirport*>(this)->readThresholdData(rootNode);
577 cache->stampCacheFile(path);
581 void FGAirport::readThresholdData(SGPropertyNode* aRoot)
583 SGPropertyNode* runway;
585 for (; (runway = aRoot->getChild("runway", runwayIndex)) != NULL; ++runwayIndex) {
586 SGPropertyNode* t0 = runway->getChild("threshold", 0),
587 *t1 = runway->getChild("threshold", 1);
589 assert(t1); // too strict? maybe we should finally allow single-ended runways
591 processThreshold(t0);
592 processThreshold(t1);
593 } // of runways iteration
596 void FGAirport::processThreshold(SGPropertyNode* aThreshold)
598 // first, let's identify the current runway
599 std::string rwyIdent(aThreshold->getStringValue("rwy"));
600 NavDataCache* cache = NavDataCache::instance();
601 PositionedID id = cache->airportItemWithIdent(guid(), FGPositioned::RUNWAY, rwyIdent);
603 SG_LOG(SG_GENERAL, SG_DEBUG, "FGAirport::processThreshold: "
604 "found runway not defined in the global data:" << ident() << "/" << rwyIdent);
608 double lon = aThreshold->getDoubleValue("lon"),
609 lat = aThreshold->getDoubleValue("lat");
610 SGGeod newThreshold(SGGeod::fromDegM(lon, lat, mPosition.getElevationM()));
612 double newHeading = aThreshold->getDoubleValue("hdg-deg");
613 double newDisplacedThreshold = aThreshold->getDoubleValue("displ-m");
614 double newStopway = aThreshold->getDoubleValue("stopw-m");
616 cache->updateRunwayThreshold(id, newThreshold,
617 newHeading, newDisplacedThreshold, newStopway);
620 SGGeod FGAirport::getTowerLocation() const
624 NavDataCache* cache = NavDataCache::instance();
625 PositionedIDVec towers = cache->airportItemsOfType(guid(), FGPositioned::TOWER);
626 if (towers.empty()) {
627 SG_LOG(SG_GENERAL, SG_ALERT, "No towers defined for:" <<ident());
631 FGPositionedRef tower = cache->loadById(towers.front());
632 return tower->geod();
635 void FGAirport::validateTowerData() const
637 if (mTowerDataLoaded) {
641 mTowerDataLoaded = true;
642 NavDataCache* cache = NavDataCache::instance();
643 if (cache->isReadOnly()) {
648 if (!XMLLoader::findAirportData(ident(), "twr", path)) {
649 return; // no XML tower data
652 if (!cache->isCachedFileModified(path)) {
653 // cached values are correct, we're all done
657 flightgear::NavDataCache::Transaction txn(cache);
658 SGPropertyNode_ptr rootNode = new SGPropertyNode;
659 readProperties(path.str(), rootNode);
660 const_cast<FGAirport*>(this)->readTowerData(rootNode);
661 cache->stampCacheFile(path);
665 void FGAirport::readTowerData(SGPropertyNode* aRoot)
667 SGPropertyNode* twrNode = aRoot->getChild("tower")->getChild("twr");
668 double lat = twrNode->getDoubleValue("lat"),
669 lon = twrNode->getDoubleValue("lon"),
670 elevM = twrNode->getDoubleValue("elev-m");
671 // tower elevation is AGL, not AMSL. Since we don't want to depend on the
672 // scenery for a precise terrain elevation, we use the field elevation
673 // (this is also what the apt.dat code does)
674 double fieldElevationM = geod().getElevationM();
675 SGGeod towerLocation(SGGeod::fromDegM(lon, lat, fieldElevationM + elevM));
677 NavDataCache* cache = NavDataCache::instance();
678 PositionedIDVec towers = cache->airportItemsOfType(guid(), FGPositioned::TOWER);
679 if (towers.empty()) {
680 cache->insertTower(guid(), towerLocation);
682 // update the position
683 cache->updatePosition(towers.front(), towerLocation);
687 bool FGAirport::validateILSData()
689 if (mILSDataLoaded) {
693 mILSDataLoaded = true;
694 NavDataCache* cache = NavDataCache::instance();
695 if (cache->isReadOnly()) {
700 if (!XMLLoader::findAirportData(ident(), "ils", path)) {
701 return false; // no XML tower data
704 if (!cache->isCachedFileModified(path)) {
705 // cached values are correct, we're all done
709 SGPropertyNode_ptr rootNode = new SGPropertyNode;
710 readProperties(path.str(), rootNode);
712 flightgear::NavDataCache::Transaction txn(cache);
713 readILSData(rootNode);
714 cache->stampCacheFile(path);
717 // we loaded data, tell the caller it might need to reload things
721 void FGAirport::readILSData(SGPropertyNode* aRoot)
723 NavDataCache* cache = NavDataCache::instance();
725 // find the entry matching the runway
726 SGPropertyNode* runwayNode, *ilsNode;
727 for (int i=0; (runwayNode = aRoot->getChild("runway", i)) != NULL; ++i) {
728 for (int j=0; (ilsNode = runwayNode->getChild("ils", j)) != NULL; ++j) {
729 // must match on both nav-ident and runway ident, to support the following:
730 // - runways with multiple distinct ILS installations (KEWD, for example)
731 // - runways where both ends share the same nav ident (LFAT, for example)
732 PositionedID ils = cache->findILS(guid(), ilsNode->getStringValue("rwy"),
733 ilsNode->getStringValue("nav-id"));
735 SG_LOG(SG_GENERAL, SG_INFO, "reading ILS data for " << ident() <<
736 ", couldn;t find runway/navaid for:" <<
737 ilsNode->getStringValue("rwy") << "/" <<
738 ilsNode->getStringValue("nav-id"));
742 double hdgDeg = ilsNode->getDoubleValue("hdg-deg"),
743 lon = ilsNode->getDoubleValue("lon"),
744 lat = ilsNode->getDoubleValue("lat"),
745 elevM = ilsNode->getDoubleValue("elev-m");
747 cache->updateILS(ils, SGGeod::fromDegM(lon, lat, elevM), hdgDeg);
748 } // of ILS iteration
749 } // of runway iteration
752 void FGAirport::addSID(flightgear::SID* aSid)
754 mSIDs.push_back(aSid);
757 void FGAirport::addSTAR(STAR* aStar)
759 mSTARs.push_back(aStar);
762 void FGAirport::addApproach(Approach* aApp)
764 mApproaches.push_back(aApp);
767 //------------------------------------------------------------------------------
768 unsigned int FGAirport::numSIDs() const
774 //------------------------------------------------------------------------------
775 flightgear::SID* FGAirport::getSIDByIndex(unsigned int aIndex) const
778 return mSIDs[aIndex];
781 //------------------------------------------------------------------------------
782 flightgear::SID* FGAirport::findSIDWithIdent(const std::string& aIdent) const
785 for (unsigned int i=0; i<mSIDs.size(); ++i) {
786 if (mSIDs[i]->ident() == aIdent) {
794 //------------------------------------------------------------------------------
795 flightgear::SIDList FGAirport::getSIDs() const
798 return flightgear::SIDList(mSIDs.begin(), mSIDs.end());
801 //------------------------------------------------------------------------------
802 unsigned int FGAirport::numSTARs() const
805 return mSTARs.size();
808 //------------------------------------------------------------------------------
809 STAR* FGAirport::getSTARByIndex(unsigned int aIndex) const
812 return mSTARs[aIndex];
815 //------------------------------------------------------------------------------
816 STAR* FGAirport::findSTARWithIdent(const std::string& aIdent) const
819 for (unsigned int i=0; i<mSTARs.size(); ++i) {
820 if (mSTARs[i]->ident() == aIdent) {
828 //------------------------------------------------------------------------------
829 STARList FGAirport::getSTARs() const
832 return STARList(mSTARs.begin(), mSTARs.end());
835 unsigned int FGAirport::numApproaches() const
838 return mApproaches.size();
841 //------------------------------------------------------------------------------
842 Approach* FGAirport::getApproachByIndex(unsigned int aIndex) const
845 return mApproaches[aIndex];
848 //------------------------------------------------------------------------------
849 Approach* FGAirport::findApproachWithIdent(const std::string& aIdent) const
852 for (unsigned int i=0; i<mApproaches.size(); ++i) {
853 if (mApproaches[i]->ident() == aIdent) {
854 return mApproaches[i];
861 //------------------------------------------------------------------------------
862 ApproachList FGAirport::getApproaches(ProcedureType type) const
865 if( type == PROCEDURE_INVALID )
866 return ApproachList(mApproaches.begin(), mApproaches.end());
869 for(size_t i = 0; i < mApproaches.size(); ++i)
871 if( mApproaches[i]->type() == type )
872 ret.push_back(mApproaches[i]);
878 FGAirport::commStations() const
880 NavDataCache* cache = NavDataCache::instance();
881 CommStationList result;
882 BOOST_FOREACH(PositionedID pos, cache->airportItemsOfType(guid(),
883 FGPositioned::FREQ_GROUND,
884 FGPositioned::FREQ_UNICOM))
886 result.push_back( loadById<CommStation>(pos) );
893 FGAirport::commStationsOfType(FGPositioned::Type aTy) const
895 NavDataCache* cache = NavDataCache::instance();
896 CommStationList result;
897 BOOST_FOREACH(PositionedID pos, cache->airportItemsOfType(guid(), aTy)) {
898 result.push_back( loadById<CommStation>(pos) );
904 class AirportWithSize
907 AirportWithSize(FGPositionedRef pos) :
911 assert(pos->type() == FGPositioned::AIRPORT);
912 FGAirport* apt = static_cast<FGAirport*>(pos.get());
913 BOOST_FOREACH(FGRunway* rwy, apt->getRunwaysWithoutReciprocals()) {
914 _sizeMetric += static_cast<int>(rwy->lengthFt());
918 bool operator<(const AirportWithSize& other) const
920 return _sizeMetric < other._sizeMetric;
923 FGPositionedRef pos() const
926 FGPositionedRef _pos;
927 unsigned int _sizeMetric;
931 void FGAirport::sortBySize(FGPositionedList& airportList)
933 std::vector<AirportWithSize> annotated;
934 BOOST_FOREACH(FGPositionedRef p, airportList) {
935 annotated.push_back(AirportWithSize(p));
937 std::sort(annotated.begin(), annotated.end());
939 for (unsigned int i=0; i<annotated.size(); ++i) {
940 airportList[i] = annotated[i].pos();
944 // get airport elevation
945 double fgGetAirportElev( const std::string& id )
947 const FGAirport *a=fgFindAirportID( id);
949 return a->getElevation();
956 // get airport position
957 SGGeod fgGetAirportPos( const std::string& id )
959 const FGAirport *a = fgFindAirportID( id);
962 return SGGeod::fromDegM(a->getLongitude(), a->getLatitude(), a->getElevation());
964 return SGGeod::fromDegM(0.0, 0.0, -9999.0);