-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnbi-data-analysis-nmn.py
60 lines (43 loc) · 1.49 KB
/
nbi-data-analysis-nmn.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
import csv
from util import nbiparser, nominatim
from datetime import datetime
from tqdm import tqdm
from osm_handlers import OSMNBIAnalyzer
from dotenv import load_dotenv
import os
load_dotenv()
NMN_ENDPOINT = os.environ.get('NMN_ENDPOINT')
# Prep Nominatim API
nom = nominatim(NMN_ENDPOINT)
# We will write to a tags<TIME>.osm file
time = str(datetime.timestamp(datetime.now()))
# parse nbi data
nbi_file = "in/NE_NBI_FULL.csv"
c1 = nbiparser(nbi_file)
nbi_dat = c1.modified_data()
ways = {}
count = 0
print("Reverse-geocoding NBI data using Nominatim...")
for bridge in tqdm(nbi_dat):
bridge.update({"osm-match":"False"})
bridge.update({"osm-match-id": "None"})
response = nom.request({'format':'jsonv2',
'lat':bridge['lat'],
'lon':bridge['lon'],},
'reverse')
# print(response['osm_type'], response['osm_id'])
ways.update({str(response['osm_id']): bridge})
# Create the PBF Handler and apply the desired OSM data for tag editing.
file_writer = OSMNBIAnalyzer(ways, nbi_dat[0].keys())
print("Writing NBI tags to OSM...")
file_writer.apply_file("in/nebraska-latest.osm.pbf")
# writing to csv file
with open("out/NBI-Analysis-nmn.csv", 'w', newline='') as csvfile:
# creating a csv writer object
csvwriter = csv.writer(csvfile)
# writing the fields
csvwriter.writerow(nbi_dat[0].keys())
for bridge in nbi_dat:
# writing the data rows
csvwriter.writerow(list(bridge.values()))
print("Done!")