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

Modern-Apps.git / scripts / maps / osm_ingest / src / bin / poi_extract.rs

poi_extract.rs98 lines · 3.5 KiBRaw
1//! `poi_extract IN.osm.pbf --geojson FILE --names FILE --index FILE [--attrs FILE] [--reviews FILE]`
2//!
3//! Replaces `scripts/maps/poi_extract.cpp`. See `osm_ingest::poi_build` for the
4//! POI type map and the on-disk record layout.
5
6use std::process::ExitCode;
7
8const USAGE: &str = "Usage: poi_extract IN.osm.pbf --geojson FILE --names FILE \
9 --index FILE [--attrs FILE] [--reviews FILE] [--region california|world] [--threads N]";
10
11fn main() -> ExitCode {
12 let argv: Vec<String> = std::env::args().skip(1).collect();
13 let args = match osm_ingest::poi_build::parse_args(&argv) {
14 Ok(v) => v,
15 Err(e) => {
16 eprintln!("ERROR: {e}\n{USAGE}");
17 return ExitCode::FAILURE;
18 }
19 };
20
21 if let Some(n) = args.threads {
22 osm_ingest::par::set_threads(n);
23 }
24
25 // The review table is parsed on its own thread while the PBF passes run;
26 // `build_with_review_loader` joins it right before the reviews are applied.
27 let loader = args.reviews.clone().map(|path| {
28 std::thread::spawn(move || {
29 let t = std::time::Instant::now();
30 let table = osm_ingest::poi_reviews::ReviewTable::load(&path);
31 eprintln!("[poi] review table loaded in {:.3}s", t.elapsed().as_secs_f64());
32 table
33 })
34 });
35 let have_reviews = loader.is_some();
36 let on_loaded = |table: &osm_ingest::poi_reviews::ReviewTable| {
37 println!("Loaded {} review row(s)", table.len());
38 };
39
40 let paths = osm_ingest::poi_build::Paths {
41 input: &args.input,
42 geojson: &args.geojson,
43 names: &args.names,
44 index: &args.index,
45 attrs: &args.attrs,
46 spatial: &args.spatial,
47 name_index: &args.name_index,
48 region: &args.region,
49 };
50 let result = match loader {
51 Some(loader) => {
52 osm_ingest::poi_build::build_with_review_loader(paths, args.bbox, loader, &on_loaded)
53 }
54 None => osm_ingest::poi_build::build_with_reviews(paths, args.bbox, None),
55 };
56 match result {
57 Ok(stats) => {
58 println!(
59 "{} POI(s) ({} node, {} closed-way, {} relation), {} unique name(s) \
60 ({} bytes)",
61 stats.records,
62 stats.from_nodes,
63 stats.from_ways,
64 stats.from_relations,
65 stats.unique_names,
66 stats.name_bytes,
67 );
68 println!(
69 "{} POI(s) with attributes, {} unique record(s), {} sidecar byte(s)",
70 stats.with_attrs, stats.unique_attrs, stats.attr_bytes
71 );
72 if have_reviews {
73 println!("{} POI(s) with review data", stats.with_reviews);
74 }
75 println!(
76 "{} populated grid cell(s), {} name index entr(ies)",
77 stats.spatial_cells, stats.name_entries
78 );
79 println!("{} POI(s) with a boundary link", stats.with_region);
80 println!(
81 "Wrote {}, {}, {}, {}, {}, {}, {}, {}",
82 args.geojson.display(),
83 args.names.display(),
84 args.index.display(),
85 args.attrs.display(),
86 args.spatial.display(),
87 args.name_index.display(),
88 args.region.display(),
89 args.region.with_file_name("poi_admin.bin").display()
90 );
91 ExitCode::SUCCESS
92 }
93 Err(e) => {
94 eprintln!("ERROR: {e}");
95 ExitCode::FAILURE
96 }
97 }
98}