forked from balrog-kun/osm-addr-tools
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmerge-building-addrs.py
executable file
·67 lines (55 loc) · 1.87 KB
/
merge-building-addrs.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3.4
import argparse
import io
import logging
import lxml
from converter import osm_to_json
from merger import Merger, get_addresses, OsmAddress
from data.base import Address
def main():
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description="""Merge osm file with address nodes with buildings in specified area as terc code""",
)
parser.add_argument(
"--addr", help="File with address nodes to merge", required=True
)
parser.add_argument(
"--building", help="File with buildings to merge", required=True
)
parser.add_argument(
"--output", help="output file with merged data (default: result.osm)"
)
parser.add_argument("--terc", help="Teryt TERC code for area processed")
parser.add_argument(
"--log-level",
help="Set logging level (debug=10, info=20, warning=30, error=40, critical=50), default: 20",
dest="log_level",
default=20,
type=int,
)
args = parser.parse_args()
log_stderr = logging.StreamHandler()
log_stderr.setLevel(args.log_level)
logIO = io.StringIO()
logging.basicConfig(level=10, handlers=[log_stderr, logging.StreamHandler(logIO)])
if args.output:
output = open(args.output, "wb")
else:
parts = args.input.rsplit(".", 1)
parts[0] += "-merged"
output = open(".".join(parts), "xb")
print("Output filename: %s" % (".".join(parts),))
data = [
OsmAddress.from_soup(x)
for x in osm_to_json(lxml.etree.parse(open(args.addr)))["elements"]
]
addr = osm_to_json(open(args.building))
m = Merger(data, addr, args.terc)
for i in data:
m._do_merge_create_point(i)
m.create_index()
m.merge_addresses()
output.write(m.get_incremental_result(logIO))
if __name__ == "__main__":
main()