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

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

osm_extract.rs66 lines · 2.2 KiBRaw
1//! `osm_extract IN.osm.pbf --layer NAME --out FILE [--bbox BOX]`
2//!
3//! One 3-pass driver for the baked vector layers, replacing the
4//! `osmium tags-filter | osmium export | normalize_*.py` chain for each of them.
5//! See `osm_ingest::extract` for the pass ordering and each layer's own module
6//! for its schema.
7
8use std::process::ExitCode;
9
10const USAGE: &str =
11 "Usage: osm_extract IN.osm.pbf --layer NAME --out FILE [--bbox BOX] [--threads N]";
12
13fn main() -> ExitCode {
14 let argv: Vec<String> = std::env::args().skip(1).collect();
15 let args = match osm_ingest::extract::parse_args(&argv) {
16 Ok(v) => v,
17 Err(e) => {
18 eprintln!("ERROR: {e}\n{USAGE}");
19 eprintln!(
20 "Layers: {}",
21 osm_ingest::extract::Layer::names().join(", ")
22 );
23 return ExitCode::FAILURE;
24 }
25 };
26
27 if let Some(n) = args.threads {
28 osm_ingest::par::set_threads(n);
29 }
30
31 let options = osm_ingest::extract::Options {
32 layer: args.layer,
33 bbox: args.bbox,
34 };
35 let started = std::time::Instant::now();
36 match osm_ingest::extract::build(&args.input, &args.out, &options) {
37 Ok(stats) => {
38 println!(
39 "{}: {} feature(s) ({} node, {} way, {} relation) in {:.1}s",
40 args.layer.name(),
41 stats.features,
42 stats.from_nodes,
43 stats.from_ways,
44 stats.from_relations,
45 started.elapsed().as_secs_f64()
46 );
47 println!("Wrote {}", args.out.display());
48 if stats.features == 0 {
49 // Not an error -- an extract really can hold no cameras -- but an
50 // empty layer is nearly always a wrong --bbox or a wrong PBF, and
51 // the tiler downstream only warns about it.
52 eprintln!(
53 "WARN: 0 features. Check --bbox and that the PBF covers the area."
54 );
55 }
56 if let Some(why) = stats.missing_half(args.layer) {
57 eprintln!("WARN: {}: {why}", args.layer.name());
58 }
59 ExitCode::SUCCESS
60 }
61 Err(e) => {
62 eprintln!("ERROR: {e}");
63 ExitCode::FAILURE
64 }
65 }
66}