From bad9708d41bd216f41ff519fdfc109a5100d35f8 Mon Sep 17 00:00:00 2001 From: Patrick Brosi Date: Mon, 23 Sep 2024 13:48:05 +0200 Subject: [PATCH] allow whitespace after commas in WKT, minor refactoring --- src/qlever-petrimaps/GeomCache.cpp | 461 ++++++++++++------------- src/qlever-petrimaps/GeomCache.h | 19 +- src/qlever-petrimaps/server/Server.cpp | 25 +- 3 files changed, 250 insertions(+), 255 deletions(-) diff --git a/src/qlever-petrimaps/GeomCache.cpp b/src/qlever-petrimaps/GeomCache.cpp index 6ed968d..5d56b25 100644 --- a/src/qlever-petrimaps/GeomCache.cpp +++ b/src/qlever-petrimaps/GeomCache.cpp @@ -91,8 +91,8 @@ const std::string &GeomCache::getQuery(const std::string &backendUrl) const { } // _____________________________________________________________________________ -const std::string & -GeomCache::getCountQuery(const std::string &backendUrl) const { +const std::string &GeomCache::getCountQuery( + const std::string &backendUrl) const { return selectQueryBasedOnUrl(backendUrl, COUNT_QUERY_ASWKT, COUNT_QUERY_WD, COUNT_QUERY); } @@ -152,224 +152,227 @@ void GeomCache::parse(const char *c, size_t size) { const char *start = c; while (c < start + size) { - if (_raw.size() < 10000) - _raw.push_back(*c); + if (_raw.size() < 10000) _raw.push_back(*c); switch (_state) { - case IN_HEADER: - if (*c == '\n') { - _state = IN_ROW; - c++; - continue; - } else { - c++; - continue; - } - case IN_ROW: - if (*c == '\t' || *c == '\n') { - // bool isGeom = util::endsWith( - // _dangling, "^^"); - - bool isGeom = true; - - auto p = _dangling.rfind("\"POINT(", 0); - - // if the previous was not a multi geometry, and if the strings - // match exactly, re-use the geometry - if (isGeom && _prev == _dangling && _lastQidToId.qid == 0) { - IdMapping idm{0, _lastQidToId.id}; - _lastQidToId = idm; - _qidToIdF.write(reinterpret_cast(&idm), - sizeof(IdMapping)); - _qidToIdFSize++; - } else if (isGeom && p != std::string::npos) { - _curUniqueGeom++; - p += 7; - auto point = parsePoint(_dangling, p); - if (pointValid(point)) { - _pointsF.write(reinterpret_cast(&point), - sizeof(util::geo::FPoint)); - _pointsFSize++; - IdMapping idm{0, _pointsFSize - 1}; - _lastQidToId = idm; - _qidToIdF.write(reinterpret_cast(&idm), - sizeof(IdMapping)); - _qidToIdFSize++; - } else { - IdMapping idm{0, std::numeric_limits::max()}; - _lastQidToId = idm; - _qidToIdF.write(reinterpret_cast(&idm), - sizeof(IdMapping)); - _qidToIdFSize++; - } - } else if (isGeom && (p = _dangling.rfind("\"LINESTRING(", 0)) != - std::string::npos) { - _curUniqueGeom++; - p += 12; - const auto &line = parseLineString(_dangling, p); - if (line.size() == 0) { - IdMapping idm{0, std::numeric_limits::max()}; - _lastQidToId = idm; - _qidToIdF.write(reinterpret_cast(&idm), - sizeof(IdMapping)); - _qidToIdFSize++; - } else { - _linesF.write(reinterpret_cast(&_linePointsFSize), - sizeof(size_t)); - _linesFSize++; - insertLine(line, false); + case IN_HEADER: + if (*c == '\n') { + _state = IN_ROW; + c++; + continue; + } else { + c++; + continue; + } + case IN_ROW: + if (*c == '\t' || *c == '\n') { + // bool isGeom = util::endsWith( + // _dangling, "^^"); + + bool isGeom = true; + + auto p = _dangling.rfind("\"POINT(", 0); - IdMapping idm{0, I_OFFSET + _linesFSize - 1}; + // if the previous was not a multi geometry, and if the strings + // match exactly, re-use the geometry + if (isGeom && _prev == _dangling && _lastQidToId.qid == 0) { + IdMapping idm{0, _lastQidToId.id}; _lastQidToId = idm; _qidToIdF.write(reinterpret_cast(&idm), sizeof(IdMapping)); _qidToIdFSize++; - } - } else if (isGeom && (p = _dangling.rfind("\"MULTILINESTRING(", 0)) != - std::string::npos) { - _curUniqueGeom++; - p += 17; - size_t i = 0; - while ((p = _dangling.find("(", p + 1)) != std::string::npos) { - const auto &line = parseLineString(_dangling, p + 1); + } else if (isGeom && p != std::string::npos) { + _curUniqueGeom++; + p += 7; + auto point = parsePoint(_dangling, p); + if (pointValid(point)) { + _pointsF.write(reinterpret_cast(&point), + sizeof(util::geo::FPoint)); + _pointsFSize++; + IdMapping idm{0, _pointsFSize - 1}; + _lastQidToId = idm; + _qidToIdF.write(reinterpret_cast(&idm), + sizeof(IdMapping)); + _qidToIdFSize++; + } else { + IdMapping idm{0, std::numeric_limits::max()}; + _lastQidToId = idm; + _qidToIdF.write(reinterpret_cast(&idm), + sizeof(IdMapping)); + _qidToIdFSize++; + } + } else if (isGeom && (p = _dangling.rfind("\"LINESTRING(", 0)) != + std::string::npos) { + _curUniqueGeom++; + p += 12; + const auto &line = parseLineString(_dangling, p); if (line.size() == 0) { - if (i == 0) { - IdMapping idm{0, std::numeric_limits::max()}; - _lastQidToId = idm; - _qidToIdF.write(reinterpret_cast(&idm), - sizeof(IdMapping)); - _qidToIdFSize++; - } + IdMapping idm{0, std::numeric_limits::max()}; + _lastQidToId = idm; + _qidToIdF.write(reinterpret_cast(&idm), + sizeof(IdMapping)); + _qidToIdFSize++; } else { _linesF.write(reinterpret_cast(&_linePointsFSize), sizeof(size_t)); _linesFSize++; insertLine(line, false); - IdMapping idm{i == 0 ? 0 : 1, I_OFFSET + _linesFSize - 1}; + if (line.size() > 10000) { + std::cout << _dangling << std::endl; + } + + IdMapping idm{0, I_OFFSET + _linesFSize - 1}; _lastQidToId = idm; _qidToIdF.write(reinterpret_cast(&idm), sizeof(IdMapping)); _qidToIdFSize++; } - i++; - } - if (i == 0) { - IdMapping idm{0, std::numeric_limits::max()}; - _lastQidToId = idm; - _qidToIdF.write(reinterpret_cast(&idm), - sizeof(IdMapping)); - _qidToIdFSize++; - } - } else if (isGeom && (p = _dangling.rfind("\"POLYGON(", 0)) != - std::string::npos) { - _curUniqueGeom++; - p += 9; - size_t i = 0; - while ((p = _dangling.find("(", p + 1)) != std::string::npos) { - const auto &line = parseLineString(_dangling, p + 1); - if (line.size() == 0) { - if (i == 0) { - IdMapping idm{0, std::numeric_limits::max()}; + } else if (isGeom && (p = _dangling.rfind("\"MULTILINESTRING(", 0)) != + std::string::npos) { + _curUniqueGeom++; + p += 17; + size_t i = 0; + while ((p = _dangling.find("(", p + 1)) != std::string::npos) { + const auto &line = parseLineString(_dangling, p + 1); + if (line.size() == 0) { + if (i == 0) { + IdMapping idm{0, std::numeric_limits::max()}; + _lastQidToId = idm; + _qidToIdF.write(reinterpret_cast(&idm), + sizeof(IdMapping)); + _qidToIdFSize++; + } + } else { + _linesF.write(reinterpret_cast(&_linePointsFSize), + sizeof(size_t)); + _linesFSize++; + insertLine(line, false); + + IdMapping idm{i == 0 ? 0 : 1, I_OFFSET + _linesFSize - 1}; _lastQidToId = idm; _qidToIdF.write(reinterpret_cast(&idm), sizeof(IdMapping)); _qidToIdFSize++; } - } else { - _linesF.write(reinterpret_cast(&_linePointsFSize), - sizeof(size_t)); - _linesFSize++; - insertLine(line, true); - - IdMapping idm{i == 0 ? 0 : 1, I_OFFSET + _linesFSize - 1}; + i++; + } + if (i == 0) { + IdMapping idm{0, std::numeric_limits::max()}; _lastQidToId = idm; _qidToIdF.write(reinterpret_cast(&idm), sizeof(IdMapping)); _qidToIdFSize++; } - i++; - } - if (i == 0) { - IdMapping idm{0, std::numeric_limits::max()}; - _lastQidToId = idm; - _qidToIdF.write(reinterpret_cast(&idm), - sizeof(IdMapping)); - _qidToIdFSize++; - } - } else if (isGeom && (p = _dangling.rfind("\"MULTIPOLYGON(", 0)) != - std::string::npos) { - _curUniqueGeom++; - p += 13; - size_t i = 0; - while ((p = _dangling.find("(", p + 1)) != std::string::npos) { - if (_dangling[p + 1] == '(') - p++; - const auto &line = parseLineString(_dangling, p + 1); - if (line.size() == 0) { - if (i == 0) { - IdMapping idm{0, std::numeric_limits::max()}; + } else if (isGeom && (p = _dangling.rfind("\"POLYGON(", 0)) != + std::string::npos) { + _curUniqueGeom++; + p += 9; + size_t i = 0; + while ((p = _dangling.find("(", p + 1)) != std::string::npos) { + const auto &line = parseLineString(_dangling, p + 1); + if (line.size() == 0) { + if (i == 0) { + IdMapping idm{0, std::numeric_limits::max()}; + _lastQidToId = idm; + _qidToIdF.write(reinterpret_cast(&idm), + sizeof(IdMapping)); + _qidToIdFSize++; + } + } else { + _linesF.write(reinterpret_cast(&_linePointsFSize), + sizeof(size_t)); + _linesFSize++; + insertLine(line, true); + + IdMapping idm{i == 0 ? 0 : 1, I_OFFSET + _linesFSize - 1}; _lastQidToId = idm; _qidToIdF.write(reinterpret_cast(&idm), sizeof(IdMapping)); _qidToIdFSize++; } - } else { - _linesF.write(reinterpret_cast(&_linePointsFSize), - sizeof(size_t)); - _linesFSize++; - insertLine(line, true); - - IdMapping idm{i == 0 ? 0 : 1, I_OFFSET + _linesFSize - 1}; + i++; + } + if (i == 0) { + IdMapping idm{0, std::numeric_limits::max()}; _lastQidToId = idm; _qidToIdF.write(reinterpret_cast(&idm), sizeof(IdMapping)); _qidToIdFSize++; } - i++; - } - if (i == 0) { + } else if (isGeom && (p = _dangling.rfind("\"MULTIPOLYGON(", 0)) != + std::string::npos) { + _curUniqueGeom++; + p += 13; + size_t i = 0; + while ((p = _dangling.find("(", p + 1)) != std::string::npos) { + if (_dangling[p + 1] == '(') p++; + const auto &line = parseLineString(_dangling, p + 1); + if (line.size() == 0) { + if (i == 0) { + IdMapping idm{0, std::numeric_limits::max()}; + _lastQidToId = idm; + _qidToIdF.write(reinterpret_cast(&idm), + sizeof(IdMapping)); + _qidToIdFSize++; + } + } else { + _linesF.write(reinterpret_cast(&_linePointsFSize), + sizeof(size_t)); + _linesFSize++; + insertLine(line, true); + + IdMapping idm{i == 0 ? 0 : 1, I_OFFSET + _linesFSize - 1}; + _lastQidToId = idm; + _qidToIdF.write(reinterpret_cast(&idm), + sizeof(IdMapping)); + _qidToIdFSize++; + } + i++; + } + if (i == 0) { + IdMapping idm{0, std::numeric_limits::max()}; + _lastQidToId = idm; + _qidToIdF.write(reinterpret_cast(&idm), + sizeof(IdMapping)); + _qidToIdFSize++; + } + } else { IdMapping idm{0, std::numeric_limits::max()}; _lastQidToId = idm; _qidToIdF.write(reinterpret_cast(&idm), sizeof(IdMapping)); _qidToIdFSize++; } - } else { - IdMapping idm{0, std::numeric_limits::max()}; - _lastQidToId = idm; - _qidToIdF.write(reinterpret_cast(&idm), - sizeof(IdMapping)); - _qidToIdFSize++; - } - if (*c == '\n') { - _curRow++; - if (_curRow % 1000000 == 0) { - LOG(INFO) << "[GEOMCACHE] " - << "@ row " << _curRow << " (" << std::fixed - << std::setprecision(2) << getLoadStatusPercent() << "%, " - << _pointsFSize << " points, " << _linesFSize - << " (open) polygons, " << _geometryDuplicates - << " duplicates)"; + if (*c == '\n') { + _curRow++; + if (_curRow % 1000000 == 0) { + LOG(INFO) << "[GEOMCACHE] " + << "@ row " << _curRow << " (" << std::fixed + << std::setprecision(2) << getLoadStatusPercent() + << "%, " << _pointsFSize << " points, " << _linesFSize + << " (open) polygons (with " << _linePointsFSize + << " points), " << _geometryDuplicates + << " duplicates)"; + } + _prev = _dangling; + _dangling.clear(); + c++; + continue; + } else { + _prev = _dangling; + _dangling.clear(); + c++; + continue; } - _prev = _dangling; - _dangling.clear(); - c++; - continue; - } else { - _prev = _dangling; - _dangling.clear(); - c++; - continue; } - } - _dangling += toupper(*c); - c++; + _dangling += toupper(*c); + c++; - break; - default: - break; + break; + default: + break; } } } @@ -395,18 +398,19 @@ double GeomCache::getLoadStatusPercent(bool total) { double parseIdsPercent = 5.0; double totalPercent = 0.0; switch (_loadStatusStage) { - case _LoadStatusStages::Parse: - totalPercent = _curRow / static_cast(_totalSize) * parsePercent; - break; - - case _LoadStatusStages::ParseIds: - totalPercent = parsePercent; - totalPercent += _curRow / static_cast(_totalSize) * parseIdsPercent; - break; - - case _LoadStatusStages::FromFile: - totalPercent = _curRow / static_cast(_totalSize) * 100.0; - break; + case _LoadStatusStages::Parse: + totalPercent = _curRow / static_cast(_totalSize) * parsePercent; + break; + + case _LoadStatusStages::ParseIds: + totalPercent = parsePercent; + totalPercent += + _curRow / static_cast(_totalSize) * parseIdsPercent; + break; + + case _LoadStatusStages::FromFile: + totalPercent = _curRow / static_cast(_totalSize) * 100.0; + break; } return std::min(100.0, totalPercent); @@ -427,8 +431,7 @@ void GeomCache::parseIds(const char *c, size_t size) { size_t lastQid = -1; for (size_t i = 0; i < size; i++) { - if (_raw.size() < 10000) - _raw.push_back(c[i]); + if (_raw.size() < 10000) _raw.push_back(c[i]); _curId.bytes[_curByte] = c[i]; _curByte = (_curByte + 1) % 8; @@ -458,8 +461,7 @@ void GeomCache::parseIds(const char *c, size_t size) { _qidToId[_curRow].qid = _curId.val; } lastQid = _curId.val; - if (_curId.val > _maxQid) - _maxQid = _curId.val; + if (_curId.val > _maxQid) _maxQid = _curId.val; } else { LOG(WARN) << "The results for the binary IDs are out of sync."; LOG(WARN) << "_curRow: " << _curRow @@ -484,12 +486,9 @@ void GeomCache::parseIds(const char *c, size_t size) { // _____________________________________________________________________________ void GeomCache::parseCount(const char *c, size_t size) { for (size_t i = 0; i < size; i++) { - if (_raw.size() < 10000) - _raw.push_back(c[i]); - if (c[i] == '\n') - _state = IN_ROW; - if (_state == IN_ROW) - _dangling += c[i]; + if (_raw.size() < 10000) _raw.push_back(c[i]); + if (c[i] == '\n') _state = IN_ROW; + if (_state == IN_ROW) _dangling += c[i]; } } @@ -541,8 +540,7 @@ size_t GeomCache::requestSize() { throw std::runtime_error(ss.str()); } - if (_exceptionPtr) - std::rethrow_exception(_exceptionPtr); + if (_exceptionPtr) std::rethrow_exception(_exceptionPtr); } else { LOG(ERROR) << "[GEOMCACHE] Failed to perform curl request."; return -1; @@ -608,8 +606,7 @@ void GeomCache::requestPart(size_t offset) { throw std::runtime_error(ss.str()); } - if (_exceptionPtr) - std::rethrow_exception(_exceptionPtr); + if (_exceptionPtr) std::rethrow_exception(_exceptionPtr); } else { LOG(ERROR) << "[GEOMCACHE] Failed to perform curl request."; return; @@ -649,27 +646,23 @@ void GeomCache::request() { char *pointsFName = strdup("pointsXXXXXX"); int i = mkstemp(pointsFName); - if (i == -1) - throw std::runtime_error("Could not create temporary file"); + if (i == -1) throw std::runtime_error("Could not create temporary file"); _pointsF.open(pointsFName, std::ios::out | std::ios::in | std::ios::binary); char *linePointsFName = strdup("linepointsXXXXXX"); i = mkstemp(linePointsFName); - if (i == -1) - throw std::runtime_error("Could not create temporary file"); + if (i == -1) throw std::runtime_error("Could not create temporary file"); _linePointsF.open(linePointsFName, std::ios::out | std::ios::in | std::ios::binary); char *linesFName = strdup("linesXXXXXX"); i = mkstemp(linesFName); - if (i == -1) - throw std::runtime_error("Could not create temporary file"); + if (i == -1) throw std::runtime_error("Could not create temporary file"); _linesF.open(linesFName, std::ios::out | std::ios::in | std::ios::binary); char *qidToIdFName = strdup("qidtoidXXXXXX"); i = mkstemp(qidToIdFName); - if (i == -1) - throw std::runtime_error("Could not create temporary file"); + if (i == -1) throw std::runtime_error("Could not create temporary file"); _qidToIdF.open(qidToIdFName, std::ios::out | std::ios::in | std::ios::binary); // immediately unlink @@ -702,8 +695,7 @@ void GeomCache::request() { lastNum = _curRow - offset; } - if (i == -1) - throw std::runtime_error("Could not create temporary file"); + if (i == -1) throw std::runtime_error("Could not create temporary file"); LOG(INFO) << "[GEOMCACHE] Building vectors..."; @@ -780,8 +772,7 @@ void GeomCache::requestIds() { throw std::runtime_error(ss.str()); } - if (_exceptionPtr) - std::rethrow_exception(_exceptionPtr); + if (_exceptionPtr) std::rethrow_exception(_exceptionPtr); } else { LOG(ERROR) << "[GEOMCACHE] Failed to perform curl request."; } @@ -820,56 +811,48 @@ std::string GeomCache::queryUrl(std::string query, size_t offset, // _____________________________________________________________________________ bool GeomCache::pointValid(const FPoint &p) { - if (p.getY() > std::numeric_limits::max()) - return false; - if (p.getY() < std::numeric_limits::lowest()) - return false; - if (p.getX() > std::numeric_limits::max()) - return false; - if (p.getX() < std::numeric_limits::lowest()) - return false; + if (p.getY() > std::numeric_limits::max()) return false; + if (p.getY() < std::numeric_limits::lowest()) return false; + if (p.getX() > std::numeric_limits::max()) return false; + if (p.getX() < std::numeric_limits::lowest()) return false; return true; } // _____________________________________________________________________________ bool GeomCache::pointValid(const DPoint &p) { - if (p.getY() > std::numeric_limits::max()) - return false; - if (p.getY() < std::numeric_limits::lowest()) - return false; - if (p.getX() > std::numeric_limits::max()) - return false; - if (p.getX() < std::numeric_limits::lowest()) - return false; + if (p.getY() > std::numeric_limits::max()) return false; + if (p.getY() < std::numeric_limits::lowest()) return false; + if (p.getX() > std::numeric_limits::max()) return false; + if (p.getX() < std::numeric_limits::lowest()) return false; return true; } // _____________________________________________________________________________ -util::geo::DLine GeomCache::parseLineString(const std::string &a, - size_t p) const { +util::geo::DLine GeomCache::parseLineString(const std::string &a, size_t p) { util::geo::DLine line; line.reserve(2); auto end = memchr(a.c_str() + p, ')', a.size() - p); assert(end); while (true) { + while (p < a.size() && std::isspace(a[p])) p++; + auto next = static_cast(memchr(a.c_str() + p, ' ', a.size() - p)); - if (!next) - break; + while (next && std::isspace(*next)) next++; + + if (!next) break; auto point = latLngToWebMerc( - DPoint(util::atof(a.c_str() + p, 10), util::atof(next + 1, 10))); + DPoint(util::atof(a.c_str() + p, 10), util::atof(next, 10))); - if (pointValid(point)) - line.push_back(point); + if (pointValid(point)) line.push_back(point); auto n = memchr(a.c_str() + p, ',', a.size() - p); - if (!n || n > end) - break; + if (!n || n > end) break; p = static_cast(n) - a.c_str() + 1; } @@ -883,12 +866,14 @@ util::geo::FPoint GeomCache::parsePoint(const std::string &a, size_t p) const { auto next = static_cast(memchr(a.c_str() + p, ' ', a.size() - p)); + while (next && std::isspace(*next)) next++; + if (!next) return {std::numeric_limits::infinity(), std::numeric_limits::infinity()}; auto point = latLngToWebMerc( - FPoint(util::atof(a.c_str() + p, 10), util::atof(next + 1, 10))); + FPoint(util::atof(a.c_str() + p, 10), util::atof(next, 10))); return point; } @@ -913,8 +898,7 @@ GeomCache::getRelObjects(const std::vector &ids) const { size_t prefJ = j; while (j < _qidToId.size() && ids[i].qid == _qidToId[j].qid) { - if (ret.size() == 0 || ret.back().second != ids[i].id) - numObjects++; + if (ret.size() == 0 || ret.back().second != ids[i].id) numObjects++; ret.push_back({_qidToId[j].id, ids[i].id}); j++; } @@ -1246,8 +1230,7 @@ std::string GeomCache::load(const std::string &cacheDir) { if (_ready) { auto indexHash = requestIndexHash(); - if (_indexHash == indexHash) - return _indexHash; + if (_indexHash == indexHash) return _indexHash; LOG(INFO) << "Loaded index hash (" << _indexHash << ") and remote index hash (" << indexHash << ") dont match."; _ready = false; diff --git a/src/qlever-petrimaps/GeomCache.h b/src/qlever-petrimaps/GeomCache.h index 211f966..bf44fc7 100644 --- a/src/qlever-petrimaps/GeomCache.h +++ b/src/qlever-petrimaps/GeomCache.h @@ -7,13 +7,13 @@ #include +#include #include #include #include #include #include #include -#include #include "qlever-petrimaps/Misc.h" #include "util/geo/Geo.h" @@ -24,8 +24,7 @@ class GeomCache { public: GeomCache() : _backendUrl(""), _curl(0) {} explicit GeomCache(const std::string& backendUrl) - : _backendUrl(backendUrl), - _curl(curl_easy_init()) {} + : _backendUrl(backendUrl), _curl(curl_easy_init()) {} GeomCache& operator=(GeomCache&& o) { _backendUrl = o._backendUrl; @@ -106,13 +105,16 @@ class GeomCache { std::atomic _curRow; size_t _curUniqueGeom; - enum _LoadStatusStages {Parse = 1, ParseIds, FromFile}; + enum _LoadStatusStages { Parse = 1, ParseIds, FromFile }; _LoadStatusStages _loadStatusStage = Parse; static size_t writeCb(void* contents, size_t size, size_t nmemb, void* userp); - static size_t writeCbIds(void* contents, size_t size, size_t nmemb, void* userp); - static size_t writeCbCount(void* contents, size_t size, size_t nmemb, void* userp); - static size_t writeCbString(void* contents, size_t size, size_t nmemb, void* userp); + static size_t writeCbIds(void* contents, size_t size, size_t nmemb, + void* userp); + static size_t writeCbCount(void* contents, size_t size, size_t nmemb, + void* userp); + static size_t writeCbString(void* contents, size_t size, size_t nmemb, + void* userp); // Get the right SPARQL query for the given backend. const std::string& getQuery(const std::string& backendUrl) const; @@ -122,12 +124,13 @@ class GeomCache { std::string queryUrl(std::string query, size_t offset, size_t limit) const; - util::geo::DLine parseLineString(const std::string& a, size_t p) const; util::geo::FPoint parsePoint(const std::string& a, size_t p) const; static bool pointValid(const util::geo::FPoint& p); static bool pointValid(const util::geo::DPoint& p); + static util::geo::DLine parseLineString(const std::string& a, size_t p); + void insertLine(const util::geo::DLine& l, bool isArea); std::string indexHashFromDisk(const std::string& fname); diff --git a/src/qlever-petrimaps/server/Server.cpp b/src/qlever-petrimaps/server/Server.cpp index 1257563..d975bef 100755 --- a/src/qlever-petrimaps/server/Server.cpp +++ b/src/qlever-petrimaps/server/Server.cpp @@ -113,13 +113,17 @@ util::http::Answer Server::handle(const util::http::Req& req, int con) const { } } catch (const std::runtime_error& e) { a = util::http::Answer("400 Bad Request", e.what()); + LOG(ERROR) << e.what(); } catch (const std::invalid_argument& e) { a = util::http::Answer("400 Bad Request", e.what()); + LOG(ERROR) << e.what(); } catch (const std::exception& e) { a = util::http::Answer("500 Internal Server Error", e.what()); + LOG(ERROR) << e.what(); } catch (...) { a = util::http::Answer("500 Internal Server Error", "Internal Server Error."); + LOG(ERROR) << "Unknown failure occured."; } a.params["Access-Control-Allow-Origin"] = "*"; @@ -368,7 +372,8 @@ util::http::Answer Server::handleHeatMapReq(const Params& pars, // the factor depends on the render thickness of the line, make // this configurable! - const auto& denseLine = densify(r->extractLineGeom(lid - I_OFFSET), res); + const auto& denseLine = + densify(r->extractLineGeom(lid - I_OFFSET), res); for (const auto& p : denseLine) { int px = ((p.getX() - bbox.getLowerLeft().getX()) / mercW) * w; @@ -844,7 +849,8 @@ std::string Server::parseUrl(std::string u, std::string pl, return util::urlDecode(parts.front()); } -void Server::pngWriteRowCb(png_structp png_ptr, png_uint_32 row, int pass) { +// _____________________________________________________________________________ +void Server::pngWriteRowCb(png_structp, png_uint_32 row, int) { _curRow = row; } @@ -876,7 +882,8 @@ inline void pngErrorCb(png_structp, png_const_charp error_msg) { } // _____________________________________________________________________________ -void Server::writePNG(const unsigned char* data, size_t w, size_t h, int sock) const { +void Server::writePNG(const unsigned char* data, size_t w, size_t h, + int sock) const { png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, pngErrorCb, pngWarnCb); if (!png_ptr) return; @@ -907,7 +914,8 @@ void Server::writePNG(const unsigned char* data, size_t w, size_t h, int sock) c png_set_IHDR(png_ptr, info_ptr, w, h, bit_depth, color_type, interlace_type, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); - png_bytep* row_pointers = (png_byte**)png_malloc(png_ptr, h * sizeof(png_bytep)); + png_bytep* row_pointers = + (png_byte**)png_malloc(png_ptr, h * sizeof(png_bytep)); for (size_t y = 0; y < h; ++y) { row_pointers[y] = const_cast(data + y * w * 4); @@ -1143,15 +1151,15 @@ util::http::Answer Server::handleLoadStatusReq(const Params& pars) const { double serverPercent = 0.05; double geomCacheLoadStatusPercent = cache->getLoadStatusPercent(true); double serverLoadStatusPercent = getLoadStatusPercent(); - double totalPercent = geomCachePercent * geomCacheLoadStatusPercent + serverPercent * serverLoadStatusPercent; + double totalPercent = geomCachePercent * geomCacheLoadStatusPercent + + serverPercent * serverLoadStatusPercent; int loadStatusStage = cache->getLoadStatusStage(); size_t totalProgress = cache->getTotalProgress(); size_t currentProgress = cache->getCurrentProgress(); std::stringstream json; - json << "{\"percent\": " << totalPercent - << ", \"stage\": " << loadStatusStage + json << "{\"percent\": " << totalPercent << ", \"stage\": " << loadStatusStage << ", \"totalProgress\": " << totalProgress << ", \"currentProgress\": " << currentProgress << "}"; util::http::Answer ans = util::http::Answer("200 OK", json.str()); @@ -1191,6 +1199,7 @@ std::string Server::getSessionId() const { return std::to_string(d(rng)); } +// _____________________________________________________________________________ double Server::getLoadStatusPercent() const { if (_totalSize == 0) { return 0.0; @@ -1202,6 +1211,7 @@ double Server::getLoadStatusPercent() const { return percent; } +// _____________________________________________________________________________ void Server::createCache(const std::string& backend) const { std::shared_ptr cache; @@ -1218,7 +1228,6 @@ void Server::createCache(const std::string& backend) const { // _____________________________________________________________________________ std::string Server::loadCache(const std::string& backend) const { - // std::shared_ptr reqor; std::shared_ptr cache = _caches[backend]; try {