-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse-map.py
More file actions
27 lines (23 loc) · 879 Bytes
/
parse-map.py
File metadata and controls
27 lines (23 loc) · 879 Bytes
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
import osmium, json
import osmium.osm
# Credit to where credit is due!
# https://lonvia.github.io/geopython17-pyosmium
class OSMHandler(osmium.SimpleHandler):
def __init__(self):
super(OSMHandler, self).__init__()
self.results = []
def area(self, area: osmium.osm.Area):
if area.tags.get("landuse") == "military":
print(".", end="", flush=True)
for ring in area.outer_rings():
self.results.append([(p.lat, p.lon) for p in ring])
if __name__ == "__main__":
h = OSMHandler()
print("Processing data...")
# Note: the referenced file must be downloaded before running this script.
h.apply_file("FI-202409120200.osm.pbf", locations=True, idx="flex_mem")
print()
print("Writing JSON...")
with open("base-data.json", "w") as f:
json.dump(h.results, f)
print("Finished.")