diff --git a/tools/osm-simplify/CMakeLists.txt b/tools/osm-simplify/CMakeLists.txt --- a/tools/osm-simplify/CMakeLists.txt +++ b/tools/osm-simplify/CMakeLists.txt @@ -1,16 +1,16 @@ +cmake_minimum_required(VERSION 2.8.12) SET (TARGET osm-simplify) PROJECT (${TARGET}) find_package(Qt5Core REQUIRED) -find_package(Qt5Widgets) +find_package(Qt5Widgets REQUIRED) find_package(Qt5Declarative) +find_package(Qt5Gui REQUIRED) include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} -../../src/plugins/runner/osm -../../src/plugins/runner/osm/writers -../../src/plugins/runner/osm/translators +../../src/lib/marble/osm ../../src/lib/marble/geodata/writer ../../src/lib/marble/geodata/parser ../../src/lib/marble/geodata/data @@ -18,32 +18,19 @@ ../../src/lib/marble/ ) + set( ${TARGET}_SRC main.cpp +BaseClipper.cpp BaseFilter.cpp PlacemarkFilter.cpp + ShpCoastlineProcessor.cpp LineStringProcessor.cpp -../../src/plugins/runner/osm/OsmParser.cpp -../../src/plugins/runner/osm/o5mreader.cpp -../../src/plugins/runner/osm/OsmElementDictionary.cpp -../../src/plugins/runner/osm/OsmNode.cpp -../../src/plugins/runner/osm/OsmParser.cpp -../../src/plugins/runner/osm/OsmPlugin.cpp -../../src/plugins/runner/osm/OsmRelation.cpp -../../src/plugins/runner/osm/OsmRunner.cpp -../../src/plugins/runner/osm/OsmWay.cpp -../../src/plugins/runner/osm/translators/OsmDocumentTagTranslator.cpp -../../src/plugins/runner/osm/translators/OsmFeatureTagTranslator.cpp -../../src/plugins/runner/osm/translators/OsmPlacemarkTagTranslator.cpp -../../src/plugins/runner/osm/writers/OsmNodeTagWriter.cpp -../../src/plugins/runner/osm/writers/OsmObjectAttributeWriter.cpp -../../src/plugins/runner/osm/writers/OsmRelationTagWriter.cpp -../../src/plugins/runner/osm/writers/OsmTagTagWriter.cpp -../../src/plugins/runner/osm/writers/OsmTagWriter.cpp -../../src/plugins/runner/osm/writers/OsmWayTagWriter.cpp + NodeReducer.cpp ) + add_definitions( -DMAKE_MARBLE_LIB ) add_executable( ${TARGET} ${${TARGET}_SRC} ) - + target_link_libraries( ${TARGET} ) -target_link_libraries( ${TARGET} Qt5::Core marblewidget-qt5 ) +target_link_libraries( ${TARGET} Qt5::Core marblewidget-qt5) \ No newline at end of file diff --git a/tools/osm-simplify/NodeReducer.h b/tools/osm-simplify/NodeReducer.h new file mode 100644 --- /dev/null +++ b/tools/osm-simplify/NodeReducer.h @@ -0,0 +1,28 @@ +// +// 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 Akshat Tandon +// + +#ifndef MARBLE_NODEREDUCER_H +#define MARBLE_NODEREDUCER_H + +#include "PlacemarkFilter.h" +#include "GeoDataLineString.h" + +class NodeReducer : public PlacemarkFilter{ +public: + NodeReducer(GeoDataDocument* document, int zoomLevel); + virtual void process(); +private: + void reduce(GeoDataLineString* lineString); + static qreal resolutionForLevel(int level); + qreal m_resolution; + qint64 m_count; +}; + +#endif \ No newline at end of file diff --git a/tools/osm-simplify/NodeReducer.cpp b/tools/osm-simplify/NodeReducer.cpp new file mode 100644 --- /dev/null +++ b/tools/osm-simplify/NodeReducer.cpp @@ -0,0 +1,128 @@ +// +// 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 Akshat Tandon +// + +#include "BaseClipper.h" +#include "GeoDataPlacemark.h" +#include "GeoDataTypes.h" +#include "GeoDataLineString.h" +#include "GeoDataCoordinates.h" +#include "MarbleMath.h" +#include "NodeReducer.h" + +#include +#include + +NodeReducer::NodeReducer(GeoDataDocument* document, int zoomLevel) : + PlacemarkFilter(document) +{ + m_resolution = resolutionForLevel(zoomLevel); + m_count = 0; +} + +void NodeReducer::process(){ + foreach (GeoDataObject* object, m_objects) { + GeoDataPlacemark* placemark = static_cast(object); + if(placemark->geometry()->nodeType() == GeoDataTypes::GeoDataLineStringType) + reduce(static_cast(placemark->geometry()) ); + else if(placemark->geometry()->nodeType() == GeoDataTypes::GeoDataLinearRingType) + reduce(static_cast(placemark->geometry()) ); + else if(placemark->geometry()->nodeType() == GeoDataTypes::GeoDataPolygonType){ + GeoDataPolygon *polygon = static_cast(placemark->geometry()); + GeoDataLinearRing &outerBoundary = polygon->outerBoundary(); + reduce(&outerBoundary); + QVector& innerBoundaries = polygon->innerBoundaries(); + for(int i = 0; i < innerBoundaries.size(); i++){ + reduce(&innerBoundaries[i]); + } + } + } + qDebug()<<"Total nodes reduced: "<size(); + if(prevSize < 2) + return; + QVector::iterator itCoords = lineString->begin(); + GeoDataCoordinates currentCoords = *itCoords; + ++itCoords; + while(itCoords != (lineString->end() - 1)){ + if(distanceSphere( currentCoords, *itCoords ) < m_resolution){ + lineString->erase(itCoords); + }else{ + currentCoords = *itCoords; + ++itCoords; + } + } + qint64 reducedSize = lineString->size(); + m_count += (prevSize - reducedSize); + //qDebug()<<"Nodes reduced "<<(prevSize - reducedSize)< // -#include "OsmParser.h" + #include "GeoWriter.h" +#include "MarbleModel.h" +#include "ParsingRunnerManager.h" -#include +#include #include #include #include #include +#include +#include #include #include "LineStringProcessor.h" +#include "ShpCoastlineProcessor.h" +#include "NodeReducer.h" using namespace Marble; + enum DebugLevel { Debug, Info, @@ -41,17 +41,17 @@ break; case QtInfoMsg: if ( debugLevel < Mute ) { - qDebug() << "Debug: " << context.file << ":" << context.line << " " << msg; + qInfo() << "Info: " << context.file << ":" << context.line << " " << msg; } break; case QtWarningMsg: if ( debugLevel < Mute ) { - qDebug() << "Info: " << context.file << ":" << context.line << " " << msg; + qDebug() << "Warning: " << context.file << ":" << context.line << " " << msg; } break; case QtCriticalMsg: if ( debugLevel < Mute ) { - qDebug() << "Warning: " << context.file << ":" << context.line << " " << msg; + qDebug() << "Critical: " << context.file << ":" << context.line << " " << msg; } break; case QtFatalMsg: @@ -69,17 +69,17 @@ int main(int argc, char *argv[]) { - QCoreApplication app(argc, argv); + QApplication app(argc, argv); - QCoreApplication::setApplicationName("osm-simplify"); - QCoreApplication::setApplicationVersion("0.1"); + QApplication::setApplicationName("osm-simplify"); + QApplication::setApplicationVersion("0.1"); QCommandLineParser parser; parser.setApplicationDescription("A tool for Marble, which is used to reduce the details of osm maps."); parser.addHelpOption(); parser.addVersionOption(); - parser.addPositionalArgument("input.osm", "The input .osm file."); - parser.addPositionalArgument("output.osm", "The output .osm file."); + parser.addPositionalArgument("input", "The input .osm or .shp file."); + parser.addOptions({ { @@ -93,10 +93,27 @@ }, { - {"ns", "no-streets-smaller-than"}, - QCoreApplication::translate("main", "eliminates streets which have realsize smaller than "), - QCoreApplication::translate("main", "real number") + {"c", "cut-to-tiles"}, + QCoreApplication::translate("main", "Cuts into tiles based on the zoom level passed by "), + QCoreApplication::translate("main", "number") + }, + + { + {"n", "node-reduce"}, + QCoreApplication::translate("main", "Reduces the number of nodes for a given way based on zoom level"), + }, + + { + {"z", "zoom-level"}, + QCoreApplication::translate("main", "Zoom level according to which OSM information has to be processed."), + QCoreApplication::translate("main", "number") }, + + { + {"o", "output"}, + QCoreApplication::translate("main", "Generates an output .osmfile based on other flags. This won't work together with the cut-to-tiles flag."), + QCoreApplication::translate("main", "output_file.osm") + } }); // Process the actual command line arguments given by the user @@ -110,12 +127,20 @@ // input is args.at(0), output is args.at(1) QString inputFileName = args.at(0); - QString outputFileName = args.at(1); + bool debug = parser.isSet("debug"); bool mute = parser.isSet("mute"); - QString smallStreetLimit = parser.value("no-streets-smaller-than"); // just an example - + unsigned int zoomLevel = parser.value("zoom-level").toInt(); + qDebug()<<"Zoom level is "<name() << " done"; + + delete tile; + } + } + } else if(parser.isSet("node-reduce")) { + qDebug()<<"Entered Node reduce"<