|
5 | 5 |
|
6 | 6 | def cli(): |
7 | 7 | parser = argparse.ArgumentParser(description='Collect GeoJSONL files into a single GeoJSON file.') |
8 | | - parser.add_argument('--bounds-dir', required=True, help='Directory containing GeoJSONL files') |
9 | | - parser.add_argument('--output-file', required=True, help='Output GeoJSON file path') |
10 | | - parser.add_argument('--preexisting-file', help='preexisting GeoJSON file to base things on', default=None) |
| 8 | + parser.add_argument('-b', '--bounds-dir', required=True, help='Directory containing GeoJSONL files') |
| 9 | + parser.add_argument('-o', '--output-file', required=True, help='Output GeoJSON file path') |
| 10 | + parser.add_argument('-u', '--update', action='store_true', help='Update the output file in place') |
| 11 | + parser.add_argument('-d', '--delete', nargs='+', help='List of ids to delete from the output file (only in update mode)') |
11 | 12 |
|
12 | 13 | args = parser.parse_args() |
13 | 14 |
|
| 15 | + if args.delete and not args.update: |
| 16 | + raise parser.error("--delete can only be used with --update") |
| 17 | + |
14 | 18 | feat_map = {} |
15 | | - if args.preexisting_file: |
16 | | - preexisting_file = Path(args.preexisting_file) |
17 | | - if not preexisting_file.exists(): |
18 | | - raise FileNotFoundError(f"Preexisting file does not exist: {preexisting_file}") |
| 19 | + if args.update: |
| 20 | + output_file = Path(args.output_file) |
| 21 | + if not output_file.exists(): |
| 22 | + raise FileNotFoundError(f"Output file does not exist for updating: {output_file}") |
19 | 23 |
|
20 | | - existing_data = json.loads(preexisting_file.read_text()) |
| 24 | + existing_data = json.loads(output_file.read_text()) |
21 | 25 | for feature in existing_data.get('features', []): |
22 | 26 | if 'properties' in feature and 'id' in feature['properties']: |
23 | 27 | sheet_name = feature['properties']['id'] |
24 | 28 | feat_map[sheet_name] = feature |
| 29 | + |
| 30 | + if args.delete: |
| 31 | + for sheet_id in args.delete: |
| 32 | + if sheet_id in feat_map: |
| 33 | + del feat_map[sheet_id] |
25 | 34 |
|
26 | 35 | bounds_dir = Path(args.bounds_dir) |
27 | 36 |
|
|
0 commit comments