-
-
Save iandees/d2ee3b56987333ca2f09 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
dir_map = { | |
"W": "West", | |
"N": "North", | |
"E": "East", | |
"S": "South", | |
"SW": "Southwest", | |
} | |
type_map = { | |
"Blvd": "Boulevard", | |
"Ave": "Avenue", | |
"St": "Street", | |
"Ct": "Court", | |
"Dr": "Drive", | |
"Ln": "Lane", | |
"Way": "Way", | |
"Rd": "Road", | |
"Pl": "Place", | |
"Cir": "Circle", | |
"Hwy": "Highway", | |
"Aly": "Alley", | |
"Pkwy": "Parkway", | |
} | |
def filterTags(attrs): | |
# AddressID (String) = 1 | |
# AddressLab (String) = 5017 W Northwest Blvd | |
# Zipcode (Integer) = 99205 | |
# AddressAng (Real) = 113.73330708 | |
# AddressTyp (Integer) = 1 | |
# FeatureTyp (Integer) = 3 | |
parts = attrs.get('AddressLab', '').split(' ') | |
cleaned = [] | |
house_num = parts.pop(0) | |
if not house_num.isdigit(): | |
print "Addr %s has non-digit address label: %s (%s)" % (attrs['AddressID'], house_num, attrs['AddressLab']) | |
return None | |
addr_dir = parts.pop(0) | |
if addr_dir not in dir_map: | |
print "Addr %s has unknown address dir: %s (%s)" % (attrs['AddressID'], addr_dir, attrs['AddressLab']) | |
return None | |
else: | |
addr_dir = dir_map[addr_dir] | |
cleaned.append(addr_dir) | |
addr_type = parts.pop(-1) | |
if addr_type not in type_map: | |
print "Addr %s has unknown street type: %s (%s)" % (attrs['AddressID'], addr_type, attrs['AddressLab']) | |
return None | |
else: | |
addr_type = type_map[addr_type] | |
street_name = ' '.join(parts) | |
cleaned.append(street_name) | |
cleaned.append(addr_type) | |
return {'addr:housenumber': house_num, | |
'addr:street:name': street_name, | |
'addr:street:type': addr_type, | |
'addr:street': ' '.join(cleaned), | |
'addr:postcode': attrs.get('Zipcode')} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment