Skip to content

Commit

Permalink
Fixes concerning Grandro-submit-menu (#12)
Browse files Browse the repository at this point in the history
* Fixed logic for parsing GeoJson files for polygons
and multipart geometries.

* Changed CMakeLists debug build flags to allow
debugging without optimized out variable values.

* Implemented better support for multi-geometries
such that geometries of a multi-geometry belong
together.

* Reverted datastructure in SPARQLCache for _lines
and _points because it handles multi-geometries
differently than GeoJSONCache.

* Fixed GeoJson export (for MultiGeometries)

* Fixed inconsistencies.
  • Loading branch information
Grandro authored Jul 10, 2024
1 parent 6f2b412 commit 6085247
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 59 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if (PNG_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()

set(CMAKE_CXX_FLAGS_DEBUG "-Og -g -DLOGLEVEL=3")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -DLOGLEVEL=3")#-Og -g -DLOGLEVEL=3")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS} -DLOGLEVEL=2")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -DLOGLEVEL=2")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -g -DLOGLEVEL=3")
Expand All @@ -63,4 +63,4 @@ add_subdirectory(src)
install(
FILES ${CMAKE_BINARY_DIR}/petrimaps DESTINATION bin
PERMISSIONS OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE
)
)
71 changes: 49 additions & 22 deletions src/qlever-petrimaps/GeoJSONCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,24 @@ std::vector<std::pair<ID_TYPE, ID_TYPE>> GeoJSONCache::getRelObjects() const {
// Used for GeoJSON, returns all objects as vector<pair<geomID, Row>>
// geomID starts from 0 ascending, Row = geomID
std::vector<std::pair<ID_TYPE, ID_TYPE>> objects;
objects.reserve(_points.size() + _linePoints.size());
objects.reserve(_points.size() + _lines.size());

size_t idx = 0;
for (size_t i = 0; i < _points.size(); i++) {
objects.push_back({i, i});
bool isFirst = std::get<1>(_points[i]);
if (isFirst && i > 0) {
idx++;
}
objects.push_back({i, idx});
}

idx = 0;
for (size_t i = 0; i < _lines.size(); i++) {
objects.push_back({i + I_OFFSET, i + I_OFFSET});
bool isFirst = std::get<1>(_lines[i]);
if (isFirst && i > 0) {
idx++;
}
objects.push_back({i + I_OFFSET, idx + I_OFFSET});
}

return objects;
Expand Down Expand Up @@ -131,24 +142,26 @@ void GeoJSONCache::load() {
auto coords = geom["coordinates"];
auto properties = feature["properties"];

LOG(INFO) << geom["type"];
LOG(INFO) << type;

// PRIMITIVES
// Point
if (type == "Point") {
auto point = latLngToWebMerc(FPoint(coords[0], coords[1]));
if (!pointValid(point)) {
LOG(INFO) << "[GeomCache] Invalid point found. Skipping...";
continue;
}
_points.push_back(point);
_points.push_back({point, true});

_curUniqueGeom++;
_attr[numPoints] = properties;
numPoints++;


// LineString
} else if (type == "LineString") {
util::geo::DLine line;
line.reserve(2);
line.reserve(coords.size());

for (std::vector<float> coord : coords) {
auto point = latLngToWebMerc(DPoint(coord[0], coord[1]));
Expand All @@ -159,18 +172,20 @@ void GeoJSONCache::load() {
line.push_back(point);
}
std::size_t idx = _linePoints.size();
_lines.push_back(idx);
_lines.push_back({idx, true});
line = util::geo::densify(line, 200 * 3);
insertLine(line, false);

_curUniqueGeom++;
_attr[numLines + I_OFFSET] = properties;
numLines++;


// Polygon
} else if (type == "Polygon") {
for (auto args : coords) {
for (size_t i = 0; i < coords.size(); i++) {
auto args = coords[i];
util::geo::DLine line;
line.reserve(2);
line.reserve(args.size());

for (std::vector<float> coord : args) {
auto point = latLngToWebMerc(DPoint(coord[0], coord[1]));
Expand All @@ -180,8 +195,10 @@ void GeoJSONCache::load() {
}
line.push_back(point);
}

std::size_t idx = _linePoints.size();
_lines.push_back(idx);
bool isFirst = i == 0;
_lines.push_back({idx, isFirst});
line = util::geo::densify(line, 200 * 3);
insertLine(line, true);
}
Expand All @@ -190,24 +207,30 @@ void GeoJSONCache::load() {
_attr[numLines + I_OFFSET] = properties;
numLines++;

// MULTIPART
// MULTIPART
// MultiPoint
} else if (type == "MultiPoint") {
for (std::vector<float> coord : coords) {
for (size_t i = 0; i < coords.size(); i++) {
std::vector<float> coord = coords[i];
auto point = latLngToWebMerc(FPoint(coord[0], coord[1]));
if (!pointValid(point)) {
LOG(INFO) << "[GeomCache] Invalid point found. Skipping...";
continue;
}
_points.push_back(point);
bool isFirst = i == 0;
_points.push_back({point, isFirst});
}

_curUniqueGeom++;
_attr[numPoints] = properties;
numPoints++;

// MultiLineString
} else if (type == "MultiLineString") {
for (auto args : coords) {
for (size_t i = 0; i < coords.size(); i++) {
auto args = coords[i];
util::geo::DLine line;
line.reserve(2);
line.reserve(args.size());

for (std::vector<float> coord : args) {
auto point = latLngToWebMerc(DPoint(coord[0], coord[1]));
Expand All @@ -218,20 +241,23 @@ void GeoJSONCache::load() {
line.push_back(point);
}
std::size_t idx = _linePoints.size();
_lines.push_back(idx);
bool isFirst = i == 0;
_lines.push_back({idx, isFirst});
line = util::geo::densify(line, 200 * 3);
insertLine(line, false);
}

_curUniqueGeom++;
_attr[numLines + I_OFFSET] = properties;
numLines++;


// MultiPolygon
} else if (type == "MultiPolygon") {
for (auto args1 : coords) {
for (size_t i = 0; i < coords.size(); i++) {
auto args1 = coords[i];
for (auto args2 : args1) {
util::geo::DLine line;
line.reserve(2);
line.reserve(args2.size());

for (std::vector<float> coord : args2) {
auto point = latLngToWebMerc(DPoint(coord[0], coord[1]));
Expand All @@ -242,7 +268,8 @@ void GeoJSONCache::load() {
line.push_back(point);
}
std::size_t idx = _linePoints.size();
_lines.push_back(idx);
bool isFirst = i == 0;
_lines.push_back({idx, isFirst});
line = util::geo::densify(line, 200 * 3);
insertLine(line, true);
}
Expand Down
12 changes: 12 additions & 0 deletions src/qlever-petrimaps/GeoJSONCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ class GeoJSONCache : public GeomCache {
return *this;
};

const util::geo::FPoint& getPoint(ID_TYPE id) const {
return std::get<0>(_points[id]);
}
size_t getLine(ID_TYPE id) const {
return std::get<0>(_lines[id]);
}
size_t getLineEnd(ID_TYPE id) const {
return id + 1 < _lines.size() ? getLine(id + 1) : _linePoints.size();
}

void load();
void setContent(const std::string& content);
std::vector<std::pair<ID_TYPE, ID_TYPE>> getRelObjects() const;
Expand All @@ -36,6 +46,8 @@ class GeoJSONCache : public GeomCache {
// 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:

Expand Down
21 changes: 8 additions & 13 deletions src/qlever-petrimaps/GeomCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,20 @@ class GeomCache {
return ready;
}

const std::vector<util::geo::FPoint>& getPoints() const { return _points; }
const virtual util::geo::FPoint& getPoint(ID_TYPE id) const = 0;
virtual size_t getLine(ID_TYPE id) const = 0;
virtual size_t getLineEnd(ID_TYPE id) const = 0;

const std::vector<util::geo::Point<int16_t>>& getLinePoints() const {
return _linePoints;
}
const std::vector<size_t>& getLines() const { return _lines; }
size_t getLine(ID_TYPE id) const { return _lines[id]; }
size_t getLineEnd(ID_TYPE id) const {
return id + 1 < _lines.size() ? _lines[id + 1] : _linePoints.size();
}

util::geo::FBox getPointBBox(size_t id) const {
return util::geo::getBoundingBox(_points[id]);
}

util::geo::DBox getLineBBox(size_t id) const;

double getLoadStatusPercent(bool total);
double getLoadStatusPercent() { return getLoadStatusPercent(false); };
double getLoadStatusPercent() {
return getLoadStatusPercent(false);
};
int getLoadStatusStage();
size_t getTotalProgress();
size_t getCurrentProgress();
Expand All @@ -72,9 +69,7 @@ class GeomCache {
mutable std::mutex _m;
bool _ready = false;

std::vector<util::geo::FPoint> _points;
std::vector<util::geo::Point<int16_t>> _linePoints;
std::vector<size_t> _lines;

static bool pointValid(const util::geo::FPoint& p);
static bool pointValid(const util::geo::DPoint& p);
Expand Down
12 changes: 12 additions & 0 deletions src/qlever-petrimaps/SPARQLCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ class SPARQLCache : public GeomCache {
return *this;
};

const util::geo::FPoint& getPoint(ID_TYPE id) const {
return _points[id];
}
size_t getLine(ID_TYPE id) const {
return _lines[id];
}
size_t getLineEnd(ID_TYPE id) const {
return id + 1 < _lines.size() ? getLine(id + 1) : _linePoints.size();
}

std::string load(const std::string& cacheFile);
void request();
size_t requestSize();
Expand Down Expand Up @@ -83,6 +93,8 @@ class SPARQLCache : public GeomCache {
IdMapping _lastQidToId;

std::vector<IdMapping> _qidToId;
std::vector<util::geo::FPoint> _points;
std::vector<size_t> _lines;

std::string _dangling, _prev, _raw;
ParseState _state;
Expand Down
8 changes: 8 additions & 0 deletions src/qlever-petrimaps/server/GeoJSONRequestor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,20 @@ void GeoJSONRequestor::request() {
_ready = false;
_objects.clear();
_clusterObjects.clear();
_rowIdToObjectId.clear();

_objects = _cache->getRelObjects();
_numObjects = _objects.size();

LOG(INFO) << "[REQUESTOR] ... done, got " << _objects.size() << " objects.";

// Create mapping rowId to objectId for multigeometries
for (size_t objectId = 0; objectId < _objects.size(); objectId++) {
std::pair<ID_TYPE, ID_TYPE> object = _objects[objectId];
ID_TYPE rowId = object.second;
_rowIdToObjectId[rowId] = objectId;
}

LOG(INFO) << "[REQUESTOR] Calculating bounding box of result...";

util::geo::FBox pointBbox;
Expand Down
Loading

0 comments on commit 6085247

Please sign in to comment.