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

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

poi_extract.rs86 lines · 2.7 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 let reviews = match args.reviews.as_deref().map(osm_ingest::poi_reviews::ReviewTable::load) {
26 Some(Ok(table)) => {
27 println!("Loaded {} review row(s)", table.len());
28 Some(table)
29 }
30 Some(Err(e)) => {
31 eprintln!("ERROR: {e}");
32 return ExitCode::FAILURE;
33 }
34 None => None,
35 };
36
37 match osm_ingest::poi_build::build_with_reviews(
38 &args.input,
39 &args.geojson,
40 &args.names,
41 &args.index,
42 &args.attrs,
43 &args.spatial,
44 &args.name_index,
45 args.bbox,
46 reviews.as_ref(),
47 ) {
48 Ok(stats) => {
49 println!(
50 "{} POI(s) ({} node, {} closed-way, {} relation), {} unique name(s) \
51 ({} bytes)",
52 stats.records,
53 stats.from_nodes,
54 stats.from_ways,
55 stats.from_relations,
56 stats.unique_names,
57 stats.name_bytes,
58 );
59 println!(
60 "{} POI(s) with attributes, {} unique record(s), {} sidecar byte(s)",
61 stats.with_attrs, stats.unique_attrs, stats.attr_bytes
62 );
63 if reviews.is_some() {
64 println!("{} POI(s) with review data", stats.with_reviews);
65 }
66 println!(
67 "{} populated grid cell(s), {} name index entr(ies)",
68 stats.spatial_cells, stats.name_entries
69 );
70 println!(
71 "Wrote {}, {}, {}, {}, {}, {}",
72 args.geojson.display(),
73 args.names.display(),
74 args.index.display(),
75 args.attrs.display(),
76 args.spatial.display(),
77 args.name_index.display()
78 );
79 ExitCode::SUCCESS
80 }
81 Err(e) => {
82 eprintln!("ERROR: {e}");
83 ExitCode::FAILURE
84 }
85 }
86}