diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 48a1b36fb..9abb7c067 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,28 +1,29 @@ add_subdirectory( tilecreator ) add_subdirectory( tilecreator-srtm2 ) add_subdirectory( routing-instructions ) add_subdirectory( dateline ) add_subdirectory( asc2kml ) add_subdirectory( constellations2kml ) add_subdirectory( dso2kml ) add_subdirectory( iau2kml ) add_subdirectory( kml2cache ) add_subdirectory( kml2kml ) +add_subdirectory( osm-simplify ) add_subdirectory( poly2kml ) add_subdirectory( pnt2svg ) add_subdirectory( pntdel ) add_subdirectory( pntreplace ) add_subdirectory( shp2pn2 ) add_subdirectory( svg2pnt ) add_subdirectory( maptheme-previewimage ) add_subdirectory( mapreproject ) add_subdirectory( speaker-files ) add_subdirectory( stars ) find_package(Protobuf) find_package(ZLIB) if(PROTOBUF_FOUND AND ZLIB_FOUND) add_subdirectory( osm-addresses ) # osm-sisyphus does not depend on zlib and protobuf, but osm-addresses add_subdirectory( osm-sisyphus ) endif() diff --git a/tools/osm-simplify/CMakeLists.txt b/tools/osm-simplify/CMakeLists.txt new file mode 100644 index 000000000..02754fe35 --- /dev/null +++ b/tools/osm-simplify/CMakeLists.txt @@ -0,0 +1,42 @@ +SET (TARGET osm-simplify) +PROJECT (${TARGET}) + +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/geodata/writer +../../src/lib/marble/geodata/parser +../../src/lib/marble/geodata/data +../../src/lib/marble/geodata +../../src/lib/marble/ +) + +set( ${TARGET}_SRC +main.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 +) +add_definitions( -DMAKE_MARBLE_LIB ) +add_executable( ${TARGET} ${${TARGET}_SRC} ) + +target_link_libraries( ${TARGET} ) +target_link_libraries( ${TARGET} Qt5::Core marblewidget-qt5 ) diff --git a/tools/osm-simplify/main.cpp b/tools/osm-simplify/main.cpp new file mode 100644 index 000000000..f26e889c5 --- /dev/null +++ b/tools/osm-simplify/main.cpp @@ -0,0 +1,123 @@ +// +// 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 David Kolozsvari +// + +#include "OsmParser.h" +#include "GeoWriter.h" + +#include +#include +#include +#include + +#include + +using namespace Marble; + +enum DebugLevel { + Debug, + Info, + Mute +}; + +DebugLevel debugLevel = Info; + +void debugOutput( QtMsgType type, const QMessageLogContext &context, const QString &msg ) +{ + switch ( type ) { + case QtDebugMsg: + if ( debugLevel == Debug ) { + qDebug() << "Debug: " << context.file << ":" << context.line << " " << msg; + } + break; + case QtInfoMsg: + case QtWarningMsg: + if ( debugLevel < Mute ) { + qDebug() << "Info: " << context.file << ":" << context.line << " " << msg; + } + break; + case QtCriticalMsg: + if ( debugLevel < Mute ) { + qDebug() << "Warning: " << context.file << ":" << context.line << " " << msg; + } + break; + case QtFatalMsg: + if ( debugLevel < Mute ) { + qDebug() << "Fatal: " << context.file << ":" << context.line << " " << msg; + abort(); + } + } +} +void usage() +{ + qDebug() << "Usage: osm-simplify [options] input.osm output.osm"; + qDebug() << "\t-q quiet"; + qDebug() << "\t-v debug output"; +} + +int main(int argc, char *argv[]) +{ + QCoreApplication a(argc, argv); + + if ( argc < 3 ) { + usage(); + return 1; + } + + QString inputSrc = argv[argc-2]; + QString outputSrc = argv[argc-1]; + + for ( int i=1; i< argc-2; ++i ) { + QString arg( argv[i] ); + if ( arg == "-v" ) { + debugLevel = Debug; + } else if ( arg == "-q" ) { + debugLevel = Mute; + } else { + usage(); + return 1; + } + } + + qInstallMessageHandler( debugOutput ); + + QFileInfo file( inputSrc ); + if ( !file.exists() ) { + qDebug() << "File " << file.absoluteFilePath() << " does not exist. Exiting."; + return 2; + } + + if ( file.suffix() == "osm") { + + QString error; + Marble::GeoDataDocument* osmMap = OsmParser::parse(inputSrc, error); + + if(!error.isEmpty()) { + qDebug() << error; + return 3; + } + + Marble::GeoWriter writer; + writer.setDocumentType("0.6"); + + QFile outputfile( outputSrc ); + outputfile.open( QIODevice::WriteOnly ); + if ( !writer.write( &outputfile, osmMap ) ) { + qDebug() << "Could not write the file " << outputSrc; + return 4; + } + + qDebug() << "Done."; + } else { + qDebug() << "Unsupported file format: " << outputSrc; + return 5; + } + + return 0; +}