1 // poidb.cxx -- points of interest management routines
3 // Written by Christian Schmitt, March 2013
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include <simgear/compiler.h>
26 #include <simgear/debug/logstream.hxx>
27 #include <simgear/math/sg_geodesy.hxx>
28 #include <simgear/misc/sg_path.hxx>
29 #include <simgear/structure/exception.hxx>
30 #include <simgear/misc/sgstream.hxx>
32 #include <Navaids/NavDataCache.hxx>
37 static FGPositioned::Type
38 mapPOITypeToFGPType(int aTy)
41 case 10: return FGPositioned::COUNTRY;
42 case 12: return FGPositioned::CITY;
43 case 13: return FGPositioned::TOWN;
44 case 14: return FGPositioned::VILLAGE;
46 throw sg_range_exception("Unknown POI type", "FGNavDataCache::readPOIFromStream");
55 static PositionedID readPOIFromStream(std::istream& aStream,
56 FGPositioned::Type type = FGPositioned::INVALID)
58 NavDataCache* cache = NavDataCache::instance();
62 if (aStream.eof() || (rawType == '#')) {
68 aStream >> lat >> lon;
69 getline(aStream, name);
71 SGGeod pos(SGGeod::fromDeg(lon, lat));
72 name = simgear::strutils::strip(name);
74 // the type can be forced by our caller, but normally we use the value
75 // supplied in the .dat file
76 if (type == FGPositioned::INVALID) {
77 type = mapPOITypeToFGPType(rawType);
79 if (type == FGPositioned::INVALID) {
83 PositionedID r = cache->createPOI(type, name, pos);
87 // load and initialize the POI database
88 bool poiDBInit(const SGPath& path)
90 sg_gzifstream in( path.str() );
91 if ( !in.is_open() ) {
92 SG_LOG( SG_NAVAID, SG_ALERT, "Cannot open file: " << path.str() );
99 readPOIFromStream(in);
101 } // of stream data loop
106 } // of namespace flightgear