-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudit.py
More file actions
72 lines (60 loc) · 2.09 KB
/
audit.py
File metadata and controls
72 lines (60 loc) · 2.09 KB
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
68
69
70
71
72
import xml.etree.cElementTree as ET
from collections import defaultdict
import re
import pprint
street_type_re = re.compile(r'\b\S+\.?$', re.IGNORECASE)
expected = ["Street", "Avenue", "Boulevard", "Drive", "Court", "Place", "Square", "Lane", "Road",
"Trail", "Parkway", "Commons", "Cove", "Alley", "Park", "Way", "Walk" "Circle", "Highway",
"Plaza", "Path", "Center", "Mission"]
mapping = { "Ave": "Avenue",
"Ave.": "Avenue",
"avenue": "Avenue",
"ave": "Avenue",
"Blvd": "Boulevard",
"Blvd.": "Boulevard",
"Blvd,": "Boulevard",
"Boulavard": "Boulevard",
"Boulvard": "Boulevard",
"Ct": "Court",
"Dr": "Drive",
"Dr.": "Drive",
"E": "East",
"Hwy": "Highway",
"Ln": "Lane",
"Ln.": "Lane",
"Pl": "Place",
"Plz": "Plaza",
"Rd": "Road",
"Rd.": "Road",
"St": "Street",
"St.": "Street",
"st": "Street",
"street": "Street",
"square": "Square",
"parkway": "Parkway"
}
def audit_street_type(street_types, street_name):
m = street_type_re.search(street_name)
if m:
street_type = m.group()
if street_type not in expected:
street_types[street_type].add(street_name)
def street_name(elem):
return (elem.attrib['k'] == "addr:street")
def audit(osmfile):
osm_file = open(osmfile, "r")
street_types = collections.defaultdict(set)
for event, elem in ET.iterparse(osm_file, events=("start",)):
if elem.tag == "node" or elem.tag == "way":
for tag in elem.iter("tag"):
if street_name(tag):
audit_street_type(street_types, tag.attrib['v'])
osm_file.close()
return street_types
def update_name(name, mapping, regex):
m = regex.search(name)
if m:
st_type = m.group()
if st_type in mapping:
name = re.sub(regex, mapping[st_type], name)
return name