Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
dependencies ▾

Modern-Apps.git / scripts / maps / osm_ingest / src / graph_build_part1.rs

graph_build_part1.rs111 lines · 4.8 KiBRaw
1/// The ways-only pass: one [`Seg`] per consecutive resolvable ref pair.
2///
3/// Re-reading the way blobs replaces a cache of every routable way and every one
4/// of its refs — 32 GB at planet scale — with the cost of inflating the way
5/// blobs a second time. Ways are a small minority of a planet file's blobs and
6/// `blob_kinds` lets the pass skip the rest outright, so the trade is heavily in
7/// favour of re-reading.
8/// One Morton-key piece: its slot range plus its disjoint slice of the key array.
9type KeyPiece<'a> = ((usize, usize), &'a mut [(u64, u32)]);
10
11#[derive(Default)]
12struct WayPass {
13 segs: Vec<Seg>,
14 lanes: Vec<u16>,
15 names: LocalNames,
16}
17
18#[derive(Default)]
19struct Pass2 {
20 /// `(dense id, lat_e7, lon_e7)`, scattered index-aligned in the sink.
21 locs: Vec<(u32, i32, i32)>,
22 /// `(dense id, stop code)`, as owned bytes. Interning is deferred until every
23 /// way name is in the pool, because a name's offset is its position in the
24 /// pool: interning a stop code early would shift every way name after it and
25 /// rewrite the whole of `road_names.bin`.
26 stops: Vec<(u32, Vec<u8>)>,
27 /// Slots this chunk claimed (first sight of the id) in the parallel scan.
28 claimed: u64,
29}
30
31#[derive(Clone, Copy)]
32struct TmpEdge {
33 source: u32,
34 target: u32,
35 dist_mm: u32,
36 name_offset: u32,
37 type_: u8,
38 speed_limit: u8,
39 lane_off: u32,
40 lane_count: u16,
41 /// Chain this edge traverses, or [`NO_CHAIN`]. Only used to make the write
42 /// order total; the geometry comes from the point range below.
43 chain: u32,
44 /// True when it runs from the chain's last point to its first, so the stored
45 /// polyline has to be read backwards.
46 chain_rev: bool,
47 /// The chain's polyline in `chains.pts`. Carried here rather than looked up per
48 /// edge: the header file is 24 GB at planet scale, so seeking back into it once
49 /// per edge would be a billion cold random reads.
50 pts_start: u64,
51 pts_len: u32,
52}
53
54/// Build-time choices that change the shape of the build rather than its output
55/// contract.
56#[derive(Clone, Default)]
57pub struct Options {
58 /// Restrict chains to a single OSM way, which trades some collapsing for the
59 /// segment array and its incidence index. See [`crate::chains`].
60 pub within_way_chains: bool,
61 /// How many source-partitioned rounds to write the pack in. One round is the
62 /// whole graph at once; more rounds trade extra sequential passes over the
63 /// chain spill for a proportionally smaller edge buffer. Zero means one.
64 pub rounds: u32,
65 /// Where to put the chain spill. Defaults to the output directory.
66 ///
67 /// Worth separating because `chains.pts` is the only file the build reads
68 /// randomly — once per edge that stores a polyline — so it wants a disk whose
69 /// seeks are cheap, while the output only ever needs sequential writes and can
70 /// go wherever there is room. Putting the spill on a slow mount cost more wall
71 /// clock on California than every other stage put together.
72 pub spill_dir: Option<PathBuf>,
73 /// Where to put `chains.pts` specifically, if it should not sit beside
74 /// `chains.hdr`.
75 ///
76 /// The header is the larger file — about 24 GB against 18 GB at planet scale —
77 /// but it is only ever streamed from the front, so it can live somewhere roomy
78 /// and slow while the randomly-read points go somewhere fast and small.
79 pub spill_pts_dir: Option<PathBuf>,
80 /// Print the [`Census`] report after the build. Changes no output file.
81 pub stats: bool,
82 /// Cap on the parallel pool. `None` leaves it to [`crate::par::threads`].
83 pub threads: Option<usize>,
84 /// A `.mdem` heightmap dataset (`dem_ingest`) to bake a per-node elevation from.
85 ///
86 /// `None` omits `elevation.bin` entirely — the graph is still valid and the device reads every
87 /// node's elevation as 0 (WS-G's route profile simply comes out flat). When set, every graph
88 /// node is sampled from the DEM and its metres written to `elevation.bin`; a node off the DEM's
89 /// coverage bakes as 0.
90 pub dem: Option<PathBuf>,
91 /// Region bbox filter: keep only ways with at least one node inside.
92 ///
93 /// `None` (world) keeps everything. `Some` (california) drops every routable
94 /// way whose nodes all fall outside — the graph then covers only the region,
95 /// which is what makes a california build fast and small. Stop nodes are
96 /// filtered the same way: a stop outside the region never enters the graph.
97 pub bbox: Option<crate::bbox::BBox>,
98}
99
100impl Options {
101 fn round_count(&self) -> u32 {
102 self.rounds.max(1)
103 }
104}
105
106pub fn build(input: &Path, out_dir: &Path) -> Result<Stats> {
107 build_with(input, out_dir, Options::default())
108}
109
110include!("graph_build_part1_s1.rs");
111include!("graph_build_part1_s2.rs");