-
Notifications
You must be signed in to change notification settings - Fork 4
/
geojson.go
executable file
·71 lines (64 loc) · 2.01 KB
/
geojson.go
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
package main
import (
"encoding/json"
"io/ioutil"
)
type GeoJSONPoints struct {
Type string `json:"type"`
Features []GeoJSONPointsFeature `json:"features"`
}
type GeoJSONPointsFeature struct {
Type string `json:"type"`
Properties struct {
MarkerColor string `json:"marker-color"`
MarkerSize string `json:"marker-size"`
MarkerSymbol string `json:"marker-symbol"`
Desc string `json:"desc"`
URL string `json:"url"`
Title string `json:"title"`
Address string `json:"address"`
Fulltitle string `json:"fulltitle"`
Rating string `json:"rating"`
ID string `json:"id"`
Distance string `json:"distance"`
DistanceFromLastCity string `json:"distance-from-last-city"`
CityThatIsClose string `json:"city-that-is-close"`
} `json:"properties"`
Geometry struct {
Type string `json:"type"`
Coordinates []float64 `json:"coordinates"` // Lon and Lat
} `json:"geometry"`
}
func (g GeoJSONPointsFeature) String() string {
b, _ := json.MarshalIndent(g, " ", " ")
return string(b)
}
func LoadGeoJSONFile(filename string) (g GeoJSONPoints, err error) {
var b []byte
b, err = ioutil.ReadFile(filename)
if err != nil {
return
}
err = json.Unmarshal(b, &g)
return
}
func GeoJSONLineStringFeature(points []Point) string {
type GeoJSONLineString struct {
Type string `json:"type"`
Properties struct {
} `json:"properties"`
Geometry struct {
Type string `json:"type"`
Coordinates [][]float64 `json:"coordinates"`
} `json:"geometry"`
}
var g GeoJSONLineString
g.Type = "Feature"
g.Geometry.Type = "LineString"
g.Geometry.Coordinates = make([][]float64, len(points))
for i, point := range points {
g.Geometry.Coordinates[i] = []float64{point.Longitude, point.Latitude}
}
b, _ := json.MarshalIndent(g, " ", " ")
return string(b)
}