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),
80 mRunwaysLoaded(false),
81 mHelipadsLoaded(false),
82 mTaxiwaysLoaded(false),
83 mProceduresLoaded(false),
84 mThresholdDataLoaded(false),
90 FGAirport::~FGAirport()
95 bool FGAirport::isAirport() const
97 return type() == AIRPORT;
100 bool FGAirport::isSeaport() const
102 return type() == SEAPORT;
105 bool FGAirport::isHeliport() const
107 return type() == HELIPORT;
110 bool FGAirport::isAirportType(FGPositioned* pos)
116 return (pos->type() >= AIRPORT) && (pos->type() <= SEAPORT);
119 FGAirportDynamics * FGAirport::getDynamics()
125 _dynamics = new FGAirportDynamics(this);
126 XMLLoader::load(_dynamics);
129 FGRunwayPreference rwyPrefs(this);
130 XMLLoader::load(&rwyPrefs);
131 _dynamics->setRwyUse(rwyPrefs);
136 //------------------------------------------------------------------------------
137 unsigned int FGAirport::numRunways() const
140 return mRunways.size();
143 //------------------------------------------------------------------------------
144 unsigned int FGAirport::numHelipads() const
147 return mHelipads.size();
150 //------------------------------------------------------------------------------
151 FGRunwayRef FGAirport::getRunwayByIndex(unsigned int aIndex) const
154 return mRunways.at(aIndex);
157 //------------------------------------------------------------------------------
158 FGHelipadRef FGAirport::getHelipadByIndex(unsigned int aIndex) const
161 return loadById<FGHelipad>(mHelipads, aIndex);
164 //------------------------------------------------------------------------------
165 FGRunwayMap FGAirport::getRunwayMap() const
170 double minLengthFt = fgGetDouble("/sim/navdb/min-runway-length-ft");
172 BOOST_FOREACH(FGRunwayRef rwy, mRunways)
174 // ignore unusably short runways
175 // TODO other methods don't check this...
176 if( rwy->lengthFt() >= minLengthFt )
177 map[ rwy->ident() ] = rwy;
183 //------------------------------------------------------------------------------
184 FGHelipadMap FGAirport::getHelipadMap() const
189 BOOST_FOREACH(PositionedID id, mHelipads)
191 FGHelipad* rwy = loadById<FGHelipad>(id);
192 map[ rwy->ident() ] = rwy;
198 //------------------------------------------------------------------------------
199 bool FGAirport::hasRunwayWithIdent(const std::string& aIdent) const
202 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
203 if (rwy->ident() == aIdent) {
211 //------------------------------------------------------------------------------
212 bool FGAirport::hasHelipadWithIdent(const std::string& aIdent) const
214 return flightgear::NavDataCache::instance()
215 ->airportItemWithIdent(guid(), FGPositioned::HELIPAD, aIdent) != 0;
218 //------------------------------------------------------------------------------
219 FGRunwayRef FGAirport::getRunwayByIdent(const std::string& aIdent) const
222 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
223 if (rwy->ident() == aIdent) {
228 SG_LOG(SG_GENERAL, SG_ALERT, "no such runway '" << aIdent << "' at airport " << ident());
229 throw sg_range_exception("unknown runway " + aIdent + " at airport:" + ident(), "FGAirport::getRunwayByIdent");
232 //------------------------------------------------------------------------------
233 FGHelipadRef FGAirport::getHelipadByIdent(const std::string& aIdent) const
235 PositionedID id = flightgear::NavDataCache::instance()->airportItemWithIdent(guid(), FGPositioned::HELIPAD, aIdent);
237 SG_LOG(SG_GENERAL, SG_ALERT, "no such helipad '" << aIdent << "' at airport " << ident());
238 throw sg_range_exception("unknown helipad " + aIdent + " at airport:" + ident(), "FGAirport::getRunwayByIdent");
241 return loadById<FGHelipad>(id);
244 //------------------------------------------------------------------------------
245 FGRunwayRef FGAirport::findBestRunwayForHeading(double aHeading, struct FindBestRunwayForHeadingParams * parms ) const
249 FGRunway* result = NULL;
250 double currentBestQuality = 0.0;
252 struct FindBestRunwayForHeadingParams fbrfhp;
253 if( NULL != parms ) fbrfhp = *parms;
255 SGPropertyNode_ptr searchNode = fgGetNode("/sim/airport/runways/search");
256 if( searchNode.valid() ) {
257 fbrfhp.lengthWeight = searchNode->getDoubleValue("length-weight", fbrfhp.lengthWeight );
258 fbrfhp.widthWeight = searchNode->getDoubleValue("width-weight", fbrfhp.widthWeight );
259 fbrfhp.surfaceWeight = searchNode->getDoubleValue("surface-weight", fbrfhp.surfaceWeight );
260 fbrfhp.deviationWeight = searchNode->getDoubleValue("deviation-weight", fbrfhp.deviationWeight );
261 fbrfhp.ilsWeight = searchNode->getDoubleValue("ils-weight", fbrfhp.ilsWeight );
264 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
265 double good = rwy->score( fbrfhp.lengthWeight, fbrfhp.widthWeight, fbrfhp.surfaceWeight, fbrfhp.ilsWeight );
266 double dev = aHeading - rwy->headingDeg();
267 SG_NORMALIZE_RANGE(dev, -180.0, 180.0);
268 double bad = fabs( fbrfhp.deviationWeight * dev) + 1e-20;
269 double quality = good / bad;
271 if (quality > currentBestQuality) {
272 currentBestQuality = quality;
280 //------------------------------------------------------------------------------
281 FGRunwayRef FGAirport::findBestRunwayForPos(const SGGeod& aPos) const
285 FGRunway* result = NULL;
286 double currentLowestDev = 180.0;
288 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
289 double inboundCourse = SGGeodesy::courseDeg(aPos, rwy->end());
290 double dev = inboundCourse - rwy->headingDeg();
291 SG_NORMALIZE_RANGE(dev, -180.0, 180.0);
294 if (dev < currentLowestDev) { // new best match
295 currentLowestDev = dev;
298 } // of runway iteration
304 //------------------------------------------------------------------------------
305 bool FGAirport::hasHardRunwayOfLengthFt(double aLengthFt) const
309 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
310 if (rwy->isHardSurface() && (rwy->lengthFt() >= aLengthFt)) {
311 return true; // we're done!
313 } // of runways iteration
318 FGRunwayRef FGAirport::longestRunway() const
323 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
324 if (!r || (r->lengthFt() < rwy->lengthFt())) {
327 } // of runways iteration
332 //------------------------------------------------------------------------------
333 FGRunwayList FGAirport::getRunways() const
340 //------------------------------------------------------------------------------
341 FGRunwayList FGAirport::getRunwaysWithoutReciprocals() const
347 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
348 FGRunway* recip = rwy->reciprocalRunway();
350 FGRunwayList::iterator it = std::find(r.begin(), r.end(), recip);
352 continue; // reciprocal already in result set, don't include us
362 //------------------------------------------------------------------------------
363 unsigned int FGAirport::numTaxiways() const
366 return mTaxiways.size();
369 //------------------------------------------------------------------------------
370 FGTaxiwayRef FGAirport::getTaxiwayByIndex(unsigned int aIndex) const
373 return loadById<FGTaxiway>(mTaxiways, aIndex);
376 //------------------------------------------------------------------------------
377 FGTaxiwayList FGAirport::getTaxiways() const
380 return loadAllById<FGTaxiway>(mTaxiways);
383 //------------------------------------------------------------------------------
384 unsigned int FGAirport::numPavements() const
387 return mPavements.size();
390 //------------------------------------------------------------------------------
391 FGPavementRef FGAirport::getPavementByIndex(unsigned int aIndex) const
394 return loadById<FGPavement>(mPavements, aIndex);
397 //------------------------------------------------------------------------------
398 FGPavementList FGAirport::getPavements() const
401 return loadAllById<FGPavement>(mPavements);
404 //------------------------------------------------------------------------------
405 FGRunwayRef FGAirport::getActiveRunwayForUsage() const
407 FGEnvironmentMgr* envMgr = (FGEnvironmentMgr *) globals->get_subsystem("environment");
409 // This forces West-facing rwys to be used in no-wind situations
410 // which is consistent with Flightgear's initial setup.
414 FGEnvironment stationWeather(envMgr->getEnvironment(geod()));
416 double windSpeed = stationWeather.get_wind_speed_kt();
417 if (windSpeed > 0.0) {
418 hdg = stationWeather.get_wind_from_heading_deg();
422 return findBestRunwayForHeading(hdg);
425 //------------------------------------------------------------------------------
426 FGAirportRef FGAirport::findClosest( const SGGeod& aPos,
430 AirportFilter aptFilter;
434 return static_pointer_cast<FGAirport>
436 FGPositioned::findClosest(aPos, aCuttofNm, filter)
440 FGAirport::HardSurfaceFilter::HardSurfaceFilter(double minLengthFt) :
441 mMinLengthFt(minLengthFt)
443 if (minLengthFt < 0.0) {
444 mMinLengthFt = fgGetDouble("/sim/navdb/min-runway-length-ft", 0.0);
448 bool FGAirport::HardSurfaceFilter::passAirport(FGAirport* aApt) const
450 return aApt->hasHardRunwayOfLengthFt(mMinLengthFt);
453 //------------------------------------------------------------------------------
454 FGAirport::TypeRunwayFilter::TypeRunwayFilter():
455 _type(FGPositioned::AIRPORT),
456 _min_runway_length_ft( fgGetDouble("/sim/navdb/min-runway-length-ft", 0.0) )
461 //------------------------------------------------------------------------------
462 bool FGAirport::TypeRunwayFilter::fromTypeString(const std::string& type)
464 if( type == "heliport" ) _type = FGPositioned::HELIPORT;
465 else if( type == "seaport" ) _type = FGPositioned::SEAPORT;
466 else if( type == "airport" ) _type = FGPositioned::AIRPORT;
472 //------------------------------------------------------------------------------
473 bool FGAirport::TypeRunwayFilter::pass(FGPositioned* pos) const
475 FGAirport* apt = static_cast<FGAirport*>(pos);
476 if( (apt->type() == FGPositioned::AIRPORT)
477 && !apt->hasHardRunwayOfLengthFt(_min_runway_length_ft)
484 //------------------------------------------------------------------------------
485 FGAirportRef FGAirport::findByIdent(const std::string& aIdent)
487 AirportCache::iterator it = airportCache.find(aIdent);
488 if (it != airportCache.end())
492 FGAirportRef r = static_pointer_cast<FGAirport>
494 FGPositioned::findFirstWithIdent(aIdent, &filter)
497 // add airport to the cache (even when it's NULL, so we don't need to search in vain again)
498 airportCache[aIdent] = r;
500 // we don't warn here when r==NULL, let the caller do that
504 //------------------------------------------------------------------------------
505 FGAirportRef FGAirport::getByIdent(const std::string& aIdent)
507 FGAirportRef r = findByIdent(aIdent);
509 throw sg_range_exception("No such airport with ident: " + aIdent);
513 char** FGAirport::searchNamesAndIdents(const std::string& aFilter)
515 return NavDataCache::instance()->searchAirportNamesAndIdents(aFilter);
518 // find basic airport location info from airport database
519 const FGAirport *fgFindAirportID( const std::string& id)
525 return FGAirport::findByIdent(id);
528 PositionedIDVec FGAirport::itemsOfType(FGPositioned::Type ty) const
530 flightgear::NavDataCache* cache = flightgear::NavDataCache::instance();
531 return cache->airportItemsOfType(guid(), ty);
534 void FGAirport::loadRunways() const
536 if (mRunwaysLoaded) {
537 return; // already loaded, great
540 loadSceneryDefinitions();
542 mRunwaysLoaded = true;
543 PositionedIDVec rwys(itemsOfType(FGPositioned::RUNWAY));
544 BOOST_FOREACH(PositionedID id, rwys) {
545 mRunways.push_back(loadById<FGRunway>(id));
549 void FGAirport::loadHelipads() const
551 if (mHelipadsLoaded) {
552 return; // already loaded, great
555 mHelipadsLoaded = true;
556 mHelipads = itemsOfType(FGPositioned::HELIPAD);
559 void FGAirport::loadTaxiways() const
561 if (mTaxiwaysLoaded) {
562 return; // already loaded, great
565 mTaxiwaysLoaded = true;
566 mTaxiways = itemsOfType(FGPositioned::TAXIWAY);
569 void FGAirport::loadProcedures() const
571 if (mProceduresLoaded) {
575 mProceduresLoaded = true;
577 if (!XMLLoader::findAirportData(ident(), "procedures", path)) {
578 SG_LOG(SG_GENERAL, SG_INFO, "no procedures data available for " << ident());
582 SG_LOG(SG_GENERAL, SG_INFO, ident() << ": loading procedures from " << path.str());
583 RouteBase::loadAirportProcedures(path, const_cast<FGAirport*>(this));
586 void FGAirport::loadSceneryDefinitions() const
588 if (mThresholdDataLoaded) {
592 mThresholdDataLoaded = true;
595 if (!XMLLoader::findAirportData(ident(), "threshold", path)) {
596 return; // no XML threshold data
600 SGPropertyNode_ptr rootNode = new SGPropertyNode;
601 readProperties(path.str(), rootNode);
602 const_cast<FGAirport*>(this)->readThresholdData(rootNode);
603 } catch (sg_exception& e) {
604 SG_LOG(SG_NAVAID, SG_WARN, ident() << "loading threshold XML failed:" << e.getFormattedMessage());
608 void FGAirport::readThresholdData(SGPropertyNode* aRoot)
610 SGPropertyNode* runway;
612 for (; (runway = aRoot->getChild("runway", runwayIndex)) != NULL; ++runwayIndex) {
613 SGPropertyNode* t0 = runway->getChild("threshold", 0),
614 *t1 = runway->getChild("threshold", 1);
616 assert(t1); // too strict? maybe we should finally allow single-ended runways
618 processThreshold(t0);
619 processThreshold(t1);
620 } // of runways iteration
623 void FGAirport::processThreshold(SGPropertyNode* aThreshold)
625 // first, let's identify the current runway
626 std::string rwyIdent(aThreshold->getStringValue("rwy"));
627 NavDataCache* cache = NavDataCache::instance();
628 PositionedID id = cache->airportItemWithIdent(guid(), FGPositioned::RUNWAY, rwyIdent);
630 double lon = aThreshold->getDoubleValue("lon"),
631 lat = aThreshold->getDoubleValue("lat");
632 SGGeod newThreshold(SGGeod::fromDegM(lon, lat, elevationM()));
634 double newHeading = aThreshold->getDoubleValue("hdg-deg");
635 double newDisplacedThreshold = aThreshold->getDoubleValue("displ-m");
636 double newStopway = aThreshold->getDoubleValue("stopw-m");
639 SG_LOG(SG_GENERAL, SG_DEBUG, "FGAirport::processThreshold: "
640 "found runway not defined in the global data:" << ident() << "/" << rwyIdent);
641 // enable this code when threshold.xml contains sufficient data to
642 // fully specify a new runway, *and* we figure out how to assign runtime
643 // Positioned IDs and insert temporary items into the spatial map.
645 double newLength = 0.0, newWidth = 0.0;
647 FGRunway* rwy = new FGRunway(id, guid(), rwyIdent, newThreshold,
650 newDisplacedThreshold, newStopway,
652 // insert into the spatial map too
653 mRunways.push_back(rwy);
656 FGRunway* rwy = loadById<FGRunway>(id);
657 rwy->updateThreshold(newThreshold, newHeading,
658 newDisplacedThreshold, newStopway);
663 SGGeod FGAirport::getTowerLocation() const
666 return mTowerPosition;
669 void FGAirport::validateTowerData() const
671 if (mTowerDataLoaded) {
675 mTowerDataLoaded = true;
677 // first, load data from the cache (apt.dat)
678 NavDataCache* cache = NavDataCache::instance();
679 PositionedIDVec towers = cache->airportItemsOfType(guid(), FGPositioned::TOWER);
680 if (towers.empty()) {
682 mTowerPosition = geod(); // use airport position
684 // offset the tower position away from the runway centerline, if
685 // airport has a single runway. Offset by eight times the runway width,
686 // an entirely guessed figure.
687 if (numRunways() <= 2) {
688 FGRunway* runway = getRunwayByIndex(0);
689 double hdg = runway->headingDeg() + 90;
690 mTowerPosition = SGGeodesy::direct(geod(), hdg, runway->widthM() * 8);
693 // increase tower elevation by 20 metres above the field elevation
694 mTowerPosition.setElevationM(geod().getElevationM() + 20.0);
696 FGPositionedRef tower = cache->loadById(towers.front());
697 mTowerPosition = tower->geod();
702 if (!XMLLoader::findAirportData(ident(), "twr", path)) {
703 return; // no XML tower data, base position is fine
707 SGPropertyNode_ptr rootNode = new SGPropertyNode;
708 readProperties(path.str(), rootNode);
709 const_cast<FGAirport*>(this)->readTowerData(rootNode);
711 } catch (sg_exception& e){
712 SG_LOG(SG_NAVAID, SG_WARN, ident() << "loading twr XML failed:" << e.getFormattedMessage());
716 void FGAirport::readTowerData(SGPropertyNode* aRoot)
718 SGPropertyNode* twrNode = aRoot->getChild("tower")->getChild("twr");
719 double lat = twrNode->getDoubleValue("lat"),
720 lon = twrNode->getDoubleValue("lon"),
721 elevM = twrNode->getDoubleValue("elev-m");
722 // tower elevation is AGL, not AMSL. Since we don't want to depend on the
723 // scenery for a precise terrain elevation, we use the field elevation
724 // (this is also what the apt.dat code does)
725 double fieldElevationM = geod().getElevationM();
726 mTowerPosition = SGGeod::fromDegM(lon, lat, fieldElevationM + elevM);
729 void FGAirport::validateILSData()
731 if (mILSDataLoaded) {
735 // to avoid re-entrancy on this code-path, ensure we set loaded
737 mILSDataLoaded = true;
740 if (!XMLLoader::findAirportData(ident(), "ils", path)) {
741 return; // no XML tower data
745 SGPropertyNode_ptr rootNode = new SGPropertyNode;
746 readProperties(path.str(), rootNode);
747 readILSData(rootNode);
748 } catch (sg_exception& e){
749 SG_LOG(SG_NAVAID, SG_WARN, ident() << "loading ils XML failed:" << e.getFormattedMessage());
753 bool FGAirport::hasTower() const
759 void FGAirport::readILSData(SGPropertyNode* aRoot)
761 NavDataCache* cache = NavDataCache::instance();
762 // find the entry matching the runway
763 SGPropertyNode* runwayNode, *ilsNode;
764 for (int i=0; (runwayNode = aRoot->getChild("runway", i)) != NULL; ++i) {
765 for (int j=0; (ilsNode = runwayNode->getChild("ils", j)) != NULL; ++j) {
766 // must match on both nav-ident and runway ident, to support the following:
767 // - runways with multiple distinct ILS installations (KEWD, for example)
768 // - runways where both ends share the same nav ident (LFAT, for example)
769 PositionedID ils = cache->findILS(guid(), ilsNode->getStringValue("rwy"),
770 ilsNode->getStringValue("nav-id"));
772 SG_LOG(SG_GENERAL, SG_INFO, "reading ILS data for " << ident() <<
773 ", couldn't find runway/navaid for:" <<
774 ilsNode->getStringValue("rwy") << "/" <<
775 ilsNode->getStringValue("nav-id"));
779 double hdgDeg = ilsNode->getDoubleValue("hdg-deg"),
780 lon = ilsNode->getDoubleValue("lon"),
781 lat = ilsNode->getDoubleValue("lat"),
782 elevM = ilsNode->getDoubleValue("elev-m");
784 FGNavRecordRef nav(FGPositioned::loadById<FGNavRecord>(ils));
786 nav->updateFromXML(SGGeod::fromDegM(lon, lat, elevM), hdgDeg);
787 } // of ILS iteration
788 } // of runway iteration
791 void FGAirport::addSID(flightgear::SID* aSid)
793 mSIDs.push_back(aSid);
796 void FGAirport::addSTAR(STAR* aStar)
798 mSTARs.push_back(aStar);
801 void FGAirport::addApproach(Approach* aApp)
803 mApproaches.push_back(aApp);
806 //------------------------------------------------------------------------------
807 unsigned int FGAirport::numSIDs() const
813 //------------------------------------------------------------------------------
814 flightgear::SID* FGAirport::getSIDByIndex(unsigned int aIndex) const
817 return mSIDs[aIndex];
820 //------------------------------------------------------------------------------
821 flightgear::SID* FGAirport::findSIDWithIdent(const std::string& aIdent) const
824 for (unsigned int i=0; i<mSIDs.size(); ++i) {
825 if (mSIDs[i]->ident() == aIdent) {
833 //------------------------------------------------------------------------------
834 flightgear::SIDList FGAirport::getSIDs() const
837 return flightgear::SIDList(mSIDs.begin(), mSIDs.end());
840 //------------------------------------------------------------------------------
841 unsigned int FGAirport::numSTARs() const
844 return mSTARs.size();
847 //------------------------------------------------------------------------------
848 STAR* FGAirport::getSTARByIndex(unsigned int aIndex) const
851 return mSTARs[aIndex];
854 //------------------------------------------------------------------------------
855 STAR* FGAirport::findSTARWithIdent(const std::string& aIdent) const
858 for (unsigned int i=0; i<mSTARs.size(); ++i) {
859 if (mSTARs[i]->ident() == aIdent) {
867 //------------------------------------------------------------------------------
868 STARList FGAirport::getSTARs() const
871 return STARList(mSTARs.begin(), mSTARs.end());
874 unsigned int FGAirport::numApproaches() const
877 return mApproaches.size();
880 //------------------------------------------------------------------------------
881 Approach* FGAirport::getApproachByIndex(unsigned int aIndex) const
884 return mApproaches[aIndex];
887 //------------------------------------------------------------------------------
888 Approach* FGAirport::findApproachWithIdent(const std::string& aIdent) const
891 for (unsigned int i=0; i<mApproaches.size(); ++i) {
892 if (mApproaches[i]->ident() == aIdent) {
893 return mApproaches[i];
900 //------------------------------------------------------------------------------
901 ApproachList FGAirport::getApproaches(ProcedureType type) const
904 if( type == PROCEDURE_INVALID )
905 return ApproachList(mApproaches.begin(), mApproaches.end());
908 for(size_t i = 0; i < mApproaches.size(); ++i)
910 if( mApproaches[i]->type() == type )
911 ret.push_back(mApproaches[i]);
917 FGAirport::commStations() const
919 NavDataCache* cache = NavDataCache::instance();
920 CommStationList result;
921 BOOST_FOREACH(PositionedID pos, cache->airportItemsOfType(guid(),
922 FGPositioned::FREQ_GROUND,
923 FGPositioned::FREQ_UNICOM))
925 result.push_back( loadById<CommStation>(pos) );
932 FGAirport::commStationsOfType(FGPositioned::Type aTy) const
934 NavDataCache* cache = NavDataCache::instance();
935 CommStationList result;
936 BOOST_FOREACH(PositionedID pos, cache->airportItemsOfType(guid(), aTy)) {
937 result.push_back( loadById<CommStation>(pos) );
943 class AirportWithSize
946 AirportWithSize(FGPositionedRef pos) :
950 assert(pos->type() == FGPositioned::AIRPORT);
951 FGAirport* apt = static_cast<FGAirport*>(pos.get());
952 BOOST_FOREACH(FGRunway* rwy, apt->getRunwaysWithoutReciprocals()) {
953 _sizeMetric += static_cast<int>(rwy->lengthFt());
957 bool operator<(const AirportWithSize& other) const
959 return _sizeMetric < other._sizeMetric;
962 FGPositionedRef pos() const
965 FGPositionedRef _pos;
966 unsigned int _sizeMetric;
970 void FGAirport::sortBySize(FGPositionedList& airportList)
972 std::vector<AirportWithSize> annotated;
973 BOOST_FOREACH(FGPositionedRef p, airportList) {
974 annotated.push_back(AirportWithSize(p));
976 std::sort(annotated.begin(), annotated.end());
978 for (unsigned int i=0; i<annotated.size(); ++i) {
979 airportList[i] = annotated[i].pos();
983 // get airport elevation
984 double fgGetAirportElev( const std::string& id )
986 const FGAirport *a=fgFindAirportID( id);
988 return a->getElevation();
995 // get airport position
996 SGGeod fgGetAirportPos( const std::string& id )
998 const FGAirport *a = fgFindAirportID( id);
1001 return SGGeod::fromDegM(a->getLongitude(), a->getLatitude(), a->getElevation());
1003 return SGGeod::fromDegM(0.0, 0.0, -9999.0);