]> git.mxchange.org Git - flightgear.git/commitdiff
Add points of interest (POI) database to FGPositioned. Useful for maps and GPS instru...
authorChristian Schmitt <chris@ilovelinux.de>
Sun, 3 Mar 2013 13:17:37 +0000 (14:17 +0100)
committerChristian Schmitt <chris@ilovelinux.de>
Sun, 3 Mar 2013 13:47:12 +0000 (14:47 +0100)
Can display country, city, towns and villages names worldwide.

src/Navaids/CMakeLists.txt
src/Navaids/NavDataCache.cxx
src/Navaids/poidb.cxx [new file with mode: 0644]
src/Navaids/poidb.hxx [new file with mode: 0644]
src/Navaids/positioned.cxx
src/Navaids/positioned.hxx

index 5d15dd3d40d3204e473473a764d9f8fb64e10e55..d611e1c16c4f5a734bdb1f0fac683ee64e166473 100644 (file)
@@ -7,6 +7,7 @@ set(SOURCES
        navdb.cxx
        navlist.cxx
        navrecord.cxx
+       poidb.cxx
        positioned.cxx
        procedure.cxx
        route.cxx
@@ -25,6 +26,7 @@ set(HEADERS
        navdb.hxx
        navlist.hxx
        navrecord.hxx
+       poidb.hxx
        positioned.hxx
        procedure.hxx
        route.hxx
@@ -41,4 +43,4 @@ if (NOT SYSTEM_SQLITE)
     list(APPEND HEADERS sqlite3.h)
 endif()
 
-flightgear_component(Navaids "${SOURCES}" "${HEADERS}")
\ No newline at end of file
+flightgear_component(Navaids "${SOURCES}" "${HEADERS}")
index aeb70cc30bd7b5870ce81ce54e4a4086d96b504b..2010743cd74cf0cfd6731798aeac21d5e366f99d 100644 (file)
@@ -60,6 +60,7 @@
 #include "PositionedOctree.hxx"
 #include <Airports/apt_loader.hxx>
 #include <Navaids/airways.hxx>
+#include "poidb.hxx"
 #include <Airports/parking.hxx>
 #include <Airports/gnnode.hxx>
 
@@ -949,7 +950,7 @@ public:
   bool transactionAborted;
   sqlite3_stmt_ptr beginTransactionStmt, commitTransactionStmt, rollbackTransactionStmt;
   
-  SGPath aptDatPath, metarDatPath, navDatPath, fixDatPath,
+  SGPath aptDatPath, metarDatPath, navDatPath, fixDatPath, poiDatPath,
   carrierDatPath, airwayDatPath;
   
   sqlite3_stmt_ptr readPropertyQuery, writePropertyQuery,
@@ -1070,6 +1071,7 @@ FGPositioned* NavDataCache::NavDataCachePrivate::loadById(sqlite3_int64 rowid)
     case FGPositioned::COUNTRY:
     case FGPositioned::CITY:
     case FGPositioned::TOWN:
+    case FGPositioned::VILLAGE:
     {
         FGPositioned* wpt = new FGPositioned(rowid, ty, ident, pos);
       return wpt;
@@ -1145,6 +1147,9 @@ NavDataCache::NavDataCache()
 
   d->fixDatPath = SGPath(globals->get_fg_root());
   d->fixDatPath.append("Navaids/fix.dat.gz");
+
+  d->poiDatPath = SGPath(globals->get_fg_root());
+  d->poiDatPath.append("Navaids/poi.dat.gz");
   
   d->carrierDatPath = SGPath(globals->get_fg_root());
   d->carrierDatPath.append("Navaids/carrier_nav.dat.gz");
@@ -1176,6 +1181,7 @@ bool NavDataCache::isRebuildRequired()
       isCachedFileModified(d->metarDatPath) ||
       isCachedFileModified(d->navDatPath) ||
       isCachedFileModified(d->fixDatPath) ||
+      isCachedFileModified(d->poiDatPath) ||
       isCachedFileModified(d->airwayDatPath))
   {
     SG_LOG(SG_NAVCACHE, SG_INFO, "NavCache: main cache rebuild required");
@@ -1237,6 +1243,11 @@ void NavDataCache::doRebuild()
     navDBInit(d->navDatPath);
     stampCacheFile(d->navDatPath);
     SG_LOG(SG_NAVCACHE, SG_INFO, "nav.dat load took:" << st.elapsedMSec());
+
+    st.stamp();
+    poiDBInit(d->poiDatPath);
+    stampCacheFile(d->poiDatPath);
+    SG_LOG(SG_NAVCACHE, SG_INFO, "poi.dat load took:" << st.elapsedMSec());
     
     loadCarrierNav(d->carrierDatPath);
     stampCacheFile(d->carrierDatPath);
diff --git a/src/Navaids/poidb.cxx b/src/Navaids/poidb.cxx
new file mode 100644 (file)
index 0000000..bfc7c81
--- /dev/null
@@ -0,0 +1,106 @@
+// poidb.cxx -- points of interest management routines
+//
+// Written by Christian Schmitt, March 2013
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+//
+// $Id$
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include <simgear/compiler.h>
+#include <simgear/debug/logstream.hxx>
+#include <simgear/math/sg_geodesy.hxx>
+#include <simgear/misc/sg_path.hxx>
+#include <simgear/structure/exception.hxx>
+#include <simgear/misc/sgstream.hxx>
+
+#include <Navaids/NavDataCache.hxx>
+#include "poidb.hxx"
+
+using std::string;
+
+static FGPositioned::Type
+mapPOITypeToFGPType(int aTy)
+{
+  switch (aTy) {
+  case 10: return FGPositioned::COUNTRY;
+  case 12: return FGPositioned::CITY;
+  case 13: return FGPositioned::TOWN;
+  case 14: return FGPositioned::VILLAGE;
+  default:
+    throw sg_range_exception("Unknown POI type", "FGNavDataCache::readPOIFromStream");
+  }
+}
+
+
+
+namespace flightgear
+{
+
+static PositionedID readPOIFromStream(std::istream& aStream,
+                                        FGPositioned::Type type = FGPositioned::INVALID)
+{
+  NavDataCache* cache = NavDataCache::instance();
+
+  int rawType;
+  aStream >> rawType;
+  if (aStream.eof() || (rawType == '#')) {
+    return 0;
+  }
+
+  double lat, lon;
+  std::string name;
+  aStream >> lat >> lon;
+  getline(aStream, name);
+
+  SGGeod pos(SGGeod::fromDeg(lon, lat));
+  name = simgear::strutils::strip(name);
+
+  // the type can be forced by our caller, but normally we use the value
+  // supplied in the .dat file
+  if (type == FGPositioned::INVALID) {
+    type = mapPOITypeToFGPType(rawType);
+  }
+  if (type == FGPositioned::INVALID) {
+    return 0;
+  }
+
+  PositionedID r = cache->createPOI(type, name, pos);
+  return r;
+}
+
+// load and initialize the POI database
+bool poiDBInit(const SGPath& path)
+{
+    sg_gzifstream in( path.str() );
+    if ( !in.is_open() ) {
+        SG_LOG( SG_NAVAID, SG_ALERT, "Cannot open file: " << path.str() );
+      return false;
+    }
+
+    in >> skipcomment;
+
+    while (!in.eof()) {
+      readPOIFromStream(in);
+      in >> skipcomment;
+    } // of stream data loop
+
+  return true;
+}
+
+} // of namespace flightgear
diff --git a/src/Navaids/poidb.hxx b/src/Navaids/poidb.hxx
new file mode 100644 (file)
index 0000000..cfbf3b9
--- /dev/null
@@ -0,0 +1,40 @@
+// poidb.cxx -- points of interest management routines
+//
+// Written by Christian Schmitt, March 2013
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+//
+// $Id$
+
+
+#ifndef _FG_POIDB_HXX
+#define _FG_POIDB_HXX
+
+
+#include <simgear/compiler.h>
+
+
+// forward decls
+class SGPath;
+
+namespace flightgear
+{
+
+// load and initialize the POI database
+bool poiDBInit(const SGPath& path);
+
+} // of namespace flightgear
+
+#endif // _FG_NAVDB_HXX
index ee60aca80fd80a339dd61f4f96fe7ec838b64e9b..450c755d94195b229424445fff6c78f19c6eb91d 100644 (file)
@@ -131,6 +131,7 @@ FGPositioned::Type FGPositioned::typeFromName(const std::string& aName)
     {"country", COUNTRY},
     {"city", CITY},
     {"town", TOWN},
+    {"village", VILLAGE},
       
   // aliases
     {"gnd", FREQ_GROUND},
@@ -191,6 +192,7 @@ const char* FGPositioned::nameForType(Type aTy)
  case COUNTRY: return "country";
  case CITY: return "city";
  case TOWN: return "town";
+ case VILLAGE: return "village";
  default:
   return "unknown";
  }
index aeaea6f12e5baedc2f2d6911558f93a4fca2f2f3..4943c964b776e1a45202d6816511fef6572fffc4 100644 (file)
@@ -85,6 +85,7 @@ public:
     COUNTRY,
     CITY,
     TOWN,
+    VILLAGE,
       
     LAST_TYPE
   } Type;