-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun.py
More file actions
26 lines (21 loc) · 723 Bytes
/
run.py
File metadata and controls
26 lines (21 loc) · 723 Bytes
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
import csv
import io
import h3
import requests
res = requests.get("https://www.chattadata.org/api/views/nvdi-c4tt/rows.csv")
with io.StringIO(res.text) as f:
reader = csv.DictReader(f)
columns = reader.fieldnames
rows = list(reader)
# add cell_id to rows
for row in rows:
if row['Latitude'] and row['Longitude']:
latitude = float(row['Latitude'])
longitude = float(row['Longitude'])
resolution = 8
row['h3_cell_id'] = h3.latlng_to_cell(latitude, longitude, resolution)
with open("data.csv", "w", newline="") as f:
new_fieldnames = columns + ['h3_cell_id']
writer = csv.DictWriter(f, fieldnames=new_fieldnames)
writer.writeheader()
writer.writerows(rows)