forked from electrious-go/cluster
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhelpers_test.go
More file actions
82 lines (72 loc) · 1.48 KB
/
Copy pathhelpers_test.go
File metadata and controls
82 lines (72 loc) · 1.48 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package cluster
import (
"encoding/json"
"fmt"
"io/ioutil"
)
////Helpers
type simplePoint struct {
Lon, Lat float64
}
func (sp simplePoint) GetCoordinates() GeoCoordinates {
return GeoCoordinates{sp.Lon, sp.Lat}
}
type TestPoint struct {
Type string
Properties struct {
//we don't need other data
Name string
PointCount int `json:"point_count"`
}
Geometry struct {
Coordinates []float64
}
}
type GeoJSONResultFeature struct {
Geometry [][]float64
Tags struct {
PointCount int `json:"point_count"`
}
}
func (tp *TestPoint) GetCoordinates() GeoCoordinates {
return GeoCoordinates{
Lng: tp.Geometry.Coordinates[0],
Lat: tp.Geometry.Coordinates[1],
}
}
func importData(filename string) []*TestPoint {
var points = struct {
Type string
Features []*TestPoint
}{}
raw, err := ioutil.ReadFile(filename)
if err != nil {
fmt.Println(err.Error())
return nil
}
json.Unmarshal(raw, &points)
//fmt.Printf("Get data: %+v\n",points)
return points.Features
}
func importPoints(filename string) []Point {
var result []Point
raw, err := ioutil.ReadFile(filename)
if err != nil {
fmt.Println(err.Error())
return nil
}
json.Unmarshal(raw, &result)
return result
}
func importGeoJSONResultFeature(filename string) []GeoJSONResultFeature {
var points = struct {
Features []GeoJSONResultFeature
}{}
raw, err := ioutil.ReadFile(filename)
if err != nil {
fmt.Println(err.Error())
return nil
}
json.Unmarshal(raw, &points)
return points.Features
}