-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnullPoint.go
More file actions
50 lines (40 loc) · 865 Bytes
/
nullPoint.go
File metadata and controls
50 lines (40 loc) · 865 Bytes
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
package datum
import (
"database/sql/driver"
"encoding/hex"
"github.com/twpayne/go-geom"
"github.com/twpayne/go-geom/encoding/ewkb"
"github.com/twpayne/go-geom/encoding/wkbcommon"
)
// NullPoint --
type NullPoint struct {
Point *geom.Point
}
// Scan scans from a []byte.
func (gc *NullPoint) Scan(src interface{}) error {
if src == nil {
return nil
}
s, ok := src.(string)
if !ok {
return ewkb.ErrExpectedByteSlice{Value: src}
}
b, err := hex.DecodeString(s)
if err != nil {
return ewkb.ErrExpectedByteSlice{Value: src}
}
got, err := ewkb.Unmarshal(b)
if err != nil {
return err
}
gc1, ok := got.(*geom.Point)
if !ok {
return wkbcommon.ErrUnexpectedType{Got: gc1, Want: gc}
}
gc.Point = gc1
return nil
}
// Value returns the WKB encoding of gc.
func (gc NullPoint) Value() (driver.Value, error) {
return value(gc.Point)
}