-
Notifications
You must be signed in to change notification settings - Fork 4
/
multi_point.go
86 lines (73 loc) · 1.95 KB
/
multi_point.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
package geo
import "database/sql/driver"
const (
mpWKTEmpty = `MULTIPOINT EMPTY`
mpWKTPrefix = `MULTIPOINT`
mpJSONPrefix = `{"type":"MultiPoint","coordinates":[`
mpJSONSuffix = `]}`
)
// MultiPoint is a collection of points.
type MultiPoint [][3]float64
// Equal compares one MultiPoint to another.
func (mp MultiPoint) Equal(g Geometry) bool {
other, ok := g.(*MultiPoint)
if !ok {
return false
}
return pointsEqual(mp, *other)
}
// Contains determines if the MultiPoint contains a point.
func (mp MultiPoint) Contains(p Point) bool {
return pointsContain(mp, p)
}
// MarshalJSON marshals the MultiPoint to JSON.
func (mp MultiPoint) MarshalJSON() ([]byte, error) {
return pointsMarshalJSON(mp, mpJSONPrefix, mpJSONSuffix), nil
}
// Scan scans a MultiPoint from Well Known Text.
func (mp *MultiPoint) Scan(src interface{}) error {
return scan(mp, src)
}
// scan scans a MultiPoint from a Well Known Text string.
func (mp *MultiPoint) scan(s string) error {
points, err := pointsScanPrefix(s, mpWKTPrefix, MultiPointType)
if err != nil {
return err
}
*mp = points
return nil
}
// String converts the MultiPoint to a string.
func (mp MultiPoint) String() string {
if len(mp) == 0 {
return mpWKTEmpty
}
return mpWKTPrefix + pointsString(mp)
}
// UnmarshalJSON unmarshals a MultiPoint from GeoJSON.
func (mp *MultiPoint) UnmarshalJSON(data []byte) error {
pts, err := pointsUnmarshal(data, MultiPointType)
if err != nil {
return err
}
*mp = pts
return nil
}
// Value returns a driver Value.
func (mp MultiPoint) Value() (driver.Value, error) {
return mp.String(), nil
}
// Transform transforms the geometry point by point.
func (mp *MultiPoint) Transform(t Transformer) {
nl := make([][3]float64, len(*mp))
for i, point := range *mp {
nl[i] = [3]float64(t.Transform(point))
}
*mp = nl
}
// VisitCoordinates visits each point in the geometry.
func (mp MultiPoint) VisitCoordinates(v Visitor) {
for _, point := range mp {
v.Visit(point)
}
}