Skip to content

Commit aba1f61

Browse files
committed
change collect bounds flags and add a delete option
1 parent baace32 commit aba1f61

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,13 @@ This project provides several command-line tools to work with topographic maps.
174174
Collects individual GeoJSONL bound files into a single GeoJSON FeatureCollection.
175175

176176
```bash
177-
collect-bounds --bounds-dir <directory> --output-file <file> [--preexisting-file <file>]
177+
collect-bounds -b <directory> -o <file> [-u] [-d <id1> <id2> ...]
178178
```
179179

180-
- `--bounds-dir`: Directory containing GeoJSONL files. (Required)
181-
- `--output-file`: Output GeoJSON file path. (Required)
182-
- `--preexisting-file`: Pre existing GeoJSON file path. (Optional)
180+
- `-b`, `--bounds-dir`: Directory containing GeoJSONL files. (Required)
181+
- `-o`, `--output-file`: Output GeoJSON file path. (Required)
182+
- `-u`, `--update`: Update the output file in place. (Optional)
183+
- `-d`, `--delete`: List of ids to delete from the output file (only available in update mode). (Optional)
183184

184185
#### `retile`
185186

topo_map_processor/tools/collect_bounds.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,32 @@
55

66
def cli():
77
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)')
1112

1213
args = parser.parse_args()
1314

15+
if args.delete and not args.update:
16+
raise parser.error("--delete can only be used with --update")
17+
1418
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}")
1923

20-
existing_data = json.loads(preexisting_file.read_text())
24+
existing_data = json.loads(output_file.read_text())
2125
for feature in existing_data.get('features', []):
2226
if 'properties' in feature and 'id' in feature['properties']:
2327
sheet_name = feature['properties']['id']
2428
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]
2534

2635
bounds_dir = Path(args.bounds_dir)
2736

0 commit comments

Comments
 (0)