@@ -47,6 +47,26 @@ def _empty_path_callback(ctx: typer.Context, value: Path) -> Optional[Path]:
47
47
return _path_callback (ctx , value )
48
48
49
49
50
+ class BboxGeometryParser (click .ParamType ): # type: ignore
51
+ """Parser for geometry in WKT form."""
52
+
53
+ name = "BBOX"
54
+
55
+ def convert (self , value , param = None , ctx = None ): # type: ignore
56
+ """Convert parameter value."""
57
+ try :
58
+ from shapely import box
59
+
60
+ bbox_values = [float (x .strip ()) for x in value .split ("," )]
61
+ return box (* bbox_values )
62
+ except ValueError : # ValueError raised when passing non-numbers to float()
63
+ raise typer .BadParameter (
64
+ "Cannot parse provided bounding box."
65
+ " Valid value must contain 4 floating point numbers"
66
+ " separated by commas."
67
+ ) from None
68
+
69
+
50
70
class WktGeometryParser (click .ParamType ): # type: ignore
51
71
"""Parser for geometry in WKT form."""
52
72
@@ -278,6 +298,7 @@ def main(
278
298
help = "PBF file to convert into GeoParquet. Can be an URL." ,
279
299
metavar = "PBF file path" ,
280
300
callback = _empty_path_callback ,
301
+ show_default = False ,
281
302
),
282
303
] = None ,
283
304
osm_tags_filter : Annotated [
@@ -293,6 +314,7 @@ def main(
293
314
" [bold bright_cyan]osm-tags-filter-file[/bold bright_cyan]."
294
315
),
295
316
click_type = OsmTagsFilterJsonParser (),
317
+ show_default = False ,
296
318
),
297
319
] = None ,
298
320
osm_tags_filter_file : Annotated [
@@ -308,6 +330,7 @@ def main(
308
330
" [bold bright_cyan]osm-tags-filter[/bold bright_cyan]."
309
331
),
310
332
click_type = OsmTagsFilterFileParser (),
333
+ show_default = False ,
311
334
),
312
335
] = None ,
313
336
keep_all_tags : Annotated [
@@ -326,22 +349,32 @@ def main(
326
349
show_default = False ,
327
350
),
328
351
] = False ,
352
+ geom_filter_bbox : Annotated [
353
+ Optional [str ],
354
+ typer .Option (
355
+ help = (
356
+ "Geometry to use as a filter in the"
357
+ " [bold dark_orange]bounding box[/bold dark_orange] format - 4 floating point"
358
+ " numbers separated by commas."
359
+ " Cannot be used together with other"
360
+ " [bold bright_cyan]geom-filter-...[/bold bright_cyan] parameters."
361
+ ),
362
+ click_type = BboxGeometryParser (),
363
+ show_default = False ,
364
+ ),
365
+ ] = None ,
329
366
geom_filter_file : Annotated [
330
367
Optional [str ],
331
368
typer .Option (
332
369
help = (
333
370
"Geometry to use as a filter in the"
334
371
" [bold dark_orange]file[/bold dark_orange] format - any that can be opened by"
335
372
" GeoPandas. Will return the unary union of the geometries in the file."
336
- " Cannot be used together with"
337
- " [bold bright_cyan]geom-filter-geocode[/bold bright_cyan] or"
338
- " [bold bright_cyan]geom-filter-geojson[/bold bright_cyan] or"
339
- " [bold bright_cyan]geom-filter-index-geohash[/bold bright_cyan] or"
340
- " [bold bright_cyan]geom-filter-index-h3[/bold bright_cyan] or"
341
- " [bold bright_cyan]geom-filter-index-s2[/bold bright_cyan] or"
342
- " [bold bright_cyan]geom-filter-wkt[/bold bright_cyan]."
373
+ " Cannot be used together with other"
374
+ " [bold bright_cyan]geom-filter-...[/bold bright_cyan] parameters."
343
375
),
344
376
click_type = GeoFileGeometryParser (),
377
+ show_default = False ,
345
378
),
346
379
] = None ,
347
380
geom_filter_geocode : Annotated [
@@ -351,15 +384,11 @@ def main(
351
384
"Geometry to use as a filter in the"
352
385
" [bold dark_orange]string to geocode[/bold dark_orange] format - it will be"
353
386
" geocoded to the geometry using Nominatim API (GeoPy library)."
354
- " Cannot be used together with"
355
- " [bold bright_cyan]geom-filter-file[/bold bright_cyan] or"
356
- " [bold bright_cyan]geom-filter-geojson[/bold bright_cyan] or"
357
- " [bold bright_cyan]geom-filter-index-geohash[/bold bright_cyan] or"
358
- " [bold bright_cyan]geom-filter-index-h3[/bold bright_cyan] or"
359
- " [bold bright_cyan]geom-filter-index-s2[/bold bright_cyan] or"
360
- " [bold bright_cyan]geom-filter-wkt[/bold bright_cyan]."
387
+ " Cannot be used together with other"
388
+ " [bold bright_cyan]geom-filter-...[/bold bright_cyan] parameters."
361
389
),
362
390
click_type = GeocodeGeometryParser (),
391
+ show_default = False ,
363
392
),
364
393
] = None ,
365
394
geom_filter_geojson : Annotated [
@@ -368,15 +397,11 @@ def main(
368
397
help = (
369
398
"Geometry to use as a filter in the [bold dark_orange]GeoJSON[/bold dark_orange]"
370
399
" format."
371
- " Cannot be used used together with"
372
- " [bold bright_cyan]geom-filter-file[/bold bright_cyan] or"
373
- " [bold bright_cyan]geom-filter-geocode[/bold bright_cyan] or"
374
- " [bold bright_cyan]geom-filter-index-geohash[/bold bright_cyan] or"
375
- " [bold bright_cyan]geom-filter-index-h3[/bold bright_cyan] or"
376
- " [bold bright_cyan]geom-filter-index-s2[/bold bright_cyan] or"
377
- " [bold bright_cyan]geom-filter-wkt[/bold bright_cyan]."
400
+ " Cannot be used together with other"
401
+ " [bold bright_cyan]geom-filter-...[/bold bright_cyan] parameters."
378
402
),
379
403
click_type = GeoJsonGeometryParser (),
404
+ show_default = False ,
380
405
),
381
406
] = None ,
382
407
geom_filter_index_geohash : Annotated [
@@ -386,15 +411,11 @@ def main(
386
411
"Geometry to use as a filter in the"
387
412
" [bold dark_orange]Geohash index[/bold dark_orange]"
388
413
" format. Separate multiple values with a comma."
389
- " Cannot be used used together with"
390
- " [bold bright_cyan]geom-filter-file[/bold bright_cyan] or"
391
- " [bold bright_cyan]geom-filter-geocode[/bold bright_cyan] or"
392
- " [bold bright_cyan]geom-filter-geojson[/bold bright_cyan] or"
393
- " [bold bright_cyan]geom-filter-index-h3[/bold bright_cyan] or"
394
- " [bold bright_cyan]geom-filter-index-s2[/bold bright_cyan] or"
395
- " [bold bright_cyan]geom-filter-wkt[/bold bright_cyan]."
414
+ " Cannot be used together with other"
415
+ " [bold bright_cyan]geom-filter-...[/bold bright_cyan] parameters."
396
416
),
397
417
click_type = GeohashGeometryParser (),
418
+ show_default = False ,
398
419
),
399
420
] = None ,
400
421
geom_filter_index_h3 : Annotated [
@@ -403,15 +424,11 @@ def main(
403
424
help = (
404
425
"Geometry to use as a filter in the [bold dark_orange]H3 index[/bold dark_orange]"
405
426
" format. Separate multiple values with a comma."
406
- " Cannot be used used together with"
407
- " [bold bright_cyan]geom-filter-file[/bold bright_cyan] or"
408
- " [bold bright_cyan]geom-filter-geocode[/bold bright_cyan] or"
409
- " [bold bright_cyan]geom-filter-geojson[/bold bright_cyan] or"
410
- " [bold bright_cyan]geom-filter-index-geohash[/bold bright_cyan] or"
411
- " [bold bright_cyan]geom-filter-index-s2[/bold bright_cyan] or"
412
- " [bold bright_cyan]geom-filter-wkt[/bold bright_cyan]."
427
+ " Cannot be used together with other"
428
+ " [bold bright_cyan]geom-filter-...[/bold bright_cyan] parameters."
413
429
),
414
430
click_type = H3GeometryParser (),
431
+ show_default = False ,
415
432
),
416
433
] = None ,
417
434
geom_filter_index_s2 : Annotated [
@@ -420,15 +437,11 @@ def main(
420
437
help = (
421
438
"Geometry to use as a filter in the [bold dark_orange]S2 index[/bold dark_orange]"
422
439
" format. Separate multiple values with a comma."
423
- " Cannot be used used together with"
424
- " [bold bright_cyan]geom-filter-file[/bold bright_cyan] or"
425
- " [bold bright_cyan]geom-filter-geocode[/bold bright_cyan] or"
426
- " [bold bright_cyan]geom-filter-geojson[/bold bright_cyan] or"
427
- " [bold bright_cyan]geom-filter-index-geohash[/bold bright_cyan] or"
428
- " [bold bright_cyan]geom-filter-index-h3[/bold bright_cyan] or"
429
- " [bold bright_cyan]geom-filter-wkt[/bold bright_cyan]."
440
+ " Cannot be used together with other"
441
+ " [bold bright_cyan]geom-filter-...[/bold bright_cyan] parameters."
430
442
),
431
443
click_type = S2GeometryParser (),
444
+ show_default = False ,
432
445
),
433
446
] = None ,
434
447
geom_filter_wkt : Annotated [
@@ -437,15 +450,11 @@ def main(
437
450
help = (
438
451
"Geometry to use as a filter in the [bold dark_orange]WKT[/bold dark_orange]"
439
452
" format."
440
- " Cannot be used together with"
441
- " [bold bright_cyan]geom-filter-file[/bold bright_cyan] or"
442
- " [bold bright_cyan]geom-filter-geocode[/bold bright_cyan] or"
443
- " [bold bright_cyan]geom-filter-geojson[/bold bright_cyan] or"
444
- " [bold bright_cyan]geom-filter-index-geohash[/bold bright_cyan] or"
445
- " [bold bright_cyan]geom-filter-index-h3[/bold bright_cyan] or"
446
- " [bold bright_cyan]geom-filter-index-s2[/bold bright_cyan]."
453
+ " Cannot be used together with other"
454
+ " [bold bright_cyan]geom-filter-...[/bold bright_cyan] parameters."
447
455
),
448
456
click_type = WktGeometryParser (),
457
+ show_default = False ,
449
458
),
450
459
] = None ,
451
460
osm_extract_query : Annotated [
@@ -457,6 +466,7 @@ def main(
457
466
"Can be used instead of [bold yellow]PBF file path[/bold yellow] argument."
458
467
),
459
468
case_sensitive = False ,
469
+ show_default = False ,
460
470
),
461
471
] = None ,
462
472
osm_extract_source : Annotated [
@@ -505,6 +515,7 @@ def main(
505
515
" Can be [bold green].parquet[/bold green] or"
506
516
" [bold green].db[/bold green] or [bold green].duckdb[/bold green] extension."
507
517
),
518
+ show_default = False ,
508
519
),
509
520
] = None ,
510
521
duckdb : Annotated [
@@ -558,6 +569,7 @@ def main(
558
569
" for file generation."
559
570
),
560
571
callback = _empty_path_callback ,
572
+ show_default = False ,
561
573
),
562
574
] = None ,
563
575
filter_osm_ids : Annotated [
@@ -570,6 +582,7 @@ def main(
570
582
" Separate multiple values with a comma."
571
583
),
572
584
callback = _filter_osm_ids_callback ,
585
+ show_default = False ,
573
586
),
574
587
] = None ,
575
588
wkt_result : Annotated [
@@ -655,6 +668,7 @@ def main(
655
668
number_of_geometries_provided = sum (
656
669
geom is not None
657
670
for geom in (
671
+ geom_filter_bbox ,
658
672
geom_filter_file ,
659
673
geom_filter_geocode ,
660
674
geom_filter_geojson ,
@@ -668,7 +682,8 @@ def main(
668
682
raise typer .BadParameter ("Provided more than one geometry for filtering" )
669
683
670
684
geometry_filter_value = (
671
- geom_filter_file
685
+ geom_filter_bbox
686
+ or geom_filter_file
672
687
or geom_filter_geocode
673
688
or geom_filter_geojson
674
689
or geom_filter_index_geohash
@@ -685,7 +700,7 @@ def main(
685
700
message = (
686
701
"QuackOSM requires either the path to the pbf file,"
687
702
" an OSM extract query (--osm-extract-query) or a geometry filter"
688
- " (one of --geom-filter-file, --geom-filter-geocode,"
703
+ " (one of --geom-filter-bbox, --geom-filter- file, --geom-filter-geocode,"
689
704
" --geom-filter-geojson, --geom-filter-index-geohash,"
690
705
" --geom-filter-index-h3, --geom-filter-index-s2, --geom-filter-wkt)"
691
706
" to download the file automatically. All three cannot be empty at once."
0 commit comments