-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenumber.cpp
120 lines (102 loc) · 3.37 KB
/
renumber.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
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
116
117
118
119
120
#define IGNORE_STRINGNODES
#include "helpers/Sequence.hpp"
#include "common/GeoTypes.hpp"
#include "Coordinates.hpp"
#include "helpers/FileIndex.hpp"
#define BALISENAME_RELATION "relation"
#define BALISENAME_NODE "node"
#define BALISENAME_WAY "way"
#define BALISENAME_TAG "tag"
using namespace fidx;
class XmlVisitor
{
private:
XmlVisitor(const XmlVisitor&);
XmlVisitor& operator=(const XmlVisitor&);
public:
uint64_t relid;
uint64_t wayid;
uint64_t nodid;
uint64_t tags;
FileIndex<uint64_t, uint64_t> *relationIdIndex;
FileIndex<uint64_t, uint64_t> *wayIdIndex;
FileIndex<GeoPoint, uint64_t> *nodeIdIndex;
KeyIndex<uint64_t> *nodeRefIndex;
explicit XmlVisitor(const std::string& rep)
{
relid = 0;
wayid = 0;
nodid = 0;
tags = 0;
relationIdIndex = new FileIndex<uint64_t,uint64_t>((rep + "/relationIdIndex") .c_str(), true);
wayIdIndex = new FileIndex<uint64_t,uint64_t>((rep +"/wayIdIndex").c_str(), true);
nodeIdIndex = new FileIndex<GeoPoint, uint64_t>((rep + "/nodeIdIndex").c_str(), true);
nodeRefIndex = new KeyIndex<uint64_t>((rep + "/nodeRefIndex").c_str(), true);
}
~XmlVisitor()
{
relationIdIndex->flush();
wayIdIndex->flush();
nodeIdIndex->flush();
if(!relationIdIndex->isSorted()) relationIdIndex->sort();
if(!wayIdIndex->isSorted()) wayIdIndex->sort();
if(!nodeIdIndex->isSorted()) nodeIdIndex->sort();
if(!nodeRefIndex->isSorted()) nodeRefIndex->sort();
delete relationIdIndex;
delete wayIdIndex;
delete nodeIdIndex;
}
void log(uint64_t done)
{
std::cerr << " done " << (done >> UINT64_C(20)) << "Mio.\t relations " << relid << "\tways " << wayid << "\tnodes " << nodid<< "\n" << std::flush;
}
void startTag([[maybe_unused]] const std::vector<SeqBalise*>& tagStack, [[maybe_unused]] SeqBalise* b)
{
}
void stringNode([[maybe_unused]] const std::vector<SeqBalise*>& tagStack, [[maybe_unused]] std::string& s)
{
}
void endTag([[maybe_unused]] const std::vector<SeqBalise*>& tagStack, SeqBalise* b)
{
if (b->baliseName == BALISENAME_RELATION)
{
relationIdIndex->append(atoll((b->keyValues["id"]).c_str()), relid++);
tags=0;
}
else if (b->baliseName == BALISENAME_WAY)
{
wayIdIndex->append(atoll((b->keyValues["id"]).c_str()), wayid++);
tags=0;
}
else if (b->baliseName == BALISENAME_TAG)
{
tags++;;
}
else if (b->baliseName == BALISENAME_NODE)
{
GeoPoint pt{ Coordinates::toNormalizedLon(b->keyValues["lon"]), Coordinates::toNormalizedLat(b->keyValues["lat"])};
uint64_t ref = atoll((b->keyValues["id"]).c_str());
if(tags)
{
nodid++;
nodeIdIndex->append(ref,pt);
nodeRefIndex->append(ref);
} else {
nodeIdIndex->append(ref,pt);
}
tags = 0;
}
}
};
int main(int argc, char *argv[])
{
if(argc != 2)
{
std::cerr << "path argument is missing\n";
exit(1);
}
XmlVisitor* v = new XmlVisitor(std::string(argv[1]));
XmlFileParser<XmlVisitor>::parseXmlFile(stdin,*v);
delete v;
return 0;
}