forked from go-spatial/tegola
-
Notifications
You must be signed in to change notification settings - Fork 0
/
g.go
69 lines (59 loc) · 1.2 KB
/
g.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
package basic
import "fmt"
// G is used to pass back a generic Geometry type. It will contains functions to do basic conversions.
type G struct {
Geometry
}
func (g G) getbase() G {
rg := g
bg, ok := g.Geometry.(G)
for ok {
rg = bg
bg, ok = g.Geometry.(G)
}
return rg
}
func (g G) IsLine() bool {
_, ok := g.getbase().Geometry.(Line)
return ok
}
func (g G) AsLine() Line {
bg := g.getbase()
l, ok := bg.Geometry.(Line)
if !ok {
panic(fmt.Sprintf("Geo is not a Line! : %T", bg.Geometry))
}
return l
}
func (g G) IsPolygon() bool {
_, ok := g.getbase().Geometry.(Polygon)
return ok
}
func (g G) AsPolygon() Polygon {
bg := g.getbase()
p, ok := bg.Geometry.(Polygon)
if !ok {
panic(fmt.Sprintf("Geo is not a Polygon! : %T", bg.Geometry))
}
return p
}
func (g G) AsMultiPolygon() MultiPolygon {
bg := g.getbase()
p, ok := bg.Geometry.(MultiPolygon)
if !ok {
panic(fmt.Sprintf("Geo is not a MultiPolygon! : %T", bg.Geometry))
}
return p
}
func (g G) IsPoint() bool {
_, ok := g.getbase().Geometry.(Point)
return ok
}
func (g G) AsPoint() Point {
bg := g.getbase()
p, ok := bg.Geometry.(Point)
if !ok {
panic(fmt.Sprintf("Geo is not a Point! : %T", bg.Geometry))
}
return p
}