-
Notifications
You must be signed in to change notification settings - Fork 4
/
tiger_address_convert.py
executable file
·55 lines (44 loc) · 1.49 KB
/
tiger_address_convert.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
#!/usr/bin/python3
"""
Tiger road data to OSM conversion script
Creates Karlsruhe-style address ways beside the main way
based on the Massachusetts GIS script by christopher schmidt
BUGS:
- On very tight curves, a loop may be generated in the address way.
- It would be nice if the ends of the address ways were not pulled back from dead ends
"""
import sys
import csv
from lib.parse import parse_shp_for_geom_and_tags
from lib.convert import addressways, compile_nodelist, compile_waylist
def shape_to_csv(shp_filename, csv_filename):
"""
Main feature: reads a file, writes a file
"""
print("parsing shpfile %s" % shp_filename)
parsed_features = parse_shp_for_geom_and_tags(shp_filename)
print("compiling nodelist")
i, nodelist = compile_nodelist(parsed_features)
print("compiling waylist")
waylist = compile_waylist(parsed_features)
print("preparing address ways")
csv_lines = addressways(waylist, nodelist, i)
print("writing %s" % csv_filename)
fieldnames = [
'from',
'to',
'interpolation',
'street',
'city',
'state',
'postcode',
'geometry'
]
with open(csv_filename, 'w', encoding="utf8") as csv_file:
csv_writer = csv.DictWriter(csv_file, delimiter=';', fieldnames=fieldnames)
csv_writer.writeheader()
csv_writer.writerows(csv_lines)
if len(sys.argv) < 3:
print("%s input.shp output.csv" % sys.argv[0])
sys.exit()
shape_to_csv(sys.argv[1], sys.argv[2])