-
Notifications
You must be signed in to change notification settings - Fork 7
/
osm.flatdata
316 lines (287 loc) · 8.82 KB
/
osm.flatdata
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/// OSM data types and archive
namespace osm {
// Max 40 bits value used to indicate null references.
/**
* Special value which represents an invalid index.
*/
const u64 INVALID_IDX = 0xFFFFFFFFFF;
/**
* Metadata attached to the archive.
*/
struct Header {
/**
* All coordinates in this archive are scaled by this constant
* To get the original degree-based coordinate back compute (latitude/coord_scale,longitude/coord_scale)
*/
coord_scale: i32;
/// Bounding box (min longitude scaled with `header.coord_scale`)
bbox_left: i32 : 32;
/// Bounding box (max longitude scaled with `header.coord_scale`)
bbox_right: i32 : 32;
/// Bounding box (max latitude scaled with `header.coord_scale`)
bbox_top: i32 : 32;
/// Bounding box (min latitude scaled with `header.coord_scale`)
bbox_bottom: i32 : 32;
/// Writing program used to write the data (reference to `stringtable`).
writingprogram_idx: u64 : 40;
/// The origin (source) of the data.
source_idx: u64 : 40;
/**
* Replication timestamp, expressed in seconds since the epoch.
* See [`state.txt`].
*
* [`state.txt`]: https://wiki.openstreetmap.org/wiki/Planet.osm/diffs#Minute.2C_Hour.2C_and_Day_Files_Organisation
*/
replication_timestamp: i64 : 64;
/**
* Replication sequence number (`sequenceNumber` from [`state.txt`]).
*
* [`state.txt`]: https://wiki.openstreetmap.org/wiki/Planet.osm/diffs#Minute.2C_Hour.2C_and_Day_Files_Organisation
*/
replication_sequence_number: i64 : 64;
/**
* Replication base URL (reference to `stringtable`).
*/
replication_base_url_idx: u64 : 40;
}
/**
* A `(key, value)` attached to a `Node`, `Way`, or `Relation.
*/
struct Tag {
/// Key index in `stringtable`
key_idx: u64 : 40;
/// Value index in `stringtable`
value_idx: u64 : 40;
}
/**
* A node is one of the core elements in the OpenStreetMap data model.
*
* It consists of a single point in space defined by its latitude, longitude and node id.
*
* See <https://wiki.openstreetmap.org/wiki/Node>.
*/
struct Node {
/// Latitude (scaled with `header.coord_scale`).
lat: i32 : 32;
/// Longitude (scaled with `header.coord_scale`).
lon: i32 : 32;
/**
* Range of tags attached to this node.
*
* The values of the range are indexes in the `tags_index` vector.
*/
@range(tags)
tag_first_idx: u64 : 40;
}
/**
* Index of a node.
*/
struct NodeIndex {
/// Index in the `nodes` vector.
@optional(INVALID_IDX)
value: u64 : 40;
}
/**
* A way is an ordered list of nodes.
*
* See <https://wiki.openstreetmap.org/wiki/Way>.
*/
struct Way {
/**
* Range of tags attached to this node.
*
* The values of the range are indexes in the `tags_index` vector.
*/
@range(tags)
tag_first_idx: u64 : 40;
/**
* Range of nodes this way consists of.
*
* The values of the range are indexes in the `nodes_index` vector.
*/
@range(refs)
ref_first_idx: u64 : 40;
}
/**
* Index of a tag.
*/
struct TagIndex {
/// Index in the `tags` vector.
value: u64 : 40;
}
/// Node member of a relation.
struct NodeMember {
/// Index of the node in the `nodes` vector.
@optional(INVALID_IDX)
node_idx: u64 : 40;
/**
* Optional textual field describing the function of the node in the relation.
*
* Index in `stringtable`.
*/
role_idx: u64 : 40;
}
/// Way member of a relation.
struct WayMember {
/// Index of the way in the `ways` vector.
@optional(INVALID_IDX)
way_idx: u64 : 40;
/**
* Optional textual field describing the function of the way in the relation.
*
* Index in `stringtable`.
*/
role_idx: u64 : 40;
}
/// Relation member of a relation.
struct RelationMember {
/// Index of the relation in the `relations` vector.
@optional(INVALID_IDX)
relation_idx: u64 : 40;
/**
* Optional textual field describing the function of the relation in the parent relation.
*
* Index in `stringtable`.
*/
role_idx: u64 : 40;
}
/**
* A relation is an ordered list of one or more nodes, ways and/or relations as members.
*
* See <https://wiki.openstreetmap.org/wiki/Relation>.
*/
struct Relation {
/**
* Range of tags attached to this relation.
*
* The values of the range are indexes in the `tags` vector.
*/
@range(tags)
tag_first_idx: u64 : 40;
}
struct Id {
value: u64 : 40;
}
/**
* An optional sub-archive storing the original OSM ids of nodes, ways, and relations
*/
archive Ids {
/**
* List of OSM ids of all nodes in the parent archive
* nodes[i] has its id stored in ids.nodes[i]
*/
nodes: vector< Id >;
/**
* List of OSM ids of all ways in the parent archive
* ways[i] has its id stored in ids.ways[i]
*/
ways: vector< Id >;
/**
* List of OSM ids of all relations in the parent archive
* relations[i] has its id stored in ids.relations[i]
*/
relations: vector< Id >;
}
/**
* OSM data archive
*
* Relations and relation members are indexed with the same index, i.e.
* a relation at index `i` in the vector `relations` has the members
* at index `i` in the multivector `relation_members`.
*
* All 1:n relationships are modeled in-place by using an additional index. This is a
* common pattern in flatdata. For example, a node might have multiple tags attached
* to it. To model this, a node in `nodes` references the first tag attached to it
* by storing an index in the `tags_index` vector. The next node in `nodes` again
* references its first tag, which is the last tag (exclusive) of the previous node.
*
* ```text
* nodes: [ ..., n_1, n_2, ... ]
* | |
* | +-------+
* v v
* tags_index: [ ..., t_11, t_12, ..., t_1n, t_21, ... t_2m, ... ]
* ```
*/
@bound_implicitly(Relations: relations, relation_members)
archive Osm {
/**
* Header which contains the metadata attached to the archive.
*/
@explicit_reference( Header.writingprogram_idx, stringtable )
@explicit_reference( Header.source_idx, stringtable )
@explicit_reference( Header.replication_base_url_idx, stringtable )
header: Header;
/**
* List of nodes.
*
* A node references a range of tags in the `tags_index` vector.
*/
@explicit_reference( Node.tag_first_idx, tags_index )
nodes: vector<Node>;
/**
* List of ways.
*
* A way references
*
* * a range of tags in the `tags_index` vector, and
* * a range of nodes in the `nodes_index` vector.
*/
@explicit_reference( Way.tag_first_idx, tags_index )
@explicit_reference( Way.ref_first_idx, nodes_index )
ways: vector<Way>;
/**
* List of relations.
*
* A relation references a range of tags in `tags_index` vectors.
* Members are attached to a relation implicitly: members that belong to a
* relation at index `i` are at index `i` in the `relation_members` multivector.
*/
@explicit_reference( Relation.tag_first_idx, tags_index )
relations: vector<Relation>;
/**
* Members attached to relations.
*
* An index in this multivector corresponds to an index in the `relations` vector.
*
* A member has a variadic type: `NodeMember`, `WayMember` or `RelationMember`.
* Each type references its role in the `stringtable` raw data. Additionally,
*
* * a node member references a node in the `nodes` vector,
* * a way member references a way in the `ways` vector,
* * a relation member references a relation in the `relations` vector.
*/
@explicit_reference( NodeMember.node_idx, nodes )
@explicit_reference( NodeMember.role_idx, stringtable )
@explicit_reference( WayMember.way_idx, ways )
@explicit_reference( WayMember.role_idx, stringtable )
@explicit_reference( RelationMember.relation_idx, relations )
@explicit_reference( RelationMember.role_idx, stringtable )
relation_members: multivector<40, NodeMember, WayMember, RelationMember>;
/**
* List of tags.
*
* A tag references its key and value in the `stringtable` raw data.
*/
@explicit_reference( Tag.key_idx, stringtable )
@explicit_reference( Tag.value_idx, stringtable )
tags: vector<Tag>;
/**
* Auxiliary index of tags to model 1:n relationships between nodes, ways, relations
* and tags.
*/
@explicit_reference( TagIndex.value, tags )
tags_index: vector<TagIndex>;
/**
* Auxiliary index of nodes to model 1:n relationship between ways and nodes.
*/
@explicit_reference( NodeIndex.value, nodes )
nodes_index: vector<NodeIndex>;
/**
* List of strings separated by `\0`.
*/
stringtable: raw_data;
@optional
ids: archive Ids;
}
} // namespace osm