summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Nienhüser <nienhueser@kde.org>2016-08-14 15:18:07 (GMT)
committerDennis Nienhüser <nienhueser@kde.org>2016-08-14 15:18:07 (GMT)
commit570a430b12409a5462554c35fda2bcf51576d14d (patch)
tree44cd7d6d7eecb70054f5745e6312865256639f56
parentf006fcb9b2d928b7cab555d595cbcc14f1bc0d47 (diff)
Add TileIterator to simplify traversing region extracts in the future.
-rw-r--r--tools/osm-simplify/CMakeLists.txt15
-rw-r--r--tools/osm-simplify/TileIterator.cpp85
-rw-r--r--tools/osm-simplify/TileIterator.h44
-rw-r--r--tools/osm-simplify/main.cpp65
4 files changed, 169 insertions, 40 deletions
diff --git a/tools/osm-simplify/CMakeLists.txt b/tools/osm-simplify/CMakeLists.txt
index fa67201..9767a60 100644
--- a/tools/osm-simplify/CMakeLists.txt
+++ b/tools/osm-simplify/CMakeLists.txt
@@ -26,13 +26,14 @@ set( ${TARGET}_SRC
main.cpp
BaseClipper.cpp
BaseFilter.cpp
- PlacemarkFilter.cpp
- ShpCoastlineProcessor.cpp
- LineStringProcessor.cpp
- TinyPlanetProcessor.cpp
- NodeReducer.cpp
- TagsFilter.cpp
- WayConcatenator.cpp
+PlacemarkFilter.cpp
+ShpCoastlineProcessor.cpp
+LineStringProcessor.cpp
+TinyPlanetProcessor.cpp
+NodeReducer.cpp
+TagsFilter.cpp
+TileIterator.cpp
+WayConcatenator.cpp
WayChunk.cpp
)
diff --git a/tools/osm-simplify/TileIterator.cpp b/tools/osm-simplify/TileIterator.cpp
new file mode 100644
index 0000000..0de09e6
--- /dev/null
+++ b/tools/osm-simplify/TileIterator.cpp
@@ -0,0 +1,85 @@
+//
+// 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 "TileIterator.h"
+#include "TileId.h"
+
+#include <QDebug>
+
+namespace Marble {
+
+TileIterator::const_iterator const TileIterator::s_end = TileIterator();
+
+const TileIterator &TileIterator::operator*()
+{
+ return *this;
+}
+
+bool TileIterator::operator!=(const TileIterator::const_iterator &other) const
+{
+ return m_state != other.m_state;
+}
+
+TileIterator::const_iterator &TileIterator::operator++()
+{
+ if (m_state.x() >= m_bounds.right()) {
+ m_state.setX(m_bounds.left());
+ if (m_state.y() < m_bounds.bottom()) {
+ ++m_state.ry();
+ } else {
+ *this = s_end;
+ }
+ } else {
+ ++m_state.rx();
+ }
+ return *this;
+}
+
+TileIterator::TileIterator(const GeoDataLatLonBox &latLonBox, int zoomLevel)
+{
+ qreal north, west, south, east;
+ latLonBox.boundaries(north, south, east, west);
+ TileId const topLeft = TileId::fromCoordinates(GeoDataCoordinates(west, north), zoomLevel);
+ TileId const bottomRight = TileId::fromCoordinates(GeoDataCoordinates(east, south), zoomLevel);
+ m_bounds.setLeft(topLeft.x());
+ m_bounds.setTop(topLeft.y());
+ m_bounds.setRight(bottomRight.x());
+ m_bounds.setBottom(bottomRight.y());
+}
+
+TileIterator::const_iterator TileIterator::begin() const
+{
+ TileIterator iter = *this;
+ iter.m_state = iter.m_bounds.topLeft();
+ return iter;
+}
+
+TileIterator::const_iterator TileIterator::end() const
+{
+ return s_end;
+}
+
+int TileIterator::x() const
+{
+ return m_state.x();
+}
+
+int TileIterator::y() const
+{
+ return m_state.y();
+}
+
+TileIterator::TileIterator() :
+ m_state(-1, -1)
+{
+ // nothing to do
+}
+
+}
diff --git a/tools/osm-simplify/TileIterator.h b/tools/osm-simplify/TileIterator.h
new file mode 100644
index 0000000..91eb54c
--- /dev/null
+++ b/tools/osm-simplify/TileIterator.h
@@ -0,0 +1,44 @@
+//
+// 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>
+//
+
+#ifndef MARBLE_TILEITERATOR_H
+#define MARBLE_TILEITERATOR_H
+
+#include "GeoDataLatLonBox.h"
+
+#include <QRect>
+
+namespace Marble {
+
+class TileIterator {
+public:
+ typedef TileIterator const_iterator;
+
+ const const_iterator& operator*();
+ bool operator!=( const const_iterator& ) const;
+ const_iterator& operator++();
+ const_iterator begin() const;
+ const_iterator end() const;
+
+ TileIterator(const GeoDataLatLonBox &latLonBox, int zoomLevel);
+ int x() const;
+ int y() const;
+
+private:
+ TileIterator();
+
+ QRect m_bounds;
+ QPoint m_state;
+ static const_iterator const s_end;
+};
+
+}
+
+#endif
diff --git a/tools/osm-simplify/main.cpp b/tools/osm-simplify/main.cpp
index 2a3fcdd..39eba0d 100644
--- a/tools/osm-simplify/main.cpp
+++ b/tools/osm-simplify/main.cpp
@@ -27,6 +27,7 @@
#include "TinyPlanetProcessor.h"
#include "NodeReducer.h"
#include "WayConcatenator.h"
+#include "TileIterator.h"
using namespace Marble;
@@ -133,7 +134,6 @@ int main(int argc, char *argv[])
QString inputFileName = args.at(0);
QString mergeFileName = parser.value("merge");
- QString const extension = parser.value("extension");
bool debug = parser.isSet("debug");
bool silent = parser.isSet("silent");
unsigned int zoomLevel = parser.value("zoom-level").toInt();
@@ -186,53 +186,52 @@ int main(int argc, char *argv[])
if(file.suffix() == "shp" && parser.isSet("cut-to-tiles")) {
ShpCoastlineProcessor processor(map);
processor.process();
- unsigned int N = pow(2, zoomLevel);
- for(unsigned int x = 0; x < N; ++x) {
- for(unsigned int y = 0; y < N; ++y) {
- GeoDataDocument* tile = processor.cutToTiles(zoomLevel, x, y);
- if (!writeTile(parser, outputName, tile, x, y, zoomLevel)) {
- return 4;
- }
- qInfo() << tile->name() << " done";
- delete tile;
+ GeoDataLatLonBox world(85.0, -85.0, 180.0, -180.0, GeoDataCoordinates::Degree);
+ //TileIterator iter(map->latLonAltBox(), zoomLevel);
+ TileIterator iter(world, zoomLevel);
+ foreach(auto const &tileId, iter) {
+ GeoDataDocument* tile = processor.cutToTiles(zoomLevel, tileId.x(), tileId.y());
+ if (!writeTile(parser, outputName, tile, tileId.x(), tileId.y(), zoomLevel)) {
+ return 4;
}
+ qInfo() << tile->name() << " done";
+ delete tile;
}
} else if (file.suffix() == "osm" && parser.isSet("cut-to-tiles") && parser.isSet("merge")) {
TinyPlanetProcessor processor(map);
processor.process();
ShpCoastlineProcessor shpProcessor(mergeMap);
shpProcessor.process();
- unsigned int N = pow(2, zoomLevel);
- for(unsigned int x = 0; x < N; ++x) {
- for(unsigned int y = 0; y < N; ++y) {
- GeoDataDocument* tile1 = processor.cutToTiles(zoomLevel, x, y);
- GeoDataDocument* tile2 = shpProcessor.cutToTiles(zoomLevel, x, y);
- GeoDataDocument* tile = mergeDocuments(tile1, tile2);
- if (!writeTile(parser, outputName, tile, x, y, zoomLevel)) {
- return 4;
- }
- qInfo() << tile->name() << " done";
- delete tile1;
- delete tile2;
- delete tile;
+ GeoDataLatLonBox world(85.0, -85.0, 180.0, -180.0, GeoDataCoordinates::Degree);
+ //TileIterator iter(map->latLonAltBox(), zoomLevel);
+ TileIterator iter(world, zoomLevel);
+ foreach(auto const &tileId, iter) {
+ GeoDataDocument* tile1 = processor.cutToTiles(zoomLevel, tileId.x(), tileId.y());
+ GeoDataDocument* tile2 = shpProcessor.cutToTiles(zoomLevel, tileId.x(), tileId.y());
+ GeoDataDocument* tile = mergeDocuments(tile1, tile2);
+ if (!writeTile(parser, outputName, tile, tileId.x(), tileId.y(), zoomLevel)) {
+ return 4;
}
+ qInfo() << tile->name() << " done";
+ delete tile1;
+ delete tile2;
+ delete tile;
}
} else if (file.suffix() == "osm" && parser.isSet("cut-to-tiles")) {
TinyPlanetProcessor processor(map);
processor.process();
- unsigned int N = pow(2, zoomLevel);
-
- for(unsigned int x = 0; x < N; ++x) {
- for(unsigned int y = 0; y < N; ++y) {
- GeoDataDocument* tile = processor.cutToTiles(zoomLevel, x, y);
- if (!writeTile(parser, outputName, tile, x, y, zoomLevel)) {
- return 4;
- }
- qInfo() << tile->name() << " done";
- delete tile;
+ GeoDataLatLonBox world(85.0, -85.0, 180.0, -180.0, GeoDataCoordinates::Degree);
+ //TileIterator iter(map->latLonAltBox(), zoomLevel);
+ TileIterator iter(world, zoomLevel);
+ foreach(auto const &tileId, iter) {
+ GeoDataDocument* tile = processor.cutToTiles(zoomLevel, tileId.x(), tileId.y());
+ if (!writeTile(parser, outputName, tile, tileId.x(), tileId.y(), zoomLevel)) {
+ return 4;
}
+ qInfo() << tile->name() << " done";
+ delete tile;
}
} else if(parser.isSet("node-reduce")) {
qDebug()<<"Entered Node reduce"<<endl;