KOSMIndoorMap

marble-geometry-assembler.cpp
1/*
2 SPDX-FileCopyrightText: 2023 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#include <../src/map/loader/marblegeometryassembler_p.h>
7
8#include <osm/datasetmergebuffer.h>
9#include <osm/datatypes.h>
10#include <osm/io.h>
11
12#include <QCommandLineParser>
13#include <QCoreApplication>
14#include <QDebug>
15#include <QFile>
16#include <QtPlugin>
17
18#if HAVE_OSM_PBF_SUPPORT
19Q_IMPORT_PLUGIN(OSM_PbfIOPlugin)
20#endif
21
22int main(int argc, char **argv)
23{
24 QCoreApplication app(argc, argv);
25 QCommandLineParser parser;
26 parser.addHelpOption();
27 QCommandLineOption outOpt({QStringLiteral("o"), QStringLiteral("output")}, QStringLiteral("output file"), QStringLiteral("file"));
28 parser.addOption(outOpt);
29 parser.process(app);
30
31 const auto fileNames = parser.positionalArguments();
32 if (fileNames.isEmpty()) {
33 parser.showHelp(1);
34 }
35
36 OSM::DataSet dataSet;
37 OSM::DataSetMergeBuffer mergeBuffer;
38 KOSMIndoorMap::MarbleGeometryAssembler marbleMerger;
39 marbleMerger.setDataSet(&dataSet);
40 auto reader = OSM::IO::readerForMimeType(u"application/vnd.openstreetmap.data+o5m", &dataSet);
41 reader->setMergeBuffer(&mergeBuffer);
42
43 for (const auto &fileName : fileNames) {
44 QFile f(fileName);
45 if (!f.open(QFile::ReadOnly)) {
46 qCritical() << f.fileName() << f.errorString();
47 return 1;
48 }
49 const auto data = f.map(0, f.size());
50 reader->read(data, f.size());
51 marbleMerger.merge(&mergeBuffer);
52 }
53
54 marbleMerger.finalize();
55
56 QFile outputFile;
57 std::unique_ptr<OSM::AbstractWriter> writer;
58 if (parser.isSet(outOpt)) {
59 outputFile.setFileName(parser.value(outOpt));
60 outputFile.open(QFile::WriteOnly);
61 writer = OSM::IO::writerForFileName(outputFile.fileName());
62 } else {
63 outputFile.open(stdout, QFile::WriteOnly);
64 writer = OSM::IO::writerForMimeType(u"application/vnd.openstreetmap.data+xml");
65 }
66 if (!outputFile.isOpen()) {
67 qCritical() << outputFile.errorString();
68 return 1;
69 }
70
71 if (!writer) {
72 qCritical() << "no file writer for requested format:" << outputFile.fileName();
73 return 1;
74 }
75 writer->write(dataSet, &outputFile);
76 return 0;
77}
Holds OSM elements produced by a parser prior to merging into OSM::DataSet.
A set of nodes, ways and relations.
Definition datatypes.h:346
KOSM_EXPORT std::unique_ptr< AbstractReader > readerForMimeType(QStringView mimeType, OSM::DataSet *dataSet)
Returns a suitable reader for the given MIME type.
Definition io.cpp:51
KOSM_EXPORT std::unique_ptr< AbstractWriter > writerForMimeType(QStringView mimeType)
Returns a suitable writer for the given MIME type.
Definition io.cpp:69
KOSM_EXPORT std::unique_ptr< AbstractWriter > writerForFileName(QStringView fileName)
Returns a suitable writer for the given file name.
Definition io.cpp:60
KEDUVOCDOCUMENT_EXPORT QStringList fileNames(const QString &language=QString())
QCommandLineOption addHelpOption()
bool addOption(const QCommandLineOption &option)
bool isSet(const QCommandLineOption &option) const const
QStringList positionalArguments() const const
void process(const QCoreApplication &app)
void showHelp(int exitCode)
QString value(const QCommandLineOption &option) const const
virtual QString fileName() const const override
bool open(FILE *fh, OpenMode mode, FileHandleFlags handleFlags)
void setFileName(const QString &name)
QString errorString() const const
bool isOpen() const const
qint64 write(const QByteArray &data)
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:55:43 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.