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.
27 #include <simgear/compiler.h>
28 #include <simgear/debug/logstream.hxx>
29 #include <simgear/math/sg_geodesy.hxx>
30 #include <simgear/misc/sg_path.hxx>
31 #include <simgear/structure/exception.hxx>
32 #include <simgear/misc/sgstream.hxx>
34 #include <Navaids/NavDataCache.hxx>
39 static FGPositioned::Type
40 mapPOITypeToFGPType(int aTy)
43 case 10: return FGPositioned::COUNTRY;
44 case 12: return FGPositioned::CITY;
45 case 13: return FGPositioned::TOWN;
46 case 14: return FGPositioned::VILLAGE;
48 throw sg_range_exception("Unknown POI type", "FGNavDataCache::readPOIFromStream");
55 static PositionedID readPOIFromStream(std::istream& aStream, NavDataCache* cache,
56 FGPositioned::Type type = FGPositioned::INVALID)
63 if (aStream.peek() == '#') {
72 aStream >> lat >> lon;
73 getline(aStream, name);
75 SGGeod pos(SGGeod::fromDeg(lon, lat));
76 name = simgear::strutils::strip(name);
78 // the type can be forced by our caller, but normally we use the value
79 // supplied in the .dat file
80 if (type == FGPositioned::INVALID) {
81 type = mapPOITypeToFGPType(rawType);
83 if (type == FGPositioned::INVALID) {
87 return cache->createPOI(type, name, pos);
90 // load and initialize the POI database
91 bool poiDBInit(const SGPath& path)
93 sg_gzifstream in( path.str() );
94 if ( !in.is_open() ) {
95 SG_LOG( SG_NAVAID, SG_ALERT, "Cannot open file: " << path.str() );
99 NavDataCache* cache = NavDataCache::instance();
101 readPOIFromStream(in, cache);
102 } // of stream data loop
107 } // of namespace flightgear