1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
//! CLI configuration via clap.
// The clap help text is golden-tested and names placeholders such as <output>.
#![allow(rustdoc::invalid_html_tags)]
use clap::{CommandFactory, Parser};
use geolith_tiles_builder::TilesConfig;
use std::path::{Path, PathBuf};
/// A path flag that only some output formats read.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PathFlag {
/// `--data`.
Data,
/// `--natural-earth`.
NaturalEarth,
/// `--water-polygons`.
WaterPolygons,
/// `--land-polygons`.
LandPolygons,
/// `--output`.
Output,
}
impl PathFlag {
/// The flag as the usage line names it.
#[must_use]
pub const fn usage(self) -> &'static str {
match self {
Self::Data => "--data <DATA>",
Self::NaturalEarth => "--natural-earth <NATURAL_EARTH>",
Self::WaterPolygons => "--water-polygons <WATER_POLYGONS>",
Self::LandPolygons => "--land-polygons <LAND_POLYGONS>",
Self::Output => "--output <OUTPUT>",
}
}
}
pub use geolith_search_builder::PgIndexFlavor;
/// Switches that reuse work an earlier run already did, flattened into
/// [`Config`] so the flags stay `--node-cache` and `--resume`.
#[derive(Debug, Parser)]
pub struct RunReuse {
/// Enable node store caching between runs.
///
/// When enabled (default), a sidecar `.meta.json` file is written
/// alongside the node store. On re-runs with the same PBF file,
/// the node collection pass is skipped entirely — reducing from
/// 2 PBF reads to 1.
#[arg(long, default_value = "true")]
pub node_cache: bool,
/// Resume from existing sort chunks in --tmpdir, skipping Phase 1.
///
/// When set, the pipeline discovers chunk files from the temporary
/// directory and proceeds directly to merge + encode + write.
/// Requires --tmpdir to point at a directory with sort chunks from
/// a previous (interrupted) run.
#[arg(long, default_value = "false")]
pub resume: bool,
}
/// Rust vector tile generator — OSM + Overture Maps → protomaps `PMTiles`.
#[derive(Debug, Parser)]
#[command(
name = "geolith",
version,
long_version = crate::cli::LONG_VERSION,
about,
override_usage = "geolith --data <DATA> --natural-earth <NATURAL_EARTH> --water-polygons <WATER_POLYGONS> --land-polygons <LAND_POLYGONS> --output <OUTPUT>\n geolith --output-format routing --osm-pbf <OSM_PBF> --routing-output <ROUTING_OUTPUT>"
)]
pub struct Config {
/// Path to Overture Maps data directory (hive-partitioned Parquet).
///
/// Required by the tiles and geocoding formats.
#[arg(long)]
pub data: Option<PathBuf>,
/// Path to planet.osm.pbf file (optional — omit for Overture-only builds).
#[arg(long)]
pub osm_pbf: Option<PathBuf>,
/// Path to Natural Earth SQLite file.
///
/// Required by the tiles format.
#[arg(long)]
pub natural_earth: Option<PathBuf>,
/// Path to water-polygons-split-3857 shapefile directory.
///
/// Required by the tiles format.
#[arg(long)]
pub water_polygons: Option<PathBuf>,
/// Path to land-polygons-split-3857 shapefile directory.
///
/// Required by the tiles format.
#[arg(long)]
pub land_polygons: Option<PathBuf>,
/// Path to India boundary `GeoJSON` file (optional).
#[arg(long)]
pub india_boundary: Option<PathBuf>,
/// India's outline on the Survey of India map (`GeoJSON` polygons, e.g.
/// `DataMeet`'s `india-composite.geojson`). Geocoding draws and resolves
/// India, Ladakh, Jammu and Kashmir, Pakistan and China with it;
/// required when the geocoding build covers India, and when the
/// --routing-admins source holds India (routing nodes inside it are in
/// India).
#[arg(long)]
pub india_outline: Option<PathBuf>,
/// Output `PMTiles` file path.
///
/// Required by the tiles format, and by geocoding without
/// --geocoding-output.
#[arg(long, short)]
pub output: Option<PathBuf>,
/// Bounding box filter: `min_lon,min_lat,max_lon,max_lat`
#[arg(long, allow_hyphen_values = true)]
pub bbox: Option<String>,
/// Maximum zoom level (default: 15).
#[arg(long, default_value = "15")]
pub max_zoom: u8,
/// Number of threads (default: available parallelism).
#[arg(long)]
pub threads: Option<usize>,
/// Sort buffer size per thread in megabytes (0 = auto-detect).
///
/// When set to 0 (the default), the chunk size is computed as
/// `min(2 GB, total_RAM / (3 × threads))`. Larger chunks produce
/// fewer files, speeding up the k-way merge phase.
#[arg(long, default_value = "0")]
pub chunk_size_mb: usize,
/// Directory for sort chunks and scratch files (default: the system
/// temporary directory). Point it at a volume with room: a planet build
/// writes about 200 GiB of chunks here.
#[arg(long)]
pub tmpdir: Option<PathBuf>,
/// Path to node coordinate store (mmap file for OSM processing).
#[arg(long)]
pub node_store: Option<PathBuf>,
/// Buildings data source: "osm", "overture", or "both".
#[arg(long, default_value = "both")]
pub buildings_source: String,
/// Places data source: "osm", "overture", or "both".
#[arg(long, default_value = "both")]
pub places_source: String,
/// Divisions data source: "overture" or "none".
#[arg(long, default_value = "overture")]
pub divisions_source: String,
/// Landcover data source: "overture" or "none".
#[arg(long, default_value = "overture")]
pub landcover_source: String,
/// Bathymetry data source: "overture" or "none".
#[arg(long, default_value = "overture")]
pub bathymetry_source: String,
/// Roads data source: "osm", "overture", or "both".
#[arg(long, default_value = "both")]
pub roads_source: String,
/// POIs data source: "osm", "overture", or "both".
#[arg(long, default_value = "both")]
pub pois_source: String,
/// Water data source: "osm", "overture", or "both".
#[arg(long, default_value = "both")]
pub water_source: String,
/// Landuse data source: "osm", "overture", or "both".
#[arg(long, default_value = "both")]
pub landuse_source: String,
/// Enable node store caching between runs.
///
/// When enabled (default), a sidecar `.meta.json` file is written
/// alongside the node store. On re-runs with the same PBF file,
/// the node collection pass is skipped entirely — reducing from
/// 2 PBF reads to 1.
#[command(flatten)]
pub reuse: RunReuse,
/// Output format: "tiles" (default), "geocoding" or "routing".
///
/// "routing" builds the routing graph from --osm-pbf and writes a
/// `.glx` file with one routing part to --routing-output. Any other
/// value fails with an error.
#[arg(long, default_value = "tiles")]
pub output_format: String,
/// Tile encoding format: "mlt" (default) or "mvt".
///
/// MLT (`MapLibre` Tiles) uses columnar encoding with built-in compression,
/// producing 50–80% smaller tiles. MVT uses protobuf + gzip.
#[arg(long, default_value = "mvt")]
pub tile_format: String,
/// Directory containing GERS bridge Parquet files for OSM deduplication.
///
/// When provided, all `.parquet` files in this directory (recursively) are
/// loaded into the deduplication index. If not set, geolith automatically
/// looks for a `gers-bridge/` sibling directory next to `--data`.
///
/// Expected structure:
/// ```text
/// gers-bridge/
/// ├── buildings/*.zstd.parquet
/// ├── transportation/*.zstd.parquet
/// └── divisions/*.zstd.parquet
/// ```
#[arg(long)]
pub bridge_dir: Option<PathBuf>,
/// Disable GERS conflation even when bridge files are found.
///
/// By default, conflation is enabled automatically when bridge files
/// are discovered. Set this flag to skip deduplication.
#[arg(long, default_value = "false")]
pub no_conflate: bool,
/// Paths to individual GERS bridge Parquet files (can be specified multiple times).
///
/// Alternative to `--bridge-dir` for specifying individual bridge files.
/// These are loaded in addition to any files found via `--bridge-dir`.
#[arg(long)]
pub bridge_files: Vec<PathBuf>,
/// Geocoding output format: "glx" (default: one `.glx` index file that
/// geolith search serves), "pg-copy" (rows and schema for your own
/// Postgres), "photon", or "pelias".
///
/// Only used when --output-format geocoding.
#[arg(long, default_value = "glx")]
pub geocoding_format: String,
/// Text index emitted in the companion DDL for the pg-copy format.
///
/// `tin` (default) needs the `tin` extension, available on `PlanetScale`
/// Postgres and Neki. `gin` needs no extension and runs anywhere.
#[arg(long, value_enum, default_value_t = PgIndexFlavor::Tin)]
pub pg_index_flavor: PgIndexFlavor,
/// Output path for geocoding data.
///
/// Only used when --output-format geocoding. Defaults to <output>.tsv for
/// pg-copy, <output>.ndjson for photon and pelias, and <output>.glx for glx.
#[arg(long)]
pub geocoding_output: Option<PathBuf>,
/// Nominatim's Wikipedia importance file, `wikimedia-importance.csv.gz`
/// from <https://nominatim.org/data/>. An OSM place with a `wikidata`
/// tag takes the importance of its Wikipedia article, so "London" finds
/// the city before a shop named after it. Without the file, a place
/// takes a default from its type.
///
/// Only used when --output-format geocoding.
#[arg(long)]
pub wikimedia_importance: Option<PathBuf>,
/// Output path for the routing `.glx` file.
///
/// Only used when --output-format routing.
#[arg(long)]
pub routing_output: Option<PathBuf>,
/// Directory to write the auto metric to as a turn-expanded graph
/// (`RoutingKit` vectors: `first_out`, `head`, `travel_time`, `latitude`,
/// `longitude` and the `vertex_*` mapping), the input of the
/// customizable contraction hierarchy.
///
/// Only used when --output-format routing.
#[arg(long)]
pub routing_metric_out: Option<PathBuf>,
/// Costing profiles to build a customizable contraction hierarchy for,
/// comma-separated (`auto`, `pedestrian`, `bicycle`). Each becomes its
/// own set of sections in the routing part (glx spec v1, 10.5).
///
/// Only used when --output-format routing.
#[arg(long, value_delimiter = ',')]
pub routing_cch: Vec<String>,
/// Directory of historical speeds in the reference CSV format: one file
/// per graph tile named by tile path (`2/000/753/554.csv`), rows
/// `edge_graph_id,free_flow_kph,constrained_kph,encoded_dct`. Fills the
/// tiles' predicted-speeds section and flow speeds exactly as
/// `valhalla_add_predicted_traffic` does.
///
/// Only used when --output-format routing.
#[arg(long)]
pub routing_predicted_speeds: Option<PathBuf>,
/// Default speed table in the reference `default_speeds_config` format
/// (`OpenStreetMapSpeeds` `default_speeds.json`): km/h per region,
/// rural/suburban/urban density band, road class, link, roundabout and
/// service use. A configured speed replaces the heuristic speed of every
/// vehicular non-ferry edge, a tagged `maxspeed` included, exactly as
/// the reference `SpeedAssigner` does.
///
/// Only used when --output-format routing.
#[arg(long)]
pub routing_default_speeds: Option<PathBuf>,
/// OSM PBF whose admin boundary relations give each routing node its
/// country and state, side of the road and country access rules, and
/// each edge its row of --routing-default-speeds: the reference's admin
/// database (`valhalla_build_admins`), read from relations with
/// `type=boundary` at `admin_level` 2 and 4 (3 and 6 in a few countries)
/// and their member ways and nodes. May be the --osm-pbf itself or a
/// file of boundaries only. Nodes inside India take India as drawn by
/// the Survey of India: --india-outline is required when the source
/// holds India.
///
/// Only used when --output-format routing.
#[arg(long)]
pub routing_admins: Option<PathBuf>,
/// Time zone areas for the routing nodes: the `.shp` of a
/// timezone-boundary-builder shapefile release
/// (`combined-shapefile-with-oceans-1970.shp`, attribute `tzid`), as
/// the reference's `valhalla_build_timezones` imports it. Each node
/// takes the index of the zone that holds it, which the router uses for
/// local time. Without it every node has no time zone and routes at a
/// `date_time` run in UTC.
///
/// Only used when --output-format routing.
#[arg(long)]
pub routing_timezones: Option<PathBuf>,
/// Delete each Overture Parquet file once its features are safely in the
/// sort chunks.
///
/// Phase 1 streams every source exactly once and Phases 2-4 read only the
/// chunks, so the source tree can be released progressively rather than
/// held alongside it. That keeps the peak footprint near the release size
/// instead of `release + chunks`, which is the difference between fitting
/// on a disk-constrained machine and hitting ENOSPC mid-read.
///
/// Only Overture inputs are affected, and only after both the read and the
/// chunk flush for a file succeed. Re-download the release to restore.
#[arg(long, default_value = "false")]
pub reclaim_source_after_read: bool,
/// Give the disk space of each sort chunk back while the merge reads it.
///
/// The merge reads every chunk once, front to back. With this flag it
/// frees each block of a chunk as soon as the block is read and deletes
/// the chunk at its end, so the chunks shrink while the archive grows and
/// the two do not peak together. On a planet build that is the difference
/// between `chunks + archive` and the larger of the two.
///
/// A build that stops during the merge cannot `--resume` from its chunks
/// afterwards: they are gone as far as they were read.
#[arg(long, default_value = "false")]
pub reclaim_chunks: bool,
/// Skip the check of free disk space before phase 1.
///
/// Without this flag the tile build estimates the disk it needs from the
/// size of the inputs and stops at once, naming the GiB, when the volume
/// of --tmpdir, --output or --node-store is short.
#[arg(long, default_value = "false")]
pub no_disk_check: bool,
}
impl Config {
/// Parse CLI arguments, exiting with a usage error when a flag the
/// output format reads is missing.
pub fn parse_args() -> Self {
let config = Self::parse();
if let Err(e) = config.check_required() {
e.exit();
}
config
}
/// The value of a path flag.
#[must_use]
pub fn path(&self, flag: PathFlag) -> Option<&Path> {
match flag {
PathFlag::Data => self.data.as_deref(),
PathFlag::NaturalEarth => self.natural_earth.as_deref(),
PathFlag::WaterPolygons => self.water_polygons.as_deref(),
PathFlag::LandPolygons => self.land_polygons.as_deref(),
PathFlag::Output => self.output.as_deref(),
}
}
/// The path flags the output format reads, in usage order: all five
/// for tiles (and an unknown format, which fails later), `--data` and
/// `--output` for geocoding (`--output` only without
/// `--geocoding-output`), none for routing.
#[must_use]
pub fn required_flags(&self) -> Vec<PathFlag> {
match self.output_format.as_str() {
"routing" => Vec::new(),
"geocoding" => {
let mut flags = vec![PathFlag::Data];
if self.geocoding_output.is_none() {
flags.push(PathFlag::Output);
}
flags
}
_ => vec![
PathFlag::Data,
PathFlag::NaturalEarth,
PathFlag::WaterPolygons,
PathFlag::LandPolygons,
PathFlag::Output,
],
}
}
/// A usage error naming the flags in `missing`, worded as the
/// argument parser words a missing required argument.
fn missing_error(missing: &[PathFlag]) -> clap::Error {
let mut msg = String::from("the following required arguments were not provided:");
for f in missing {
msg.push_str("\n ");
msg.push_str(f.usage());
}
Self::command().error(clap::error::ErrorKind::MissingRequiredArgument, msg)
}
/// Check that every path flag the output format reads is present.
///
/// # Errors
///
/// A usage error naming each missing flag.
pub fn check_required(&self) -> Result<(), clap::Error> {
let missing: Vec<PathFlag> = self
.required_flags()
.into_iter()
.filter(|&f| self.path(f).is_none())
.collect();
if missing.is_empty() {
Ok(())
} else {
Err(Self::missing_error(&missing))
}
}
/// The value of a path flag the running format needs.
///
/// # Errors
///
/// The usage error for a missing required flag.
pub fn required_path(&self, flag: PathFlag) -> Result<&Path, clap::Error> {
self.path(flag).ok_or_else(|| Self::missing_error(&[flag]))
}
/// Check if India boundary fix is enabled.
pub const fn has_india_boundary(&self) -> bool {
self.india_boundary.is_some()
}
/// Check if a source should include OSM data.
pub fn uses_osm(&self, source: &str) -> bool {
self.tiles_view().uses_osm(source)
}
/// Check if a source should include Overture data.
pub fn uses_overture(&self, source: &str) -> bool {
self.tiles_view().uses_overture(source)
}
/// Whether Overture data should be included for a given layer.
///
/// Layers without a dedicated source flag always include Overture data.
pub fn overture_enabled(&self, layer: crate::layers::Layer) -> bool {
self.tiles_view().overture_enabled(layer)
}
/// Whether OSM data should be included for a given layer.
///
/// Returns `false` for all layers when `--osm-pbf` is not provided.
pub fn osm_enabled(&self, layer: crate::layers::Layer) -> bool {
self.tiles_view().osm_enabled(layer)
}
/// Compute the effective sort-buffer size in bytes per thread.
pub fn effective_chunk_bytes(&self) -> usize {
self.tiles_view().effective_chunk_bytes()
}
/// Discover all GERS bridge Parquet files for OSM deduplication.
///
/// Resolution order: explicit `--bridge-files`, then `--bridge-dir`,
/// then the `gers-bridge/` sibling of `--data`.
#[must_use]
pub fn discover_bridge_files(&self) -> Vec<PathBuf> {
self.tiles_view().discover_bridge_files()
}
/// The tile build this invocation describes.
///
/// # Errors
///
/// A usage error naming each path flag the tile build needs and lacks.
pub fn tiles(&self) -> Result<TilesConfig, clap::Error> {
let missing: Vec<PathFlag> = [
PathFlag::Data,
PathFlag::NaturalEarth,
PathFlag::WaterPolygons,
PathFlag::LandPolygons,
PathFlag::Output,
]
.into_iter()
.filter(|&f| self.path(f).is_none())
.collect();
if missing.is_empty() {
Ok(self.tiles_view())
} else {
Err(Self::missing_error(&missing))
}
}
/// The tile build with empty paths where a flag is missing: enough for
/// the questions that do not read a path.
fn tiles_view(&self) -> TilesConfig {
let path = |flag| self.path(flag).map(Path::to_path_buf).unwrap_or_default();
let mut tiles = TilesConfig::new(
path(PathFlag::Data),
path(PathFlag::NaturalEarth),
path(PathFlag::WaterPolygons),
path(PathFlag::LandPolygons),
path(PathFlag::Output),
);
tiles.osm_pbf.clone_from(&self.osm_pbf);
tiles.india_boundary.clone_from(&self.india_boundary);
tiles.bbox.clone_from(&self.bbox);
tiles.max_zoom = self.max_zoom;
tiles.threads = self.threads;
tiles.chunk_size_mb = self.chunk_size_mb;
tiles.tmpdir.clone_from(&self.tmpdir);
tiles.node_store.clone_from(&self.node_store);
tiles.buildings_source.clone_from(&self.buildings_source);
tiles.places_source.clone_from(&self.places_source);
tiles.divisions_source.clone_from(&self.divisions_source);
tiles.landcover_source.clone_from(&self.landcover_source);
tiles.bathymetry_source.clone_from(&self.bathymetry_source);
tiles.roads_source.clone_from(&self.roads_source);
tiles.pois_source.clone_from(&self.pois_source);
tiles.water_source.clone_from(&self.water_source);
tiles.landuse_source.clone_from(&self.landuse_source);
tiles.reuse = geolith_tiles_builder::Reuse::new(self.reuse.node_cache, self.reuse.resume);
tiles.tile_format.clone_from(&self.tile_format);
tiles.bridge_dir.clone_from(&self.bridge_dir);
tiles.no_conflate = self.no_conflate;
tiles.bridge_files.clone_from(&self.bridge_files);
tiles.reclaim_source_after_read = self.reclaim_source_after_read;
tiles.reclaim_chunks = self.reclaim_chunks;
tiles.disk_check = !self.no_disk_check;
tiles
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn uses_osm_for_both() {
let config = Config::try_parse_from([
"geolith",
"--data",
"/tmp/data",
"--osm-pbf",
"/tmp/planet.osm.pbf",
"--natural-earth",
"/tmp/ne.sqlite",
"--water-polygons",
"/tmp/water",
"--land-polygons",
"/tmp/land",
"--output",
"/tmp/out.pmtiles",
])
.expect("parse should succeed");
assert!(config.uses_osm("both"));
assert!(config.uses_osm("osm"));
assert!(!config.uses_osm("overture"));
assert!(config.uses_overture("both"));
assert!(config.uses_overture("overture"));
assert!(!config.uses_overture("osm"));
assert!(!config.has_india_boundary());
}
#[test]
fn default_source_values() {
let config = Config::try_parse_from([
"geolith",
"--data",
"/tmp/data",
"--osm-pbf",
"/tmp/planet.osm.pbf",
"--natural-earth",
"/tmp/ne.sqlite",
"--water-polygons",
"/tmp/water",
"--land-polygons",
"/tmp/land",
"--output",
"/tmp/out.pmtiles",
])
.expect("parse should succeed");
assert_eq!(config.buildings_source, "both");
assert_eq!(config.places_source, "both");
assert_eq!(config.divisions_source, "overture");
assert_eq!(config.landcover_source, "overture");
assert_eq!(config.bathymetry_source, "overture");
assert_eq!(config.roads_source, "both");
assert_eq!(config.pois_source, "both");
assert_eq!(config.water_source, "both");
assert_eq!(config.landuse_source, "both");
assert_eq!(config.max_zoom, 15);
}
#[test]
fn overture_enabled_respects_source_flags() {
let config = Config::try_parse_from([
"geolith",
"--data",
"/tmp/data",
"--osm-pbf",
"/tmp/planet.osm.pbf",
"--natural-earth",
"/tmp/ne.sqlite",
"--water-polygons",
"/tmp/water",
"--land-polygons",
"/tmp/land",
"--output",
"/tmp/out.pmtiles",
"--buildings-source",
"osm",
"--roads-source",
"overture",
"--landcover-source",
"none",
])
.expect("parse should succeed");
use crate::layers::Layer;
assert!(!config.overture_enabled(Layer::Buildings));
assert!(config.overture_enabled(Layer::Roads));
assert!(!config.overture_enabled(Layer::Landcover));
assert!(config.overture_enabled(Layer::Earth));
assert!(config.overture_enabled(Layer::Water));
assert!(config.overture_enabled(Layer::Pois));
assert!(config.overture_enabled(Layer::Landuse));
}
#[test]
fn osm_enabled_respects_source_flags() {
let config = Config::try_parse_from([
"geolith",
"--data",
"/tmp/data",
"--osm-pbf",
"/tmp/planet.osm.pbf",
"--natural-earth",
"/tmp/ne.sqlite",
"--water-polygons",
"/tmp/water",
"--land-polygons",
"/tmp/land",
"--output",
"/tmp/out.pmtiles",
"--buildings-source",
"overture",
"--roads-source",
"osm",
])
.expect("parse should succeed");
use crate::layers::Layer;
assert!(!config.osm_enabled(Layer::Buildings));
assert!(config.osm_enabled(Layer::Roads));
assert!(config.osm_enabled(Layer::Earth));
assert!(config.osm_enabled(Layer::Water));
assert!(config.osm_enabled(Layer::Landuse));
assert!(config.osm_enabled(Layer::Pois));
assert!(config.osm_enabled(Layer::Places));
}
#[test]
fn osm_pbf_omitted_disables_all_osm_layers() {
let config = Config::try_parse_from([
"geolith",
"--data",
"/tmp/data",
"--natural-earth",
"/tmp/ne.sqlite",
"--water-polygons",
"/tmp/water",
"--land-polygons",
"/tmp/land",
"--output",
"/tmp/out.pmtiles",
])
.expect("parse should succeed without --osm-pbf");
use crate::layers::Layer;
assert!(config.osm_pbf.is_none());
assert!(!config.osm_enabled(Layer::Buildings));
assert!(!config.osm_enabled(Layer::Roads));
assert!(!config.osm_enabled(Layer::Earth));
assert!(!config.osm_enabled(Layer::Water));
assert!(!config.osm_enabled(Layer::Landuse));
assert!(!config.osm_enabled(Layer::Pois));
assert!(!config.osm_enabled(Layer::Places));
assert!(!config.osm_enabled(Layer::Transit));
assert!(!config.osm_enabled(Layer::Boundaries));
assert!(config.overture_enabled(Layer::Buildings));
assert!(config.overture_enabled(Layer::Roads));
assert!(config.overture_enabled(Layer::Water));
assert!(config.overture_enabled(Layer::Landuse));
}
#[test]
fn default_output_format_is_tiles() {
let config = Config::try_parse_from([
"geolith",
"--data",
"/tmp/data",
"--osm-pbf",
"/tmp/planet.osm.pbf",
"--natural-earth",
"/tmp/ne.sqlite",
"--water-polygons",
"/tmp/water",
"--land-polygons",
"/tmp/land",
"--output",
"/tmp/out.pmtiles",
])
.expect("parse");
assert_eq!(config.output_format, "tiles");
}
#[test]
fn output_format_flag_parsed() {
let config = Config::try_parse_from([
"geolith",
"--data",
"/tmp/data",
"--osm-pbf",
"/tmp/planet.osm.pbf",
"--natural-earth",
"/tmp/ne.sqlite",
"--water-polygons",
"/tmp/water",
"--land-polygons",
"/tmp/land",
"--output",
"/tmp/out.pmtiles",
"--output-format",
"routing",
])
.expect("parse");
assert_eq!(config.output_format, "routing");
}
/// The `--schema` flag is gone: tiles always follow the protomaps
/// basemap schema, so an old script that still passes it fails loudly.
#[test]
fn schema_flag_is_refused() {
let err = Config::try_parse_from([
"geolith",
"--data",
"/tmp/data",
"--natural-earth",
"/tmp/ne.sqlite",
"--water-polygons",
"/tmp/water",
"--land-polygons",
"/tmp/land",
"--output",
"/tmp/out.pmtiles",
"--schema",
"protomaps",
])
.expect_err("--schema is no longer a flag");
assert_eq!(err.kind(), clap::error::ErrorKind::UnknownArgument);
}
#[test]
fn osrm_output_is_no_longer_a_flag() {
let err = Config::try_parse_from([
"geolith",
"--data",
"/tmp/data",
"--natural-earth",
"/tmp/ne.sqlite",
"--water-polygons",
"/tmp/water",
"--land-polygons",
"/tmp/land",
"--output",
"/tmp/out.pmtiles",
"--osrm-output",
"/tmp/routing.osrm.tar",
])
.expect_err("the OSRM writer was removed");
assert_eq!(err.kind(), clap::error::ErrorKind::UnknownArgument);
}
}