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>
55 #include <Navaids/navrecord.hxx>
60 using namespace flightgear;
62 /***************************************************************************
64 ***************************************************************************/
66 AirportCache FGAirport::airportCache;
68 FGAirport::FGAirport( PositionedID aGuid,
69 const std::string &id,
70 const SGGeod& location,
71 const std::string &name,
74 FGPositioned(aGuid, aType, id, location),
76 _has_metar(has_metar),
78 mTowerDataLoaded(false),
79 mRunwaysLoaded(false),
80 mHelipadsLoaded(false),
81 mTaxiwaysLoaded(false),
82 mProceduresLoaded(false),
83 mThresholdDataLoaded(false),
89 FGAirport::~FGAirport()
94 bool FGAirport::isAirport() const
96 return type() == AIRPORT;
99 bool FGAirport::isSeaport() const
101 return type() == SEAPORT;
104 bool FGAirport::isHeliport() const
106 return type() == HELIPORT;
109 bool FGAirport::isAirportType(FGPositioned* pos)
115 return (pos->type() >= AIRPORT) && (pos->type() <= SEAPORT);
118 FGAirportDynamics * FGAirport::getDynamics()
124 _dynamics = new FGAirportDynamics(this);
125 XMLLoader::load(_dynamics);
128 FGRunwayPreference rwyPrefs(this);
129 XMLLoader::load(&rwyPrefs);
130 _dynamics->setRwyUse(rwyPrefs);
135 //------------------------------------------------------------------------------
136 unsigned int FGAirport::numRunways() const
139 return mRunways.size();
142 //------------------------------------------------------------------------------
143 unsigned int FGAirport::numHelipads() const
146 return mHelipads.size();
149 //------------------------------------------------------------------------------
150 FGRunwayRef FGAirport::getRunwayByIndex(unsigned int aIndex) const
153 return mRunways.at(aIndex);
156 //------------------------------------------------------------------------------
157 FGHelipadRef FGAirport::getHelipadByIndex(unsigned int aIndex) const
160 return loadById<FGHelipad>(mHelipads, aIndex);
163 //------------------------------------------------------------------------------
164 FGRunwayMap FGAirport::getRunwayMap() const
169 double minLengthFt = fgGetDouble("/sim/navdb/min-runway-length-ft");
171 BOOST_FOREACH(FGRunwayRef rwy, mRunways)
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
201 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
202 if (rwy->ident() == aIdent) {
210 //------------------------------------------------------------------------------
211 bool FGAirport::hasHelipadWithIdent(const std::string& aIdent) const
213 return flightgear::NavDataCache::instance()
214 ->airportItemWithIdent(guid(), FGPositioned::HELIPAD, aIdent) != 0;
217 //------------------------------------------------------------------------------
218 FGRunwayRef FGAirport::getRunwayByIdent(const std::string& aIdent) const
221 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
222 if (rwy->ident() == aIdent) {
227 SG_LOG(SG_GENERAL, SG_ALERT, "no such runway '" << aIdent << "' at airport " << ident());
228 throw sg_range_exception("unknown runway " + aIdent + " at airport:" + ident(), "FGAirport::getRunwayByIdent");
231 //------------------------------------------------------------------------------
232 FGHelipadRef FGAirport::getHelipadByIdent(const std::string& aIdent) const
234 PositionedID id = flightgear::NavDataCache::instance()->airportItemWithIdent(guid(), FGPositioned::HELIPAD, aIdent);
236 SG_LOG(SG_GENERAL, SG_ALERT, "no such helipad '" << aIdent << "' at airport " << ident());
237 throw sg_range_exception("unknown helipad " + aIdent + " at airport:" + ident(), "FGAirport::getRunwayByIdent");
240 return loadById<FGHelipad>(id);
243 //------------------------------------------------------------------------------
244 FGRunwayRef FGAirport::findBestRunwayForHeading(double aHeading, struct FindBestRunwayForHeadingParams * parms ) const
248 FGRunway* result = NULL;
249 double currentBestQuality = 0.0;
251 struct FindBestRunwayForHeadingParams fbrfhp;
252 if( NULL != parms ) fbrfhp = *parms;
254 SGPropertyNode_ptr searchNode = fgGetNode("/sim/airport/runways/search");
255 if( searchNode.valid() ) {
256 fbrfhp.lengthWeight = searchNode->getDoubleValue("length-weight", fbrfhp.lengthWeight );
257 fbrfhp.widthWeight = searchNode->getDoubleValue("width-weight", fbrfhp.widthWeight );
258 fbrfhp.surfaceWeight = searchNode->getDoubleValue("surface-weight", fbrfhp.surfaceWeight );
259 fbrfhp.deviationWeight = searchNode->getDoubleValue("deviation-weight", fbrfhp.deviationWeight );
260 fbrfhp.ilsWeight = searchNode->getDoubleValue("ils-weight", fbrfhp.ilsWeight );
263 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
264 double good = rwy->score( fbrfhp.lengthWeight, fbrfhp.widthWeight, fbrfhp.surfaceWeight, fbrfhp.ilsWeight );
265 double dev = aHeading - rwy->headingDeg();
266 SG_NORMALIZE_RANGE(dev, -180.0, 180.0);
267 double bad = fabs( fbrfhp.deviationWeight * dev) + 1e-20;
268 double quality = good / bad;
270 if (quality > currentBestQuality) {
271 currentBestQuality = quality;
279 //------------------------------------------------------------------------------
280 FGRunwayRef FGAirport::findBestRunwayForPos(const SGGeod& aPos) const
284 FGRunway* result = NULL;
285 double currentLowestDev = 180.0;
287 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
288 double inboundCourse = SGGeodesy::courseDeg(aPos, rwy->end());
289 double dev = inboundCourse - rwy->headingDeg();
290 SG_NORMALIZE_RANGE(dev, -180.0, 180.0);
293 if (dev < currentLowestDev) { // new best match
294 currentLowestDev = dev;
297 } // of runway iteration
303 //------------------------------------------------------------------------------
304 bool FGAirport::hasHardRunwayOfLengthFt(double aLengthFt) const
308 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
309 if (rwy->isHardSurface() && (rwy->lengthFt() >= aLengthFt)) {
310 return true; // we're done!
312 } // of runways iteration
317 //------------------------------------------------------------------------------
318 FGRunwayList FGAirport::getRunways() const
325 //------------------------------------------------------------------------------
326 FGRunwayList FGAirport::getRunwaysWithoutReciprocals() const
332 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
333 FGRunway* recip = rwy->reciprocalRunway();
335 FGRunwayList::iterator it = std::find(r.begin(), r.end(), recip);
337 continue; // reciprocal already in result set, don't include us
347 //------------------------------------------------------------------------------
348 unsigned int FGAirport::numTaxiways() const
351 return mTaxiways.size();
354 //------------------------------------------------------------------------------
355 FGTaxiwayRef FGAirport::getTaxiwayByIndex(unsigned int aIndex) const
358 return loadById<FGTaxiway>(mTaxiways, aIndex);
361 //------------------------------------------------------------------------------
362 FGTaxiwayList FGAirport::getTaxiways() const
365 return loadAllById<FGTaxiway>(mTaxiways);
368 //------------------------------------------------------------------------------
369 unsigned int FGAirport::numPavements() const
372 return mPavements.size();
375 //------------------------------------------------------------------------------
376 FGPavementRef FGAirport::getPavementByIndex(unsigned int aIndex) const
379 return loadById<FGPavement>(mPavements, aIndex);
382 //------------------------------------------------------------------------------
383 FGPavementList FGAirport::getPavements() const
386 return loadAllById<FGPavement>(mPavements);
389 //------------------------------------------------------------------------------
390 FGRunwayRef FGAirport::getActiveRunwayForUsage() const
392 FGEnvironmentMgr* envMgr = (FGEnvironmentMgr *) globals->get_subsystem("environment");
394 // This forces West-facing rwys to be used in no-wind situations
395 // which is consistent with Flightgear's initial setup.
399 FGEnvironment stationWeather(envMgr->getEnvironment(geod()));
401 double windSpeed = stationWeather.get_wind_speed_kt();
402 if (windSpeed > 0.0) {
403 hdg = stationWeather.get_wind_from_heading_deg();
407 return findBestRunwayForHeading(hdg);
410 //------------------------------------------------------------------------------
411 FGAirportRef FGAirport::findClosest( const SGGeod& aPos,
415 AirportFilter aptFilter;
419 return static_pointer_cast<FGAirport>
421 FGPositioned::findClosest(aPos, aCuttofNm, filter)
425 FGAirport::HardSurfaceFilter::HardSurfaceFilter(double minLengthFt) :
426 mMinLengthFt(minLengthFt)
428 if (minLengthFt < 0.0) {
429 mMinLengthFt = fgGetDouble("/sim/navdb/min-runway-length-ft", 0.0);
433 bool FGAirport::HardSurfaceFilter::passAirport(FGAirport* aApt) const
435 return aApt->hasHardRunwayOfLengthFt(mMinLengthFt);
438 //------------------------------------------------------------------------------
439 FGAirport::TypeRunwayFilter::TypeRunwayFilter():
440 _type(FGPositioned::AIRPORT),
441 _min_runway_length_ft( fgGetDouble("/sim/navdb/min-runway-length-ft", 0.0) )
446 //------------------------------------------------------------------------------
447 bool FGAirport::TypeRunwayFilter::fromTypeString(const std::string& type)
449 if( type == "heliport" ) _type = FGPositioned::HELIPORT;
450 else if( type == "seaport" ) _type = FGPositioned::SEAPORT;
451 else if( type == "airport" ) _type = FGPositioned::AIRPORT;
457 //------------------------------------------------------------------------------
458 bool FGAirport::TypeRunwayFilter::pass(FGPositioned* pos) const
460 FGAirport* apt = static_cast<FGAirport*>(pos);
461 if( (apt->type() == FGPositioned::AIRPORT)
462 && !apt->hasHardRunwayOfLengthFt(_min_runway_length_ft)
469 //------------------------------------------------------------------------------
470 FGAirportRef FGAirport::findByIdent(const std::string& aIdent)
472 AirportCache::iterator it = airportCache.find(aIdent);
473 if (it != airportCache.end())
477 FGAirportRef r = static_pointer_cast<FGAirport>
479 FGPositioned::findFirstWithIdent(aIdent, &filter)
482 // add airport to the cache (even when it's NULL, so we don't need to search in vain again)
483 airportCache[aIdent] = r;
485 // we don't warn here when r==NULL, let the caller do that
489 //------------------------------------------------------------------------------
490 FGAirportRef FGAirport::getByIdent(const std::string& aIdent)
492 FGAirportRef r = findByIdent(aIdent);
494 throw sg_range_exception("No such airport with ident: " + aIdent);
498 char** FGAirport::searchNamesAndIdents(const std::string& aFilter)
500 return NavDataCache::instance()->searchAirportNamesAndIdents(aFilter);
503 // find basic airport location info from airport database
504 const FGAirport *fgFindAirportID( const std::string& id)
510 return FGAirport::findByIdent(id);
513 PositionedIDVec FGAirport::itemsOfType(FGPositioned::Type ty) const
515 flightgear::NavDataCache* cache = flightgear::NavDataCache::instance();
516 return cache->airportItemsOfType(guid(), ty);
519 void FGAirport::loadRunways() const
521 if (mRunwaysLoaded) {
522 return; // already loaded, great
525 loadSceneryDefinitions();
527 mRunwaysLoaded = true;
528 PositionedIDVec rwys(itemsOfType(FGPositioned::RUNWAY));
529 BOOST_FOREACH(PositionedID id, rwys) {
530 mRunways.push_back(loadById<FGRunway>(id));
534 void FGAirport::loadHelipads() const
536 if (mHelipadsLoaded) {
537 return; // already loaded, great
540 mHelipadsLoaded = true;
541 mHelipads = itemsOfType(FGPositioned::HELIPAD);
544 void FGAirport::loadTaxiways() const
546 if (mTaxiwaysLoaded) {
547 return; // already loaded, great
550 mTaxiwaysLoaded = true;
551 mTaxiways = itemsOfType(FGPositioned::TAXIWAY);
554 void FGAirport::loadProcedures() const
556 if (mProceduresLoaded) {
560 mProceduresLoaded = true;
562 if (!XMLLoader::findAirportData(ident(), "procedures", path)) {
563 SG_LOG(SG_GENERAL, SG_INFO, "no procedures data available for " << ident());
567 SG_LOG(SG_GENERAL, SG_INFO, ident() << ": loading procedures from " << path.str());
568 RouteBase::loadAirportProcedures(path, const_cast<FGAirport*>(this));
571 void FGAirport::loadSceneryDefinitions() const
573 if (mThresholdDataLoaded) {
577 mThresholdDataLoaded = true;
580 if (!XMLLoader::findAirportData(ident(), "threshold", path)) {
581 return; // no XML threshold data
585 SGPropertyNode_ptr rootNode = new SGPropertyNode;
586 readProperties(path.str(), rootNode);
587 const_cast<FGAirport*>(this)->readThresholdData(rootNode);
588 } catch (sg_exception& e) {
589 SG_LOG(SG_NAVAID, SG_WARN, ident() << "loading threshold XML failed:" << e.getFormattedMessage());
593 void FGAirport::readThresholdData(SGPropertyNode* aRoot)
595 SGPropertyNode* runway;
597 for (; (runway = aRoot->getChild("runway", runwayIndex)) != NULL; ++runwayIndex) {
598 SGPropertyNode* t0 = runway->getChild("threshold", 0),
599 *t1 = runway->getChild("threshold", 1);
601 assert(t1); // too strict? maybe we should finally allow single-ended runways
603 processThreshold(t0);
604 processThreshold(t1);
605 } // of runways iteration
608 void FGAirport::processThreshold(SGPropertyNode* aThreshold)
610 // first, let's identify the current runway
611 std::string rwyIdent(aThreshold->getStringValue("rwy"));
612 NavDataCache* cache = NavDataCache::instance();
613 PositionedID id = cache->airportItemWithIdent(guid(), FGPositioned::RUNWAY, rwyIdent);
615 double lon = aThreshold->getDoubleValue("lon"),
616 lat = aThreshold->getDoubleValue("lat");
617 SGGeod newThreshold(SGGeod::fromDegM(lon, lat, elevationM()));
619 double newHeading = aThreshold->getDoubleValue("hdg-deg");
620 double newDisplacedThreshold = aThreshold->getDoubleValue("displ-m");
621 double newStopway = aThreshold->getDoubleValue("stopw-m");
624 SG_LOG(SG_GENERAL, SG_DEBUG, "FGAirport::processThreshold: "
625 "found runway not defined in the global data:" << ident() << "/" << rwyIdent);
626 // enable this code when threshold.xml contains sufficient data to
627 // fully specify a new runway, *and* we figure out how to assign runtime
628 // Positioned IDs and insert temporary items into the spatial map.
630 double newLength = 0.0, newWidth = 0.0;
632 FGRunway* rwy = new FGRunway(id, guid(), rwyIdent, newThreshold,
635 newDisplacedThreshold, newStopway,
637 // insert into the spatial map too
638 mRunways.push_back(rwy);
641 FGRunway* rwy = loadById<FGRunway>(id);
642 rwy->updateThreshold(newThreshold, newHeading,
643 newDisplacedThreshold, newStopway);
648 SGGeod FGAirport::getTowerLocation() const
651 return mTowerPosition;
654 void FGAirport::validateTowerData() const
656 if (mTowerDataLoaded) {
660 mTowerDataLoaded = true;
662 // first, load data from the cache (apt.dat)
663 NavDataCache* cache = NavDataCache::instance();
664 PositionedIDVec towers = cache->airportItemsOfType(guid(), FGPositioned::TOWER);
665 if (towers.empty()) {
666 SG_LOG(SG_GENERAL, SG_ALERT, "No towers defined for:" <<ident());
667 mTowerPosition = geod(); // use airport position
668 // increase tower elevation by 20 metres above the field elevation
669 mTowerPosition.setElevationM(geod().getElevationM() + 20.0);
671 FGPositionedRef tower = cache->loadById(towers.front());
672 mTowerPosition = tower->geod();
676 if (!XMLLoader::findAirportData(ident(), "twr", path)) {
677 return; // no XML tower data, base position is fine
681 SGPropertyNode_ptr rootNode = new SGPropertyNode;
682 readProperties(path.str(), rootNode);
683 const_cast<FGAirport*>(this)->readTowerData(rootNode);
684 } catch (sg_exception& e){
685 SG_LOG(SG_NAVAID, SG_WARN, ident() << "loading twr XML failed:" << e.getFormattedMessage());
689 void FGAirport::readTowerData(SGPropertyNode* aRoot)
691 SGPropertyNode* twrNode = aRoot->getChild("tower")->getChild("twr");
692 double lat = twrNode->getDoubleValue("lat"),
693 lon = twrNode->getDoubleValue("lon"),
694 elevM = twrNode->getDoubleValue("elev-m");
695 // tower elevation is AGL, not AMSL. Since we don't want to depend on the
696 // scenery for a precise terrain elevation, we use the field elevation
697 // (this is also what the apt.dat code does)
698 double fieldElevationM = geod().getElevationM();
699 mTowerPosition = SGGeod::fromDegM(lon, lat, fieldElevationM + elevM);
702 void FGAirport::validateILSData()
704 if (mILSDataLoaded) {
708 // to avoid re-entrancy on this code-path, ensure we set loaded
710 mILSDataLoaded = true;
713 if (!XMLLoader::findAirportData(ident(), "ils", path)) {
714 return; // no XML tower data
718 SGPropertyNode_ptr rootNode = new SGPropertyNode;
719 readProperties(path.str(), rootNode);
720 readILSData(rootNode);
721 } catch (sg_exception& e){
722 SG_LOG(SG_NAVAID, SG_WARN, ident() << "loading ils XML failed:" << e.getFormattedMessage());
726 void FGAirport::readILSData(SGPropertyNode* aRoot)
728 NavDataCache* cache = NavDataCache::instance();
729 // find the entry matching the runway
730 SGPropertyNode* runwayNode, *ilsNode;
731 for (int i=0; (runwayNode = aRoot->getChild("runway", i)) != NULL; ++i) {
732 for (int j=0; (ilsNode = runwayNode->getChild("ils", j)) != NULL; ++j) {
733 // must match on both nav-ident and runway ident, to support the following:
734 // - runways with multiple distinct ILS installations (KEWD, for example)
735 // - runways where both ends share the same nav ident (LFAT, for example)
736 PositionedID ils = cache->findILS(guid(), ilsNode->getStringValue("rwy"),
737 ilsNode->getStringValue("nav-id"));
739 SG_LOG(SG_GENERAL, SG_INFO, "reading ILS data for " << ident() <<
740 ", couldn't find runway/navaid for:" <<
741 ilsNode->getStringValue("rwy") << "/" <<
742 ilsNode->getStringValue("nav-id"));
746 double hdgDeg = ilsNode->getDoubleValue("hdg-deg"),
747 lon = ilsNode->getDoubleValue("lon"),
748 lat = ilsNode->getDoubleValue("lat"),
749 elevM = ilsNode->getDoubleValue("elev-m");
751 FGNavRecordRef nav(FGPositioned::loadById<FGNavRecord>(ils));
753 nav->updateFromXML(SGGeod::fromDegM(lon, lat, elevM), hdgDeg);
754 } // of ILS iteration
755 } // of runway iteration
758 void FGAirport::addSID(flightgear::SID* aSid)
760 mSIDs.push_back(aSid);
763 void FGAirport::addSTAR(STAR* aStar)
765 mSTARs.push_back(aStar);
768 void FGAirport::addApproach(Approach* aApp)
770 mApproaches.push_back(aApp);
773 //------------------------------------------------------------------------------
774 unsigned int FGAirport::numSIDs() const
780 //------------------------------------------------------------------------------
781 flightgear::SID* FGAirport::getSIDByIndex(unsigned int aIndex) const
784 return mSIDs[aIndex];
787 //------------------------------------------------------------------------------
788 flightgear::SID* FGAirport::findSIDWithIdent(const std::string& aIdent) const
791 for (unsigned int i=0; i<mSIDs.size(); ++i) {
792 if (mSIDs[i]->ident() == aIdent) {
800 //------------------------------------------------------------------------------
801 flightgear::SIDList FGAirport::getSIDs() const
804 return flightgear::SIDList(mSIDs.begin(), mSIDs.end());
807 //------------------------------------------------------------------------------
808 unsigned int FGAirport::numSTARs() const
811 return mSTARs.size();
814 //------------------------------------------------------------------------------
815 STAR* FGAirport::getSTARByIndex(unsigned int aIndex) const
818 return mSTARs[aIndex];
821 //------------------------------------------------------------------------------
822 STAR* FGAirport::findSTARWithIdent(const std::string& aIdent) const
825 for (unsigned int i=0; i<mSTARs.size(); ++i) {
826 if (mSTARs[i]->ident() == aIdent) {
834 //------------------------------------------------------------------------------
835 STARList FGAirport::getSTARs() const
838 return STARList(mSTARs.begin(), mSTARs.end());
841 unsigned int FGAirport::numApproaches() const
844 return mApproaches.size();
847 //------------------------------------------------------------------------------
848 Approach* FGAirport::getApproachByIndex(unsigned int aIndex) const
851 return mApproaches[aIndex];
854 //------------------------------------------------------------------------------
855 Approach* FGAirport::findApproachWithIdent(const std::string& aIdent) const
858 for (unsigned int i=0; i<mApproaches.size(); ++i) {
859 if (mApproaches[i]->ident() == aIdent) {
860 return mApproaches[i];
867 //------------------------------------------------------------------------------
868 ApproachList FGAirport::getApproaches(ProcedureType type) const
871 if( type == PROCEDURE_INVALID )
872 return ApproachList(mApproaches.begin(), mApproaches.end());
875 for(size_t i = 0; i < mApproaches.size(); ++i)
877 if( mApproaches[i]->type() == type )
878 ret.push_back(mApproaches[i]);
884 FGAirport::commStations() const
886 NavDataCache* cache = NavDataCache::instance();
887 CommStationList result;
888 BOOST_FOREACH(PositionedID pos, cache->airportItemsOfType(guid(),
889 FGPositioned::FREQ_GROUND,
890 FGPositioned::FREQ_UNICOM))
892 result.push_back( loadById<CommStation>(pos) );
899 FGAirport::commStationsOfType(FGPositioned::Type aTy) const
901 NavDataCache* cache = NavDataCache::instance();
902 CommStationList result;
903 BOOST_FOREACH(PositionedID pos, cache->airportItemsOfType(guid(), aTy)) {
904 result.push_back( loadById<CommStation>(pos) );
910 class AirportWithSize
913 AirportWithSize(FGPositionedRef pos) :
917 assert(pos->type() == FGPositioned::AIRPORT);
918 FGAirport* apt = static_cast<FGAirport*>(pos.get());
919 BOOST_FOREACH(FGRunway* rwy, apt->getRunwaysWithoutReciprocals()) {
920 _sizeMetric += static_cast<int>(rwy->lengthFt());
924 bool operator<(const AirportWithSize& other) const
926 return _sizeMetric < other._sizeMetric;
929 FGPositionedRef pos() const
932 FGPositionedRef _pos;
933 unsigned int _sizeMetric;
937 void FGAirport::sortBySize(FGPositionedList& airportList)
939 std::vector<AirportWithSize> annotated;
940 BOOST_FOREACH(FGPositionedRef p, airportList) {
941 annotated.push_back(AirportWithSize(p));
943 std::sort(annotated.begin(), annotated.end());
945 for (unsigned int i=0; i<annotated.size(); ++i) {
946 airportList[i] = annotated[i].pos();
950 // get airport elevation
951 double fgGetAirportElev( const std::string& id )
953 const FGAirport *a=fgFindAirportID( id);
955 return a->getElevation();
962 // get airport position
963 SGGeod fgGetAirportPos( const std::string& id )
965 const FGAirport *a = fgFindAirportID( id);
968 return SGGeod::fromDegM(a->getLongitude(), a->getLatitude(), a->getElevation());
970 return SGGeod::fromDegM(0.0, 0.0, -9999.0);