Skip to content

Instantly share code, notes, and snippets.

@markmarkoh
Last active July 19, 2020 20:31

Revisions

  1. markmarkoh revised this gist Jul 19, 2020. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions sample.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    [
    {
    "hex": "87416e865ffffff",
    "count": 862
    },
    {
    "hex": "87414880bffffff",
    "count": 866
    },
    {
    ...]
  2. markmarkoh revised this gist Jul 19, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion make_h3.py
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    import csv
    import json

    with open('./data.csv', newline='') as csvfile:
    with open('./thor_filtered.csv', newline='') as csvfile:
    line = csv.reader(csvfile, delimiter=',')
    lines = 0
    results = {}
  3. markmarkoh created this gist Jul 19, 2020.
    31 changes: 31 additions & 0 deletions make_h3.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    import h3
    import csv
    import json

    with open('./data.csv', newline='') as csvfile:
    line = csv.reader(csvfile, delimiter=',')
    lines = 0
    results = {}
    for row in line:
    lines += 1
    if (lines == 1):
    continue
    lat, lng = float(row[8]), float(row[9])
    hexval = h3.geo_to_h3(lat, lng, 7)
    if hexval in results:
    results[hexval] += 1
    else:
    results[hexval] = 1
    hexarr = []
    for val in results:
    # skip the 1 off in this dataset, looks to be air combat?
    count = results[val]
    if count == 1 or count > 7000:
    continue
    obj = {}
    obj['hex'] = val
    obj['count'] = count
    hexarr.append(obj)

    print(json.dumps(hexarr, indent=2))