Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / scripts / maps / osm_ingest / src / bin / osm_extract.rs
osm_extract.rs58 lines · 2.1 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 | |
| 8 | use std::process::ExitCode; |
| 9 | |
| 10 | const USAGE: &str = |
| 11 | "Usage: osm_extract IN.osm.pbf --layer NAME --out FILE [--bbox BOX] [--threads N]"; |
| 12 | |
| 13 | fn 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!("Layers: {}", osm_ingest::extract::Layer::names().join(", ")); |
| 20 | return ExitCode::FAILURE; |
| 21 | } |
| 22 | }; |
| 23 | |
| 24 | if let Some(n) = args.threads { |
| 25 | osm_ingest::par::set_threads(n); |
| 26 | } |
| 27 | |
| 28 | let options = osm_ingest::extract::Options { layer: args.layer, bbox: args.bbox }; |
| 29 | let started = std::time::Instant::now(); |
| 30 | match osm_ingest::extract::build(&args.input, &args.out, &options) { |
| 31 | Ok(stats) => { |
| 32 | println!( |
| 33 | "{}: {} feature(s) ({} node, {} way, {} relation) in {:.1}s", |
| 34 | args.layer.name(), |
| 35 | stats.features, |
| 36 | stats.from_nodes, |
| 37 | stats.from_ways, |
| 38 | stats.from_relations, |
| 39 | started.elapsed().as_secs_f64() |
| 40 | ); |
| 41 | println!("Wrote {}", args.out.display()); |
| 42 | if stats.features == 0 { |
| 43 | // Not an error -- an extract really can hold no cameras -- but an |
| 44 | // empty layer is nearly always a wrong --bbox or a wrong PBF, and |
| 45 | // the tiler downstream only warns about it. |
| 46 | eprintln!("WARN: 0 features. Check --bbox and that the PBF covers the area."); |
| 47 | } |
| 48 | if let Some(why) = stats.missing_half(args.layer) { |
| 49 | eprintln!("WARN: {}: {why}", args.layer.name()); |
| 50 | } |
| 51 | ExitCode::SUCCESS |
| 52 | } |
| 53 | Err(e) => { |
| 54 | eprintln!("ERROR: {e}"); |
| 55 | ExitCode::FAILURE |
| 56 | } |
| 57 | } |
| 58 | } |