Skip to content

Commit

Permalink
Update frequency-plans and test AU915
Browse files Browse the repository at this point in the history
timcooijmans committed Mar 20, 2023
1 parent 56a0e53 commit be414fb
Showing 14 changed files with 451 additions and 221 deletions.
37 changes: 37 additions & 0 deletions generator/geosjon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import json
import geojson
import h3.api.numpy_int as h3
import numpy as np

def fix_transmeridian(loop):
isTransmerdian = False
for i in range(len(loop)):
if loop[i][0]-loop[(i+1) % len(loop)][0] > 180.0:
isTransmerdian = True
break

if not isTransmerdian:
return loop

for i in range(len(loop)):
if loop[i][0] < 0.0:
loop[i] = (loop[i][0]+360.0, loop[i][1])
return loop

def fix_transmeridian_multipoly(multipoly):
for i in range(len(multipoly)):
for j in range(len(multipoly[i])):
multipoly[i][j] = fix_transmeridian(multipoly[i][j])

features = []
for plan in ["EU868", "AU915"]:
cells = np.fromfile(file=f"../go/frequency_plan/{plan}.h3", dtype=np.int64, sep="", count=-1, offset=0)
multipoly=h3.h3_set_to_multi_polygon(h3.uncompact(cells, 6), geo_json=True)
fix_transmeridian_multipoly(multipoly)
gmp = geojson.MultiPolygon(multipoly, validate=True)
feature = geojson.Feature(id=plan, geometry=gmp, properties={"Plan": plan})
features.append(feature)

fc = geojson.FeatureCollection(features)
f = open("plans.geojson", "w")
f.write(json.dumps(fc))
24 changes: 0 additions & 24 deletions generator/go.mod

This file was deleted.

56 changes: 0 additions & 56 deletions generator/go.sum

This file was deleted.

20 changes: 18 additions & 2 deletions generator/main.go
Original file line number Diff line number Diff line change
@@ -144,6 +144,20 @@ func writeH3IndexFiles(frequencyHex map[string][]h3.Cell) {
}
}

func writeH3GeojsonFiles(frequencyHex map[string][]h3.Cell) {
for frequencyPlan, index := range frequencyHex {
filename := fmt.Sprintf("../go/frequency_plan/%s.geojson", frequencyPlan)
f, err := os.Create(filename)
if err != nil {
logrus.WithError(err).Fatalf("could not open file: %s", filename)
}

geoj := h3tools.H3CellsToMultiPolygon(index)

f.Write([]byte(geoj.JSON()))
}
}

func generateH3Index() {
wp := workerpool.New(runtime.NumCPU())
logrus.Infof("running h3 index generator using %d workers", runtime.NumCPU())
@@ -196,8 +210,6 @@ func generateH3Index() {
}
}

logrus.Infof("compacting for %s", country)
cells = h3tools.DebupAndCompactCells(cells)
logrus.Infof("adding for %s", country)
frequencyHexMutex.Lock()
frequencyHex[plan] = append(frequencyHex[plan], cells...)
@@ -209,6 +221,10 @@ func generateH3Index() {
// Wait for all workers to complete
wp.StopWait()

for plan, _ := range frequencyHex {
frequencyHex[plan] = h3tools.DebupAndCompactCells(frequencyHex[plan])
}

writeH3IndexFiles(frequencyHex)

}
1 change: 1 addition & 0 deletions generator/plans.geojson

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@ require (

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gammazero/deque v0.2.0 // indirect
github.com/gammazero/workerpool v1.1.3 // indirect
github.com/jacobsa/crypto v0.0.0-20190317225127-9f44e2d11115 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -12,6 +12,10 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/gammazero/deque v0.2.0 h1:SkieyNB4bg2/uZZLxvya0Pq6diUlwx7m2TeT7GAIWaA=
github.com/gammazero/deque v0.2.0/go.mod h1:LFroj8x4cMYCukHJDbxFCkT+r9AndaJnFMuZDV34tuU=
github.com/gammazero/workerpool v1.1.3 h1:WixN4xzukFoN0XSeXF6puqEqFTl2mECI9S6W44HWy9Q=
github.com/gammazero/workerpool v1.1.3/go.mod h1:wPjyBLDbyKnUn2XwwyD3EEwo9dHutia9/fwNmSHWACc=
github.com/go-redis/redis/v8 v8.8.3/go.mod h1:ik7vb7+gm8Izylxu6kf6wG26/t2VljgCfSQ1DM4O1uU=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
Loading

0 comments on commit be414fb

Please sign in to comment.