-
Notifications
You must be signed in to change notification settings - Fork 9
/
comm2osm.cpp
82 lines (66 loc) · 2.34 KB
/
comm2osm.cpp
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
/*
Convert Shapefiles into OSM files.
*/
#include <getopt.h>
#include <iostream>
#include <vector>
#include <gdal/ogrsf_frmts.h>
#include "plugins/base_plugin.hpp"
#include "plugins/navteq/navteq_plugin.hpp"
#include "plugins/dummy/dummy_plugin.hpp"
boost::filesystem::path input_path, output_file;
void print_help() {
std::cout << "comm2osm [OPTIONS] [INFILE [OUTFILE]]\n\n"
<< "If INFILE or OUTFILE is not given stdin/stdout is assumed.\n"
<< "File format is autodetected from file name suffix.\n"
// << "Use -t option to force file format.\n"
<< "\nFile format:\n" << " (default) XML encoding\n"
<< " pbf binary PBF encoding\n"
<< " opl OPL encoding\n" << "\nFile compression\n"
<< " gz compressed with gzip\n"
<< " bz2 compressed with bzip2\n"
<< "\nOptions:\n"
<< " -h, --help This help message\n"
<< " -t, --to-format=FORMAT Output format\n";
}
void check_args_and_setup(int argc, char* argv[]) {
// options
static struct option long_options[] = { { "help", no_argument, 0, 'h' }, { 0, 0 } };
while (true) {
int c = getopt_long(argc, argv, "dhf:t:", long_options, 0);
if (c == -1) {
break;
}
switch (c) {
case 'h':
print_help();
exit(0);
default:
exit(1);
}
}
int remaining_args = argc - optind;
if (remaining_args < 2) {
std::cerr << "Usage: " << argv[0] << " [OPTIONS] [INFILE [OUTFILE]]" << std::endl;
exit(1);
} else if (remaining_args == 2) {
input_path = boost::filesystem::path(argv[optind]);
output_file = boost::filesystem::path(argv[optind + 1]);
} else if (remaining_args == 1) {
input_path = boost::filesystem::path(argv[optind]);
}
}
int main(int argc, char* argv[]) {
check_args_and_setup(argc, argv);
std::vector<base_plugin*> plugins;
boost::filesystem::path executable_path(argv[0]);
plugins.push_back(new dummy_plugin());
plugins.push_back(new navteq_plugin(executable_path));
for (auto plugin : plugins) {
if (plugin->check_input(input_path, output_file)) {
std::cout << "executing plugin " << plugin->get_name() << std::endl;
plugin->execute();
}
delete plugin;
}
}