Changeset View
Changeset View
Standalone View
Standalone View
tools/osm-simplify/main.cpp
Show All 17 Lines | |||||
18 | #include <QFileInfo> | 18 | #include <QFileInfo> | ||
19 | #include <QDir> | 19 | #include <QDir> | ||
20 | #include <QString> | 20 | #include <QString> | ||
21 | 21 | | |||
22 | #include <QMessageLogContext> | 22 | #include <QMessageLogContext> | ||
23 | 23 | | |||
24 | #include "LineStringProcessor.h" | 24 | #include "LineStringProcessor.h" | ||
25 | #include "ShpCoastlineProcessor.h" | 25 | #include "ShpCoastlineProcessor.h" | ||
26 | #include "NodeReducer.h" | ||||
26 | 27 | | |||
27 | using namespace Marble; | 28 | using namespace Marble; | ||
28 | 29 | | |||
29 | enum DebugLevel { | 30 | enum DebugLevel { | ||
30 | Debug, | 31 | Debug, | ||
31 | Info, | 32 | Info, | ||
32 | Mute | 33 | Mute | ||
33 | }; | 34 | }; | ||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Line(s) | 87 | parser.addOptions({ | |||
91 | 92 | | |||
92 | { | 93 | { | ||
93 | {"m","mute"}, | 94 | {"m","mute"}, | ||
94 | QCoreApplication::translate("main", "Don't output to terminal.") | 95 | QCoreApplication::translate("main", "Don't output to terminal.") | ||
95 | }, | 96 | }, | ||
96 | 97 | | |||
97 | { | 98 | { | ||
98 | {"c", "cut-to-tiles"}, | 99 | {"c", "cut-to-tiles"}, | ||
99 | QCoreApplication::translate("main", "Cuts into tiles based on the zoom level passed by <number>"), | 100 | QCoreApplication::translate("main", "Cuts into tiles based on the zoom level passed using -z."), | ||
101 | //QCoreApplication::translate("main", "number") | ||||
102 | }, | ||||
103 | | ||||
104 | { | ||||
105 | {"n", "node-reduce"}, | ||||
106 | QCoreApplication::translate("main", "Reduces the number of nodes for a given way based on zoom level"), | ||||
107 | }, | ||||
108 | | ||||
109 | { | ||||
110 | {"z", "zoom-level"}, | ||||
111 | QCoreApplication::translate("main", "Zoom level according to which OSM information has to be processed."), | ||||
100 | QCoreApplication::translate("main", "number") | 112 | QCoreApplication::translate("main", "number") | ||
101 | }, | 113 | }, | ||
102 | 114 | | |||
103 | { | 115 | { | ||
104 | {"o", "output"}, | 116 | {"o", "output"}, | ||
105 | QCoreApplication::translate("main", "Generates an output .osmfile based on other flags. This won't work together with the cut-to-tiles flag."), | 117 | QCoreApplication::translate("main", "Generates an output .osmfile based on other flags. This won't work together with the cut-to-tiles flag."), | ||
106 | QCoreApplication::translate("main", "output_file.osm") | 118 | QCoreApplication::translate("main", "output_file.osm") | ||
107 | } | 119 | } | ||
108 | }); | 120 | }); | ||
109 | 121 | | |||
110 | // Process the actual command line arguments given by the user | 122 | // Process the actual command line arguments given by the user | ||
111 | parser.process(app); | 123 | parser.process(app); | ||
112 | 124 | | |||
113 | const QStringList args = parser.positionalArguments(); | 125 | const QStringList args = parser.positionalArguments(); | ||
114 | if (args.isEmpty()) { | 126 | if (args.isEmpty()) { | ||
115 | parser.showHelp(); | 127 | parser.showHelp(); | ||
116 | return 0; | 128 | return 0; | ||
117 | } | 129 | } | ||
118 | // input is args.at(0), output is args.at(1) | 130 | // input is args.at(0), output is args.at(1) | ||
119 | 131 | | |||
120 | QString inputFileName = args.at(0); | 132 | QString inputFileName = args.at(0); | ||
121 | bool debug = parser.isSet("debug"); | 133 | bool debug = parser.isSet("debug"); | ||
122 | bool mute = parser.isSet("mute"); | 134 | bool mute = parser.isSet("mute"); | ||
123 | unsigned int zoomLevel = parser.value("cut-to-tiles").toInt(); | 135 | unsigned int zoomLevel = parser.value("zoom-level").toInt(); | ||
124 | QString outputFileName = parser.value("output"); | 136 | qDebug()<<"Zoom level is "<<zoomLevel<<endl; | ||
137 | | ||||
138 | QString outputFileName; | ||||
139 | if(parser.isSet("output")){ | ||||
140 | outputFileName = parser.value("output"); | ||||
141 | } | ||||
142 | else{ | ||||
143 | outputFileName = "s_" + inputFileName; | ||||
144 | } | ||||
145 | qDebug()<<"Output file name is "<<outputFileName<<endl; | ||||
125 | 146 | | |||
126 | if(debug) { | 147 | if(debug) { | ||
127 | debugLevel = Debug; | 148 | debugLevel = Debug; | ||
128 | qInstallMessageHandler( debugOutput ); | 149 | qInstallMessageHandler( debugOutput ); | ||
129 | } | 150 | } | ||
130 | if(mute) { | 151 | if(mute) { | ||
131 | debugLevel = Mute; | 152 | debugLevel = Mute; | ||
132 | qInstallMessageHandler( debugOutput ); | 153 | qInstallMessageHandler( debugOutput ); | ||
Show All 40 Lines | 192 | if ( !writer.write( &outputFile, tile ) ) { | |||
173 | return 4; | 194 | return 4; | ||
174 | } | 195 | } | ||
175 | 196 | | |||
176 | qInfo() << tile->name() << " done"; | 197 | qInfo() << tile->name() << " done"; | ||
177 | 198 | | |||
178 | delete tile; | 199 | delete tile; | ||
179 | } | 200 | } | ||
180 | } | 201 | } | ||
181 | } else { | 202 | } else if(parser.isSet("node-reduce")) { | ||
182 | // future functionality | 203 | qDebug()<<"Entered Node reduce"<<endl; | ||
204 | qDebug()<<"Finished Processing"<<endl; | ||||
205 | if(!parser.isSet("zoom-level")){ | ||||
206 | qDebug()<<" Zoom level not set"<<endl; | ||||
207 | } | ||||
208 | else{ | ||||
209 | NodeReducer reducer(map, zoomLevel); | ||||
210 | reducer.process(); | ||||
211 | QFile outputFile(outputFileName); | ||||
212 | GeoWriter writer; | ||||
213 | writer.setDocumentType("0.6"); | ||||
214 | | ||||
215 | outputFile.open( QIODevice::WriteOnly ); | ||||
216 | if ( !writer.write( &outputFile, map ) ) { | ||||
217 | qDebug() << "Could not write the file " << outputFileName; | ||||
218 | return 4; | ||||
219 | } | ||||
220 | | ||||
221 | } | ||||
222 | | ||||
183 | } | 223 | } | ||
184 | 224 | | |||
185 | 225 | | |||
186 | return 0; | 226 | return 0; | ||
187 | } | 227 | } |