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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
package wkt
import (
"bytes"
"testing"
"github.com/paulmach/orb"
)
func TestMarshal(t *testing.T) {
cases := []struct {
name string
geo orb.Geometry
expected []byte
}{
{
name: "point",
geo: orb.Point{1, 2},
expected: []byte("POINT(1 2)"),
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
v := Marshal(tc.geo)
if !bytes.Equal(v, tc.expected) {
t.Log(string(v))
t.Log(string(tc.expected))
t.Errorf("incorrect wkt marshalling")
}
})
}
}
func TestMarshalString(t *testing.T) {
cases := []struct {
name string
geo orb.Geometry
expected string
}{
{
name: "point",
geo: orb.Point{1, 2},
expected: "POINT(1 2)",
},
{
name: "multipoint",
geo: orb.MultiPoint{{1, 2}, {0.5, 1.5}},
expected: "MULTIPOINT((1 2),(0.5 1.5))",
},
{
name: "multipoint empty",
geo: orb.MultiPoint{},
expected: "MULTIPOINT EMPTY",
},
{
name: "linestring",
geo: orb.LineString{{1, 2}, {0.5, 1.5}},
expected: "LINESTRING(1 2,0.5 1.5)",
},
{
name: "linestring empty",
geo: orb.LineString{},
expected: "LINESTRING EMPTY",
},
{
name: "multilinestring",
geo: orb.MultiLineString{{{1, 2}, {3, 4}}, {{5, 6}, {7, 8}}},
expected: "MULTILINESTRING((1 2,3 4),(5 6,7 8))",
},
{
name: "multilinestring empty",
geo: orb.MultiLineString{},
expected: "MULTILINESTRING EMPTY",
},
{
name: "ring",
geo: orb.Ring{{0, 0}, {1, 0}, {1, 1}, {0, 0}},
expected: "POLYGON((0 0,1 0,1 1,0 0))",
},
{
name: "polygon",
geo: orb.Polygon{{{1, 2}, {3, 4}}, {{5, 6}, {7, 8}}},
expected: "POLYGON((1 2,3 4),(5 6,7 8))",
},
{
name: "polygon empty",
geo: orb.Polygon{},
expected: "POLYGON EMPTY",
},
{
name: "multipolygon",
geo: orb.MultiPolygon{{{{1, 2}, {3, 4}}}, {{{5, 6}, {7, 8}}, {{1, 2}, {5, 4}}}},
expected: "MULTIPOLYGON(((1 2,3 4)),((5 6,7 8),(1 2,5 4)))",
},
{
name: "multipolygon empty",
geo: orb.MultiPolygon{},
expected: "MULTIPOLYGON EMPTY",
},
{
name: "collection",
geo: orb.Collection{orb.Point{1, 2}, orb.LineString{{3, 4}, {5, 6}}},
expected: "GEOMETRYCOLLECTION(POINT(1 2),LINESTRING(3 4,5 6))",
},
{
name: "collection empty",
geo: orb.Collection{},
expected: "GEOMETRYCOLLECTION EMPTY",
},
{
name: "bound",
geo: orb.Bound{Min: orb.Point{0, 0}, Max: orb.Point{1, 2}},
expected: "POLYGON((0 0,1 0,1 2,0 2,0 0))",
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
v := MarshalString(tc.geo)
if v != tc.expected {
t.Log(v)
t.Log(tc.expected)
t.Errorf("incorrect wkt marshalling")
}
})
}
}
|