geo_shape_test.rb
3.14 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
require "pp"
require_relative "test_helper"
class GeoShapeTest < Minitest::Test
def test_geo_shape
regions = [
{name: "Region A", text: "The witch had a cat", territory: "30,40,35,45,40,40,40,30,30,30,30,40"},
{name: "Region B", text: "and a very tall hat", territory: "50,60,55,65,60,60,60,50,50,50,50,60"},
{name: "Region C", text: "and long ginger hair which she wore in a plait.", territory: "10,20,15,25,20,20,20,10,10,10,10,20"},
]
store regions, Region
# circle
assert_search "*", ["Region A"], {
where: {
territory: {
geo_shape: {
type: "circle",
coordinates: {lat: 28.0, lon: 38.0},
radius: "444000m"
}
}
}
}, Region
# envelope
assert_search "*", ["Region A"], {
where: {
territory: {
geo_shape: {
type: "envelope",
coordinates: [[28, 42], [32, 38]]
}
}
}
}, Region
# envelope as corners
assert_search "*", ["Region A"], {
where: {
territory: {
geo_shape: {
type: "envelope",
top_left: {lat: 42.0, lon: 28.0},
bottom_right: {lat: 38.0, lon: 32.0}
}
}
}
}, Region
# polygon
assert_search "*", ["Region A"], {
where: {
territory: {
geo_shape: {
type: "polygon",
coordinates: [[[38, 42], [42, 42], [42, 38], [38, 38], [38, 42]]]
}
}
}
}, Region
# multipolygon
assert_search "*", ["Region A", "Region B"], {
where: {
territory: {
geo_shape: {
type: "multipolygon",
coordinates: [
[[[38, 42], [42, 42], [42, 38], [38, 38], [38, 42]]],
[[[58, 62], [62, 62], [62, 58], [58, 58], [58, 62]]]
]
}
}
}
}, Region
# disjoint
assert_search "*", ["Region B", "Region C"], {
where: {
territory: {
geo_shape: {
type: "envelope",
relation: "disjoint",
coordinates: [[28, 42], [32, 38]]
}
}
}
}, Region
# within
assert_search "*", ["Region A"], {
where: {
territory: {
geo_shape: {
type: "envelope",
relation: "within",
coordinates: [[20, 50], [50, 20]]
}
}
}
}, Region
# contains
assert_search "*", ["Region A"], {
where: {
territory: {
geo_shape: {
type: "envelope",
relation: "contains",
coordinates: [[32, 33], [33, 32]]
}
}
}
}, Region
# with search
assert_search "witch", ["Region A"], {
where: {
territory: {
geo_shape: {
type: "envelope",
coordinates: [[28, 42], [32, 38]]
}
}
}
}, Region
assert_search "ginger hair", [], {
where: {
territory: {
geo_shape: {
type: "envelope",
coordinates: [[28, 42], [32, 38]]
}
}
}
}, Region
end
end