12#include <simgear/compiler.h>
13#include <simgear/debug/logstream.hxx>
14#include <simgear/math/sg_geodesy.hxx>
15#include <simgear/misc/sg_path.hxx>
16#include <simgear/structure/exception.hxx>
17#include <simgear/io/iostreams/sgstream.hxx>
37 throw sg_range_exception(
"Unknown POI type",
"FGNavDataCache::readPOIFromStream");
50static bool isNearby(
const SGVec3d& pos1,
const SGVec3d& pos2)
52 const double d = distSqr(pos1, pos2);
64 std::size_t bytesReadSoFar,
65 std::size_t totalSizeOfAllDatFiles)
67 _path = sceneryLocation.
datPath;
68 sg_gzifstream in( _path );
69 const std::string utf8path = _path.utf8Str();
71 if ( !in.is_open() ) {
72 throw sg_io_exception(
73 "Cannot open file (" + simgear::strutils::error_string(errno) +
")",
78 for (
int i = 0;
i < 2;
i++) {
80 std::getline(in, line);
81 throwExceptionIfStreamError(in);
85 unsigned int lineNumber = 3;
88 for (std::string line; !in.eof(); lineNumber++) {
90 readPOIFromStream(in, lineNumber);
93 if ((lineNumber % 100) == 0) {
95 unsigned int percent = ((bytesReadSoFar + in.approxOffset()) * 100)
96 / totalSizeOfAllDatFiles;
101 throwExceptionIfStreamError(in);
104void POILoader::throwExceptionIfStreamError(
const sg_gzifstream& input_stream)
106 if (input_stream.bad()) {
107 const std::string errMsg = simgear::strutils::error_string(errno);
109 SG_LOG(SG_NAVAID, SG_ALERT,
110 "Error while reading '" << _path.utf8Str() <<
"': " << errMsg);
111 throw sg_io_exception(
"POILoader: error reading file (" + errMsg +
")",
116PositionedID POILoader::readPOIFromStream(std::istream& aStream,
124 if (aStream.peek() ==
'#') {
133 aStream >> lat >> lon;
134 getline(aStream,
name);
136 SGGeod pos(SGGeod::fromDeg(lon, lat));
137 name = simgear::strutils::strip(
name);
148 const auto cartPos = SGVec3d::fromGeod(pos);
151 const auto key = std::make_tuple(type,
name);
152 auto matching = _loadedPOIs.equal_range(key);
153 for (
auto it = matching.first; it != matching.second; ++it) {
154 if (
isNearby(cartPos, it->second)) {
155 SG_LOG(SG_NAVAID, SG_INFO,
156 _path.utf8Str() <<
":" << lineNumber <<
": skipping POI '" <<
157 name <<
"' (already defined nearby)");
162 _loadedPOIs.emplace(key, cartPos);
163 return _cache->createPOI(type,
name, pos,
name,
false);
void loadPOIs(const NavDataCache::SceneryLocation &sceneryLocation, std::size_t bytesReadSoFar, std::size_t totalSizeOfAllDatFiles)
FlightPlan.hxx - defines a full flight-plan object, including departure, cruise, arrival information ...
static const double DUPLICATE_DETECTION_RADIUS_SQR_M
static const double DUPLICATE_DETECTION_RADIUS_NM
static bool isNearby(const SGGeod &pos1, const SGGeod &pos2)
static FGPositioned::Type mapPOITypeToFGPType(int aTy)