Skip to content

Commit

Permalink
Implemented first version of SQL-petrimaps.
Browse files Browse the repository at this point in the history
  • Loading branch information
Grandro committed Nov 19, 2024
1 parent bdce756 commit c3f9ba5
Show file tree
Hide file tree
Showing 606 changed files with 118,160 additions and 849 deletions.
76 changes: 76 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"files.associations": {
"any": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"cinttypes": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"codecvt": "cpp",
"compare": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"regex": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"ranges": "cpp",
"semaphore": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"typeinfo": "cpp",
"valarray": "cpp",
"*.tpp": "cpp",
"pqxx": "cpp"
}
}
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 3.8)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

project (qlever-petrimaps)
project(qlever-petrimaps)

# only change first char
if (CMAKE_BUILD_TYPE)
Expand Down
2 changes: 1 addition & 1 deletion src/3rdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
file(GLOB_RECURSE 3RDPARTY_SRC *.c)
file(GLOB_RECURSE 3RDPARTY_SRC *.c *.cpp)

add_library(3rdparty_dep ${3RDPARTY_SRC})
3 changes: 1 addition & 2 deletions src/3rdparty/md5/md5.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ documentation and/or software.
#define BZF_MD5_H

#include <cstring>
#include <iostream>

#include <iostream>

// a small class for calculating MD5 hashes of strings or byte arrays
// it is not meant to be fast or secure
Expand Down
2 changes: 1 addition & 1 deletion src/qlever-petrimaps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ add_custom_command(
VERBATIM
)

add_custom_target(htmlfiles DEPENDS index.h build.h style.h)
add_custom_target(htmlfiles DEPENDS index.h style.h build.h)

add_dependencies(qlever_petrimaps_dep htmlfiles)

Expand Down
98 changes: 28 additions & 70 deletions src/qlever-petrimaps/GeoJSONCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@
using petrimaps::GeoJSONCache;
using json = nlohmann::json;

// _____________________________________________________________________________
double GeoJSONCache::getLoadStatusPercentTotal() {
if (_totalSize == 0) {
return 0.0;
}

double totalPercent = 0.0;
switch (_loadStatusStage) {
case _LoadStatusStages::Parse:
totalPercent += _curRow / static_cast<double>(_totalSize) * 100.0;
break;
}

return totalPercent;
}

// _____________________________________________________________________________
int GeoJSONCache::getLoadStatusStage() {
return _loadStatusStage;
}

