Group points in output with geohash.

pull/226/head
Christopher Young 2015-12-15 11:37:16 -05:00
rodzic 936b148026
commit ec4c652758
1 zmienionych plików z 20 dodań i 3 usunięć

Wyświetl plik

@ -6,6 +6,7 @@ import (
"encoding/json" "encoding/json"
"flag" "flag"
"fmt" "fmt"
"github.com/gansidui/geohash"
"os" "os"
"strconv" "strconv"
"strings" "strings"
@ -24,7 +25,7 @@ type UATFrame struct {
// For AIRMET/NOTAM. // For AIRMET/NOTAM.
//FIXME: Temporary. //FIXME: Temporary.
Points []uatparse.GeoPoint Points map[string][]uatparse.GeoPoint
ReportNumber uint16 ReportNumber uint16
ReportYear uint16 ReportYear uint16
LocationIdentifier string LocationIdentifier string
@ -35,6 +36,22 @@ type UATFrame struct {
var reports map[string]UATFrame var reports map[string]UATFrame
func groupPoints(f *uatparse.UATFrame) map[string][]uatparse.GeoPoint {
// Index all of the points by GeoHash. Group points together.
res := make(map[string][]uatparse.GeoPoint)
precision := 5 // 6 maybe, 0.000687.
for _, p := range f.Points {
hash, _ := geohash.Encode(p.Lat, p.Lon, precision)
if r, ok := res[hash]; ok {
r = append(r, p)
res[hash] = r
} else {
res[hash] = []uatparse.GeoPoint{p}
}
}
return res
}
func updateReport(f *uatparse.UATFrame) { func updateReport(f *uatparse.UATFrame) {
if f.ReportNumber == 0 || f.ReportYear == 0 || f.RecordFormat == 0 { if f.ReportNumber == 0 || f.ReportYear == 0 || f.RecordFormat == 0 {
return return
@ -46,7 +63,7 @@ func updateReport(f *uatparse.UATFrame) {
} }
if p, ok := reports[s]; ok { if p, ok := reports[s]; ok {
if len(f.Points) > 0 { if len(f.Points) > 0 {
p.Points = f.Points p.Points = groupPoints(f)
reports[s] = p reports[s] = p
} }
if len(f.Text_data) > 0 { if len(f.Text_data) > 0 {
@ -61,7 +78,7 @@ func updateReport(f *uatparse.UATFrame) {
z.FISB_minutes = f.FISB_minutes z.FISB_minutes = f.FISB_minutes
z.FISB_seconds = f.FISB_seconds z.FISB_seconds = f.FISB_seconds
z.Product_id = f.Product_id z.Product_id = f.Product_id
z.Points = f.Points z.Points = groupPoints(f)
z.ReportNumber = f.ReportNumber z.ReportNumber = f.ReportNumber
z.ReportYear = f.ReportYear z.ReportYear = f.ReportYear
z.LocationIdentifier = f.LocationIdentifier z.LocationIdentifier = f.LocationIdentifier