-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathosm2rdf.cpp
More file actions
115 lines (103 loc) · 4.1 KB
/
osm2rdf.cpp
File metadata and controls
115 lines (103 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright 2020, University of Freiburg
// Authors: Axel Lehmann <[email protected]>.
// This file is part of osm2rdf.
//
// osm2rdf is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// osm2rdf is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with osm2rdf. If not, see <https://www.gnu.org/licenses/>.
#include <cstdlib>
#include <filesystem>
#include <iostream>
#include <string>
#include "osm2rdf/Version.h"
#include "osm2rdf/config/Config.h"
#include "osm2rdf/config/ExitCode.h"
#include "osm2rdf/osm/OsmiumHandler.h"
#include "osm2rdf/ttl/Writer.h"
#include "osm2rdf/util/Ram.h"
#include "osm2rdf/util/Time.h"
#if defined(_OPENMP)
#include "omp.h"
#endif
// ____________________________________________________________________________
template <typename T>
void run(const osm2rdf::config::Config& config) {
// Setup
// Input file reference
osm2rdf::util::Output output{config, config.output};
if (!output.open()) {
std::cerr << "Error opening outputfile: " << config.output << std::endl;
exit(1);
}
osm2rdf::ttl::Writer<T> writer{config, &output};
writer.writeHeader();
writer.writeTriple(
writer.generateIRIUnsafe(osm2rdf::ttl::constants::NAMESPACE__OSM2RDF,
"replace-with-dataset-specific-id"),
writer.generateIRIUnsafe(osm2rdf::ttl::constants::NAMESPACE__OSM2RDF,
"git-info"),
writer.generateLiteral(osm2rdf::version::GIT_INFO, ""));
osm2rdf::osm::OsmiumHandler osmiumHandler{config, &writer};
osmiumHandler.handle();
// All work done, close output
output.close();
// Write final RDF statistics if requested
if (config.writeRDFStatistics) {
writer.writeStatisticJson(config.rdfStatisticsPath);
}
}
// ____________________________________________________________________________
int main(int argc, char** argv) {
std::cerr << osm2rdf::util::currentTimeFormatted()
<< "osm2rdf :: " << osm2rdf::version::GIT_INFO << " :: BEGIN"
<< std::endl;
osm2rdf::config::Config config;
config.fromArgs(argc, argv);
std::cerr << config.getInfo(osm2rdf::util::formattedTimeSpacer) << std::endl;
std::cerr << osm2rdf::util::currentTimeFormatted() << "Free ram: "
<< osm2rdf::util::ram::available() /
(osm2rdf::util::ram::GIGA * 1.0)
<< "G/"
<< osm2rdf::util::ram::physPages() /
(osm2rdf::util::ram::GIGA * 1.0)
<< "G" << std::endl;
#if defined(_OPENMP)
omp_set_num_threads(config.numThreads);
#endif
try {
if (config.outputFormat == "qlever") {
run<osm2rdf::ttl::format::QLEVER>(config);
} else if (config.outputFormat == "nt") {
run<osm2rdf::ttl::format::NT>(config);
} else if (config.outputFormat == "ttl") {
run<osm2rdf::ttl::format::TTL>(config);
} else {
std::cerr << osm2rdf::util::currentTimeFormatted()
<< "osm2rdf :: " << osm2rdf::version::GIT_INFO << " :: ERROR"
<< std::endl;
std::cerr << "Unknown output format: " << config.outputFormat
<< std::endl;
std::exit(osm2rdf::config::ExitCode::FAILURE);
}
} catch (const std::exception& e) {
// All exceptions used by the Osmium library derive from std::exception.
std::cerr << osm2rdf::util::currentTimeFormatted()
<< "osm2rdf :: " << osm2rdf::version::GIT_INFO << " :: ERROR"
<< std::endl;
std::cerr << e.what() << std::endl;
std::exit(osm2rdf::config::ExitCode::EXCEPTION);
}
std::cerr << osm2rdf::util::currentTimeFormatted()
<< "osm2rdf :: " << osm2rdf::version::GIT_INFO << " :: FINISHED"
<< std::endl;
std::exit(osm2rdf::config::ExitCode::SUCCESS);
}