-
Notifications
You must be signed in to change notification settings - Fork 1
/
unit.go
78 lines (66 loc) · 1.59 KB
/
unit.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
package proj
/*
#cgo CFLAGS: -I. -I${SRCDIR}/usr/local/include
#cgo LDFLAGS: -L${SRCDIR}/usr/local/lib -lproj
#include "wrapper.h"
*/
import "C"
import "fmt"
// Unit contains data needed to define distance units
//
type Unit struct {
pj *C.PJ_UNITS
}
var (
units map[string]*Unit
)
// GetUnitByID returns an ellipsoid from its identifier
//
func GetUnitByID ( id string ) (u *Unit, e error) {
if u = units[id] ; u == nil {
e = fmt.Errorf("No Unit with that identifier '%s'", id)
}
return
}
// ID returns the keyword name of the unit.
//
func (u *Unit) ID () string {
return C.GoString((*u).pj.id)
}
// String returns a text representation of the factor that converts a given
// unit to meters.
//
func (u *Unit) String () string {
return C.GoString((*u).pj.to_meter)
}
// ToMeter returns the conversion factor that converts the unit to meters.
//
func (u *Unit) ToMeter () float64 {
return float64((*u).pj.factor)
}
// Name returns the name of the unit.
//
func (u *Unit) Name () string {
return C.GoString((*u).pj.name)
}
// Handle returns the PROJ internal object to be passed to the PROJ library
//
func (u *Unit) Handle () (interface{}) {
return (*u).pj
}
// HandleIsNil returns true when the PROJ internal object is NULL.
//
func (u *Unit) HandleIsNil () bool {
return (*u).pj == (*C.PJ_UNITS)(nil)
}
// init package initialisation
//
func init () {
lus := int(C.nbUnitsFromPROJ())
units = make(map[string]*Unit)
for i := 0 ; i < lus ; i++ {
u := &Unit{pj:nil}
(*u).pj = C.getUnitFromPROJ(C.int(i))
units[u.ID()] = u
}
}