summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Nienhüser <nienhueser@kde.org>2016-10-01 06:35:20 (GMT)
committerDennis Nienhüser <nienhueser@kde.org>2016-10-01 06:35:20 (GMT)
commitec804223cd061d6b4b33cb5f4fe8924002cd2aec (patch)
tree37a02df18fdc522fda811ec91956a3bd140b3aae
parent3078a3cb8af2d24ac6e60ee035e42bae48fe120e (diff)
Move LandmassLoader to its own file, rename TileDirectory
-rw-r--r--tools/vectorosm-tilecreator/CMakeLists.txt1
-rw-r--r--tools/vectorosm-tilecreator/TileDirectory.cpp56
-rw-r--r--tools/vectorosm-tilecreator/TileDirectory.h35
-rw-r--r--tools/vectorosm-tilecreator/main.cpp61
4 files changed, 96 insertions, 57 deletions
diff --git a/tools/vectorosm-tilecreator/CMakeLists.txt b/tools/vectorosm-tilecreator/CMakeLists.txt
index 038b51d..5850cf8 100644
--- a/tools/vectorosm-tilecreator/CMakeLists.txt
+++ b/tools/vectorosm-tilecreator/CMakeLists.txt
@@ -30,6 +30,7 @@ BaseFilter.cpp
NodeReducer.cpp
TagsFilter.cpp
TileIterator.cpp
+TileDirectory.cpp
VectorClipper.cpp
WayConcatenator.cpp
WayChunk.cpp
diff --git a/tools/vectorosm-tilecreator/TileDirectory.cpp b/tools/vectorosm-tilecreator/TileDirectory.cpp
new file mode 100644
index 0000000..951b1dd
--- /dev/null
+++ b/tools/vectorosm-tilecreator/TileDirectory.cpp
@@ -0,0 +1,56 @@
+//
+// This file is part of the Marble Virtual Globe.
+//
+// This program is free software licensed under the GNU LGPL. You can
+// find a copy of this license in LICENSE.txt in the top directory of
+// the source code.
+//
+// Copyright 2016 Dennis Nienhüser <nienhueser@kde.org>
+//
+
+#include "TileDirectory.h"
+
+#include <QFileInfo>
+#include <QDebug>
+
+namespace Marble {
+
+TileDirectory::TileDirectory(const QString &baseDir, ParsingRunnerManager &manager, QString const &extension) :
+ m_baseDir(baseDir),
+ m_manager(manager),
+ m_zoomLevel(QFileInfo(baseDir).baseName().toInt()),
+ m_tileX(-1),
+ m_tileY(-1),
+ m_extension(extension)
+{
+ // nothing to do
+}
+
+QSharedPointer<GeoDataDocument> TileDirectory::load(int zoomLevel, int tileX, int tileY)
+{
+ int const zoomDiff = zoomLevel - m_zoomLevel;
+ int const x = tileX >> zoomDiff;
+ int const y = tileY >> zoomDiff;
+ if (x == m_tileX && y == m_tileY) {
+ return m_landmass;
+ }
+
+ m_tileX = x;
+ m_tileY = y;
+ QString const filename = QString("%1/%2/%3.%4").arg(m_baseDir).arg(x).arg(y).arg(m_extension);
+ m_landmass = open(filename, m_manager);
+ return m_landmass;
+}
+
+QSharedPointer<GeoDataDocument> TileDirectory::open(const QString &filename, ParsingRunnerManager &manager)
+{
+ // Timeout is set to 10 min. If the file is reaaally huge, set it to something bigger.
+ GeoDataDocument* map = manager.openFile(filename, DocumentRole::MapDocument, 600000);
+ if(map == nullptr) {
+ qWarning() << "File" << filename << "couldn't be loaded.";
+ }
+ QSharedPointer<GeoDataDocument> result = QSharedPointer<GeoDataDocument>(map);
+ return result;
+}
+
+}
diff --git a/tools/vectorosm-tilecreator/TileDirectory.h b/tools/vectorosm-tilecreator/TileDirectory.h
new file mode 100644
index 0000000..ceebeae
--- /dev/null
+++ b/tools/vectorosm-tilecreator/TileDirectory.h
@@ -0,0 +1,35 @@
+//
+// This file is part of the Marble Virtual Globe.
+//
+// This program is free software licensed under the GNU LGPL. You can
+// find a copy of this license in LICENSE.txt in the top directory of
+// the source code.
+//
+// Copyright 2016 Dennis Nienhüser <nienhueser@kde.org>
+//
+
+
+#include <QSharedPointer>
+#include <ParsingRunnerManager.h>
+
+namespace Marble {
+
+class TileDirectory
+{
+public:
+ TileDirectory(const QString &baseDir, ParsingRunnerManager &manager, const QString &extension);
+ QSharedPointer<GeoDataDocument> load(int zoomLevel, int tileX, int tileY);
+
+ static QSharedPointer<GeoDataDocument> open(const QString &filename, ParsingRunnerManager &manager);
+
+private:
+ QString m_baseDir;
+ ParsingRunnerManager &m_manager;
+ QSharedPointer<GeoDataDocument> m_landmass;
+ int m_zoomLevel;
+ int m_tileX;
+ int m_tileY;
+ QString m_extension;
+};
+
+}
diff --git a/tools/vectorosm-tilecreator/main.cpp b/tools/vectorosm-tilecreator/main.cpp
index 94b73d0..3d61182 100644
--- a/tools/vectorosm-tilecreator/main.cpp
+++ b/tools/vectorosm-tilecreator/main.cpp
@@ -34,6 +34,7 @@
#include "NodeReducer.h"
#include "WayConcatenator.h"
#include "TileIterator.h"
+#include "TileDirectory.h"
#include <iostream>
@@ -172,34 +173,6 @@ QStringList tagsFilteredIn(int zoomLevel)
return tags;
}
-QSharedPointer<GeoDataDocument> open(const QString &filename, ParsingRunnerManager &manager)
-{
- // Timeout is set to 10 min. If the file is reaaally huge, set it to something bigger.
- GeoDataDocument* map = manager.openFile(filename, DocumentRole::MapDocument, 600000);
- if(map == nullptr) {
- qWarning() << "File" << filename << "couldn't be loaded.";
- }
- QSharedPointer<GeoDataDocument> result = QSharedPointer<GeoDataDocument>(map);
- return result;
-}
-
-class LandmassLoader
-{
-public:
- LandmassLoader(const QString &baseDir, ParsingRunnerManager &manager, const QString &extension);
- QSharedPointer<GeoDataDocument> load(int zoomLevel, int tileX, int tileY);
-
-private:
- QString m_baseDir;
- ParsingRunnerManager &m_manager;
- QSharedPointer<GeoDataDocument> m_landmass;
- int m_zoomLevel;
- int m_tileX;
- int m_tileY;
- QString m_extension;
-};
-
-
GeoDataDocument* mergeDocuments(GeoDataDocument* map1, GeoDataDocument* map2)
{
GeoDataDocument* mergedMap = new GeoDataDocument(*map1);
@@ -347,7 +320,7 @@ int main(int argc, char *argv[])
}
}
} else if (*zoomLevels.cbegin() <= 9) {
- auto map = open(inputFileName, manager);
+ auto map = TileDirectory::open(inputFileName, manager);
VectorClipper processor(map.data());
GeoDataLatLonBox world(85.0, -85.0, 180.0, -180.0, GeoDataCoordinates::Degree);
foreach(auto zoomLevel, zoomLevels) {
@@ -372,8 +345,8 @@ int main(int argc, char *argv[])
}
}
} else {
- auto map = open(inputFileName, manager);
- LandmassLoader loader(parser.value("merge"), manager, parser.value("extension"));
+ auto map = TileDirectory::open(inputFileName, manager);
+ TileDirectory loader(parser.value("merge"), manager, parser.value("extension"));
QSharedPointer<VectorClipper> landMassClipper;
QSharedPointer<GeoDataDocument> mergeMap;
@@ -425,29 +398,3 @@ int main(int argc, char *argv[])
return 0;
}
-LandmassLoader::LandmassLoader(const QString &baseDir, ParsingRunnerManager &manager, QString const &extension) :
- m_baseDir(baseDir),
- m_manager(manager),
- m_zoomLevel(QFileInfo(baseDir).baseName().toInt()),
- m_tileX(-1),
- m_tileY(-1),
- m_extension(extension)
-{
- // nothing to do
-}
-
-QSharedPointer<GeoDataDocument> LandmassLoader::load(int zoomLevel, int tileX, int tileY)
-{
- int const zoomDiff = zoomLevel - m_zoomLevel;
- int const x = tileX >> zoomDiff;
- int const y = tileY >> zoomDiff;
- if (x == m_tileX && y == m_tileY) {
- return m_landmass;
- }
-
- m_tileX = x;
- m_tileY = y;
- QString const filename = QString("%1/%2/%3.%4").arg(m_baseDir).arg(x).arg(y).arg(m_extension);
- m_landmass = open(filename, m_manager);
- return m_landmass;
-}