-
Notifications
You must be signed in to change notification settings - Fork 1
/
extract.py
30 lines (22 loc) · 1.17 KB
/
extract.py
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
import argparse
from robosat.osm.parking import ParkingHandler
from robosat.osm.building import BuildingHandler
from robosat.osm.road import RoadHandler
# Register your osmium handlers here; in addition to the osmium handler interface
# they need to support a `save(path)` function for GeoJSON serialization to a file.
handlers = {"parking": ParkingHandler, "building": BuildingHandler, "road": RoadHandler}
def add_parser(subparser):
parser = subparser.add_parser(
"extract",
help="extracts GeoJSON features from OpenStreetMap",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument("--type", type=str, required=True, choices=handlers.keys(), help="type of feature to extract")
parser.add_argument("--batch", type=int, default=100000, help="number of features to save per file")
parser.add_argument("map", type=str, help="path to .osm.pbf base map")
parser.add_argument("out", type=str, help="path to GeoJSON file to store features in")
parser.set_defaults(func=main)
def main(args):
handler = handlers[args.type](args.out, args.batch)
handler.apply_file(filename=args.map, locations=True)
handler.flush()