This repository has been archived by the owner on Feb 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
128 lines (104 loc) · 2.58 KB
/
types.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package turfgo
const (
infinity = 0x7FF0000000000000
none = -1
)
//R is radius of earth
var R = map[string]float64{"mi": 3960,
"km": 6373,
"m": 6373000,
"d": 57.2957795,
"r": 1}
//Geometry is geoJson geometry
type Geometry interface {
getPoints() []*Point
}
//PolygonI is geoJson geometry
type PolygonI interface {
getPolygons() []*Polygon
}
//Point geojson type
type Point struct {
Lat float64
Lng float64
}
func (p *Point) getPoints() []*Point {
return []*Point{p}
}
//NewPoint creates a new point for given lat, lng
func NewPoint(lat float64, lon float64) *Point {
return &Point{lat, lon}
}
//MultiPoint geojson type
type MultiPoint struct {
Points []*Point
}
func (p *MultiPoint) getPoints() []*Point {
return p.Points
}
//NewMultiPoint creates a new multiPoint for given points
func NewMultiPoint(points []*Point) *MultiPoint {
return &MultiPoint{Points: points}
}
//LineString geojson type
type LineString struct {
Points []*Point
}
func (p *LineString) getPoints() []*Point {
return p.Points
}
//NewLineString creates a new lineString for given points
func NewLineString(points []*Point) *LineString {
return &LineString{Points: points}
}
//MultiLineString geojson type
type MultiLineString struct {
LineStrings []*LineString
}
func (p *MultiLineString) getPoints() []*Point {
points := []*Point{}
for _, lineString := range p.LineStrings {
points = append(points, lineString.getPoints()...)
}
return points
}
//NewMultiLineString creates a new multiLineString for given lineStrings
func NewMultiLineString(lineStrings []*LineString) *MultiLineString {
return &MultiLineString{LineStrings: lineStrings}
}
//Polygon geojson type
type Polygon struct {
LineStrings []*LineString
}
func (p *Polygon) getPoints() []*Point {
points := []*Point{}
for _, lineString := range p.LineStrings {
points = append(points, lineString.getPoints()...)
}
return points
}
func (p *Polygon) getPolygons() []*Polygon {
return []*Polygon{p}
}
//NewPolygon creates a new polygon for given lineStrings
func NewPolygon(lineStrings []*LineString) *Polygon {
return &Polygon{LineStrings: lineStrings}
}
//MultiPolygon geojson type
type MultiPolygon struct {
Polygons []*Polygon
}
func (p *MultiPolygon) getPoints() []*Point {
points := []*Point{}
for _, polygon := range p.Polygons {
points = append(points, polygon.getPoints()...)
}
return points
}
func (p *MultiPolygon) getPolygons() []*Polygon {
return p.Polygons
}
//NewMultiPolygon creates a new multiPolygon for given polygons
func NewMultiPolygon(polygons []*Polygon) *MultiPolygon {
return &MultiPolygon{Polygons: polygons}
}