// _____________________________________________________________________________
std::vector<std::pair<ID_TYPE, ID_TYPE>> GeoJSONCache::getRelObjects() const {
// Used for GeoJSON, returns all objects as vector<pair<geomID, Row>>
Expand Down Expand Up @@ -38,68 +59,7 @@ std::vector<std::pair<ID_TYPE, ID_TYPE>> GeoJSONCache::getRelObjects() const {
}

// _____________________________________________________________________________
void GeoJSONCache::insertLine(const util::geo::DLine& l, bool isArea) {
const auto& bbox = util::geo::getBoundingBox(l);
int16_t mainX = (bbox.getLowerLeft().getX() * 10.0) / M_COORD_GRANULARITY;
int16_t mainY = (bbox.getLowerLeft().getY() * 10.0) / M_COORD_GRANULARITY;

if (mainX != 0 || mainY != 0) {
util::geo::Point<int16_t> p{mCoord(mainX), mCoord(mainY)};
_linePoints.push_back(p);
}

// add bounding box lower left
int16_t minorXLoc =
(bbox.getLowerLeft().getX() * 10.0) - mainX * M_COORD_GRANULARITY;
int16_t minorYLoc =
(bbox.getLowerLeft().getY() * 10.0) - mainY * M_COORD_GRANULARITY;
util::geo::Point<int16_t> p{minorXLoc, minorYLoc};
_linePoints.push_back(p);

// add bounding box upper left
int16_t mainXLoc = (bbox.getUpperRight().getX() * 10.0) / M_COORD_GRANULARITY;
int16_t mainYLoc = (bbox.getUpperRight().getY() * 10.0) / M_COORD_GRANULARITY;
minorXLoc =
(bbox.getUpperRight().getX() * 10.0) - mainXLoc * M_COORD_GRANULARITY;
minorYLoc =
(bbox.getUpperRight().getY() * 10.0) - mainYLoc * M_COORD_GRANULARITY;
if (mainXLoc != mainX || mainYLoc != mainY) {
mainX = mainXLoc;
mainY = mainYLoc;
util::geo::Point<int16_t> p{mCoord(mainX), mCoord(mainY)};
_linePoints.push_back(p);
}
p = util::geo::Point<int16_t>{minorXLoc, minorYLoc};
_linePoints.push_back(p);

// add line points
for (const auto& p : l) {
mainXLoc = (p.getX() * 10.0) / M_COORD_GRANULARITY;
mainYLoc = (p.getY() * 10.0) / M_COORD_GRANULARITY;

if (mainXLoc != mainX || mainYLoc != mainY) {
mainX = mainXLoc;
mainY = mainYLoc;
util::geo::Point<int16_t> p{mCoord(mainX), mCoord(mainY)};
_linePoints.push_back(p);
}

int16_t minorXLoc = (p.getX() * 10.0) - mainXLoc * M_COORD_GRANULARITY;
int16_t minorYLoc = (p.getY() * 10.0) - mainYLoc * M_COORD_GRANULARITY;
util::geo::Point<int16_t> pp{minorXLoc, minorYLoc};
_linePoints.push_back(pp);
}

// if we have an area, we end in a major coord (which is not possible for
// other types)
if (isArea) {
util::geo::Point<int16_t> p{mCoord(0), mCoord(0)};
_linePoints.push_back(p);
}
}

// _____________________________________________________________________________
void GeoJSONCache::load() {
void GeoJSONCache::load(const std::string& cacheDir) {
_loadStatusStage = _LoadStatusStages::Parse;

json res = json::parse(_content);
Expand Down Expand Up @@ -142,12 +102,10 @@ void GeoJSONCache::load() {
auto coords = geom["coordinates"];
auto properties = feature["properties"];

LOG(INFO) << type;

// PRIMITIVES
// Point
if (type == "Point") {
auto point = latLngToWebMerc(FPoint(coords[0], coords[1]));
FPoint point = latLngToWebMerc(FPoint(coords[0], coords[1]));
if (!pointValid(point)) {
LOG(INFO) << "[GeomCache] Invalid point found. Skipping...";
continue;
Expand All @@ -164,7 +122,7 @@ void GeoJSONCache::load() {
line.reserve(coords.size());

for (std::vector<float> coord : coords) {
auto point = latLngToWebMerc(DPoint(coord[0], coord[1]));
DPoint point = latLngToWebMerc(DPoint(coord[0], coord[1]));
if (!pointValid(point)) {
LOG(INFO) << "[GeomCache] Invalid point found. Skipping...";
continue;
Expand All @@ -188,7 +146,7 @@ void GeoJSONCache::load() {
line.reserve(args.size());

for (std::vector<float> coord : args) {
auto point = latLngToWebMerc(DPoint(coord[0], coord[1]));
DPoint point = latLngToWebMerc(DPoint(coord[0], coord[1]));
if (!pointValid(point)) {
LOG(INFO) << "[GeomCache] Invalid point found. Skipping...";
continue;
Expand All @@ -212,7 +170,7 @@ void GeoJSONCache::load() {
} else if (type == "MultiPoint") {
for (size_t i = 0; i < coords.size(); i++) {
std::vector<float> coord = coords[i];
auto point = latLngToWebMerc(FPoint(coord[0], coord[1]));
FPoint point = latLngToWebMerc(FPoint(coord[0], coord[1]));
if (!pointValid(point)) {
LOG(INFO) << "[GeomCache] Invalid point found. Skipping...";
continue;
Expand All @@ -233,7 +191,7 @@ void GeoJSONCache::load() {
line.reserve(args.size());

for (std::vector<float> coord : args) {
auto point = latLngToWebMerc(DPoint(coord[0], coord[1]));
DPoint point = latLngToWebMerc(DPoint(coord[0], coord[1]));
if (!pointValid(point)) {
LOG(INFO) << "[GeomCache] Invalid point found. Skipping...";
continue;
Expand All @@ -260,7 +218,7 @@ void GeoJSONCache::load() {
line.reserve(args2.size());

for (std::vector<float> coord : args2) {
auto point = latLngToWebMerc(DPoint(coord[0], coord[1]));
DPoint point = latLngToWebMerc(DPoint(coord[0], coord[1]));
if (!pointValid(point)) {
LOG(INFO) << "[GeomCache] Invalid point found. Skipping...";
continue;
Expand Down
14 changes: 8 additions & 6 deletions src/qlever-petrimaps/GeoJSONCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,27 @@ class GeoJSONCache : public GeomCache {
return id + 1 < _lines.size() ? getLine(id + 1) : _linePoints.size();
}

void load();
void load(const std::string& cacheDir);
void setContent(const std::string& content);
std::vector<std::pair<ID_TYPE, ID_TYPE>> getRelObjects() const;
std::map<std::string, std::string> getAttrRow(size_t row) const {
std::map<std::string, std::string> getRowAttr(size_t row) const {
return _attr.at(row);
}

private:
enum _LoadStatusStages {Parse = 1};
_LoadStatusStages _loadStatusStage = Parse;

double getLoadStatusPercentTotal();
int getLoadStatusStage();

std::string _content;

void insertLine(const util::geo::DLine& l, bool isArea);
// Map geomID to map<key, value>
std::map<size_t, std::map<std::string, std::string>> _attr;
// ------------------------
std::vector<std::tuple<util::geo::FPoint, bool>> _points;
std::vector<std::tuple<size_t, bool>> _lines;

protected:

};
} // namespace petrimaps

Expand Down
Loading

0 comments on commit c3f9ba5

Please sign in to comment.