-
Notifications
You must be signed in to change notification settings - Fork 0
/
gis.go
44 lines (32 loc) · 771 Bytes
/
gis.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
package main
import (
"encoding/json"
"github.com/paulmach/orb"
"github.com/paulmach/orb/encoding/wkb"
)
// PointLocation extends orb.Point, representing
// a single point
type PointLocation struct {
orb.Point
}
// MarshalJSON represents PointLocation (orb.Point) as JSON
func (v PointLocation) MarshalJSON() ([]byte, error) {
return json.Marshal([]float64{v.Lon(), v.Lat()})
}
// Scan allows scanning of PostGIS binary locations
func (v *PointLocation) Scan(src interface{}) error {
if src == nil {
emptyPoint := orb.Point{}
*v = PointLocation{emptyPoint}
return nil
}
var err error
source := src.([]byte)
geom, err := wkb.Unmarshal(source)
if err != nil {
return err
}
point := geom.(orb.Point)
*v = PointLocation{point}
return nil
}