-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddr_split.py
More file actions
executable file
·48 lines (39 loc) · 1.6 KB
/
Copy pathaddr_split.py
File metadata and controls
executable file
·48 lines (39 loc) · 1.6 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
#!/usr/bin/python3
import re
import copy
import csv
import sys
def main():
addr_input = sys.argv[1]
county = sys.argv[2]
split_county(addr_input, county)
def split_county(addr_input, county):
""" Makes a file of just the data from a single county. The format is the same
as that of the input file, with the exception that latitude and longitude are
added so that the data can be visualized in JOSM.
"""
out_file_name = county.lower().replace(' county','') + '_raw.csv'
with open(addr_input, newline='') as csvfile:
addr_reader = csv.DictReader(csvfile)
with open(out_file_name, 'w', newline='') as csvfile_out:
field_names = copy.deepcopy(addr_reader.fieldnames)
field_names.append('latitude')
field_names.append('longitude')
writer = csv.DictWriter(csvfile_out, fieldnames=field_names)
writer.writeheader()
county = county.upper()
for row in addr_reader:
# Unlike the rest of the file, it seems that the 'MUNICIPALITY' field's
# contents are in title case, but we don't take any chances and force
# an uppercase comparison.
if row['MUNICIPALITY'].upper() == county:
new_row = {}
for key, value in row.items():
new_row[key] = value
new_row['latitude'] = row['LAT']
new_row['longitude'] = row['LONG']
writer.writerow(new_row)
if __name__ == '__main__':
#summarize()
#split_county()
main()