Commit 357ad31c authored by Volker Krause's avatar Volker Krause Committed by Torsten Rahn
Browse files

Actually generate o5m tiles in the Tirex backend

This is mostly copy/pasting of the relevant code from cachetiles.cpp,
but this now actually allows to request on-demand created o5m tiles
via mod_tile, assuming the setup this code expects is all there.

This did expose a limitation of mod_tile, which assumes file extensions
to only contain lower-case letters, and thus chokes on our use of "o5m".
This can be worked around though by a simple rewrite rule.
parent 01929656
......@@ -43,11 +43,7 @@ TirexBackend::TirexBackend(QObject *parent)
}
// read map configuration
const auto configFiles = getenv("TIREX_BACKEND_MAP_CONFIGS");
if (configFiles) {
QSettings settings(QString::fromUtf8(configFiles), QSettings::IniFormat);
m_tileDir = settings.value(QLatin1String("tiledir")).toString();
}
m_tileDir = configValue(QStringLiteral("tiledir")).toString();
}
TirexBackend::~TirexBackend() = default;
......@@ -132,9 +128,14 @@ void TirexBackend::tileError(const TirexMetatileRequest &req, const QString &err
m_commandSocket.writeDatagram(reply);
}
QString TirexBackend::tileDir() const
QVariant TirexBackend::configValue(const QString &key) const
{
return m_tileDir;
const auto configFiles = getenv("TIREX_BACKEND_MAP_CONFIGS");
if (configFiles) {
QSettings settings(QString::fromUtf8(configFiles), QSettings::IniFormat);
return settings.value(key);
}
return {};
}
QString TirexBackend::metatileFileName(const TirexMetatileRequest &req)
......@@ -148,7 +149,8 @@ QString TirexBackend::metatileFileName(const TirexMetatileRequest &req)
y >>= 4;
}
QString path = m_tileDir + QLatin1Char('/') + QString::number(req.tile.z) + QLatin1Char('/') +
QString path = m_tileDir + QLatin1Char('/') +
QString::number(req.tile.z) + QLatin1Char('/') +
QString::number(hash[4]) + QLatin1Char('/') +
QString::number(hash[3]) + QLatin1Char('/') +
QString::number(hash[2]) + QLatin1Char('/') +
......
......@@ -48,8 +48,8 @@ public:
/** Indicate a render request failed. */
void tileError(const TirexMetatileRequest &req, const QString &errMsg);
/** The base directory for tile output. */
QString tileDir() const;
/** Returns the value of the entry @p key from the corresponding map configuration file of Tirex. */
QVariant configValue(const QString &key) const;
/** Returns the full file name of the requested meta tile. */
QString metatileFileName(const TirexMetatileRequest &req);
......
/*
SPDX-FileCopyrightText: 2016 Dennis Nienhüser <nienhueser@kde.org>
SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
......@@ -6,10 +7,39 @@
#include "tirexbackend.h"
#include "GeoDataDocumentWriter.h"
#include "GeoDataPolygon.h"
#include "MarbleModel.h"
#include "NodeReducer.h"
#include "ParsingRunnerManager.h"
#include "TileDirectory.h"
#include "TileId.h"
#include "VectorClipper.h"
#include "WayConcatenator.h"
#include <QCoreApplication>
#include <QDebug>
#include <QFile>
using namespace Marble;
GeoDataDocument* mergeDocuments(GeoDataDocument* map1, GeoDataDocument* map2)
{
GeoDataDocument* mergedMap = new GeoDataDocument(*map1);
OsmPlacemarkData marbleLand;
marbleLand.addTag("marble_land","landmass");
for (auto placemark: map2->placemarkList()) {
GeoDataPlacemark* land = new GeoDataPlacemark(*placemark);
if (geodata_cast<GeoDataPolygon>(land->geometry())) {
land->setOsmData(marbleLand);
}
mergedMap->append(land);
}
return mergedMap;
}
int main(int argc, char **argv)
{
setenv("QT_LOGGING_TO_CONSOLE", "0", true); // redirects qDebug to syslog
......@@ -17,8 +47,19 @@ int main(int argc, char **argv)
QCoreApplication app(argc, argv);
TirexBackend backend;
QObject::connect(&backend, &TirexBackend::tileRequested, &app, [&backend](const TirexMetatileRequest &req) {
qDebug() << req.tile.x << req.tile.y << req.tile.z << backend.metatileFileName(req);
MarbleModel model;
ParsingRunnerManager manager(model.pluginManager());
const auto cacheDirectory = backend.configValue(QStringLiteral("cache-directory")).toString();
QObject::connect(&backend, &TirexBackend::tileRequested, &app, [&](const TirexMetatileRequest &req) {
// load bigger tiles at high-z levels, it's more efficient there
// that however assumes we are rendering square power of two meta-tiles with proper alignment
int loadZ = req.tile.z;
if (backend.metatileColumns() == backend.metatileRows() && backend.metatileRows() == 8 && req.tile.z <= 15) {
loadZ = req.tile.z - 3;
}
TileDirectory mapTiles(cacheDirectory, QStringLiteral("planet.osmx"), manager, req.tile.z, loadZ);
TileDirectory landTiles(TileDirectory::Landmass, cacheDirectory, manager, req.tile.z);
QFile f(backend.metatileFileName(req));
if (!f.open(QFile::WriteOnly)) {
......@@ -29,10 +70,23 @@ int main(int argc, char **argv)
backend.writeMetatileHeader(&f, req.tile);
for (int x = 0; x < backend.metatileColumns(); ++x) {
for (int y = 0; y < backend.metatileRows(); ++y) {
QByteArray b = "TEST: " + QByteArray::number(x + req.tile.x) + "x" + QByteArray::number(y + req.tile.y);
auto const tileId = TileId (0, req.tile.z, x + req.tile.x, y + req.tile.y);
using GeoDocPtr = QSharedPointer<GeoDataDocument>;
GeoDocPtr tile1 = GeoDocPtr(mapTiles.clip(tileId.zoomLevel(), tileId.x(), tileId.y()));
TagsFilter::removeAnnotationTags(tile1.data());
if (tileId.zoomLevel() < 17) {
WayConcatenator concatenator(tile1.data());
}
NodeReducer nodeReducer(tile1.data(), tileId);
GeoDocPtr tile2 = GeoDocPtr(landTiles.clip(tileId.zoomLevel(), tileId.x(), tileId.y()));
GeoDocPtr combined = GeoDocPtr(mergeDocuments(tile1.data(), tile2.data()));
const auto offset = f.pos();
f.write(b);
backend.writeMetatileEntry(&f, x * backend.metatileColumns() + y, offset, b.size());
if (GeoDataDocumentWriter::write(&f, *combined, QStringLiteral("o5m"))) {
backend.writeMetatileEntry(&f, x * backend.metatileColumns() + y, offset, f.pos() - offset);
} else {
qWarning() << "Could not write the tile " << combined->name();
}
}
}
backend.tileDone(req);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment