Coverage for src/overturetoosm/cli.py: 0%
37 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-07-22 06:43 -0400
« prev ^ index » next coverage.py v7.6.1, created at 2025-07-22 06:43 -0400
1"""Command line interface for the overturetoosm package."""
3import argparse
4import json
6from . import process_address, process_building, process_geojson, process_place
9def main():
10 """Configure the argument parser for the CLI."""
11 parent = argparse.ArgumentParser(add_help=False)
12 parent.add_argument(
13 "-i", "--input", required=True, help="Path to the input GeoJSON file"
14 )
15 out = parent.add_argument_group("output options")
16 output_group = out.add_mutually_exclusive_group(required=True)
17 output_group.add_argument("-o", "--output", help="Path to the output GeoJSON file")
18 output_group.add_argument(
19 "--in-place",
20 action="store_true",
21 help="Convert the input file in place (overwrites the input file)",
22 )
24 parser = argparse.ArgumentParser(
25 description="Convert Overture data to the OSM schema in the GeoJSON format."
26 )
27 subs = parser.add_subparsers(dest="fx_type", help="types")
28 place_parser = subs.add_parser("place", help="Convert place data", parents=[parent])
29 place_parser.add_argument(
30 "-c",
31 "--confidence",
32 type=float,
33 default=0.0,
34 help="The minimum confidence level. Default: 0.0",
35 )
36 place_parser.add_argument(
37 "-r",
38 "--region-tag",
39 default="addr:state",
40 help="What tag to convert Overture's `region` tag to. Default: `addr:state`",
41 )
42 place_parser.add_argument(
43 "-u",
44 "--unmatched",
45 choices=["force", "ignore"],
46 default="ignore",
47 help="How to handle unmatched Overture categories. Default: ignore",
48 )
50 building_parser = subs.add_parser(
51 "building", help="Convert building data", parents=[parent]
52 )
53 building_parser.add_argument(
54 "-c",
55 "--confidence",
56 type=float,
57 default=0.0,
58 help="The minimum confidence level. Default: 0.0",
59 )
61 address_parser = subs.add_parser(
62 "address", help="Convert address data", parents=[parent]
63 )
64 address_parser.add_argument(
65 "-s",
66 "--style",
67 default="US",
68 help="How to handle the `address_levels` field. Default: US",
69 )
71 args = parser.parse_args()
73 with open(args.input, encoding="utf-8") as f:
74 contents: dict = json.load(f)
75 geojson = {}
76 if args.fx_type == "place":
77 geojson = process_geojson(
78 contents,
79 process_place,
80 confidence=args.confidence,
81 options={"region_tag": args.region_tag, "unmatched": args.unmatched},
82 )
83 elif args.fx_type == "building":
84 geojson = process_geojson(
85 contents, process_building, confidence=args.confidence
86 )
87 elif args.fx_type == "address":
88 geojson = process_geojson(
89 contents, process_address, options={"style": args.style}
90 )
92 if not geojson:
93 raise ValueError("No features found in the input file.")
95 if args.in_place:
96 with open(args.input, "w+", encoding="utf-8") as f:
97 json.dump(geojson, f, indent=4)
98 else:
99 with open(args.output, "w+", encoding="utf-8") as f:
100 json.dump(geojson, f, indent=4)