Repository navigation
Expand file tree
/
Copy pathdump.cpp
More file actions
92 lines (83 loc) · 2.56 KB
/
Copy pathdump.cpp
File metadata and controls
92 lines (83 loc) · 2.56 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
#include <fstream>
#include <iostream>
#include "pgmap.h"
#include "util.h"
#include "osmfile.h"
#include "cppGzip/EncodeGzip.h"
#include "cppo5m/osmxml.h"
#include <boost/program_options.hpp>
namespace po = boost::program_options;
int main(int argc, char **argv)
{
auto started = std::chrono::steady_clock::now();
po::options_description desc("Dump the whole map");
desc.add_options()
("help", "produce help message")
("out", po::value<string>()->default_value("dump.o5m.gz"), (string("Output file name, ending in ") + OsmFileWriter::SupportedNames()).c_str())
("no-update-info", "Leave out of the file header what keeping it up to date needs: the edit IDs it is current to, "
"its area and the server to update from (public_url in config.cfg).")
("edit-ids", "Kept for scripts that give it: the edit IDs are written unless --no-update-info is given")
;
po::variables_map vm;
try
{
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
}
catch(const exception &error)
{
cerr << error.what() << endl;
return 2;
}
if (vm.count("help")) {
cout << desc << "\n";
return 1;
}
string outFina = vm["out"].as<string>();
try
{
OsmFileWriter::FormatOf(outFina); // An unusable name is refused before any work
}
catch(const invalid_argument &error)
{
cerr << error.what() << endl;
return 2;
}
bool updateInfo = !vm.count("no-update-info");
cout << "Reading settings from config.cfg" << endl;
std::map<string, string> config;
ReadSettingsFile("config.cfg", config);
string cstr = GeneratePgConnectionString(config);
class PgMap pgMap(cstr, config["dbtableprefix"], config["dbtablemodifyprefix"], config["dbtablemodifyprefix"], config["dbtabletestprefix"]);
if (pgMap.Ready()) {
cout << "Opened database successfully" << endl;
} else {
cout << "Can't open database" << endl;
return 1;
}
bool order = true;
try
{
std::shared_ptr<class PgTransaction> transaction = pgMap.GetTransaction("ACCESS SHARE");
// The edit IDs come from the same snapshot as the dump below.
TagMap rootAttribs;
if(updateInfo)
{
rootAttribs = transaction->GetLatestEditIdAttribs();
if(!config["public_url"].empty())
rootAttribs["update_url"] = config["public_url"];
}
OsmFileWriter writer(outFina, rootAttribs);
if(order)
writer.SetSortedTypeThenId();
transaction->Dump(order, true, true, true, writer.Encoder());
writer.Close();
}
catch(const exception &error)
{
cerr << "Dump failed after " << Took(started) << ": " << error.what() << endl;
return 1;
}
cout << "All done, in " << Took(started) << "." << endl;
return 0;
}