-
Notifications
You must be signed in to change notification settings - Fork 16
/
simon_bartlett_test.go
140 lines (108 loc) · 3.37 KB
/
simon_bartlett_test.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
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
package tests
import (
"testing"
ravendb "github.com/ravendb/ravendb-go-client"
"github.com/stretchr/testify/assert"
)
func simonBartlettLineStringsShouldIntersect(t *testing.T, driver *RavenTestDriver) {
var err error
store := driver.getDocumentStoreMust(t)
defer store.Close()
index := NewGeoIndex()
err = store.ExecuteIndex(index, "")
assert.NoError(t, err)
{
session := openSessionMust(t, store)
geoDocument := &GeoDocument{
Wkt: "LINESTRING (0 0, 1 1, 2 1)",
}
err = session.Store(geoDocument)
assert.NoError(t, err)
err = session.SaveChanges()
assert.NoError(t, err)
session.Close()
}
err = driver.waitForIndexing(store, "", 0)
assert.NoError(t, err)
{
session := openSessionMust(t, store)
q := session.QueryIndex(index.IndexName)
fn := func(f *ravendb.SpatialCriteriaFactory) ravendb.SpatialCriteria {
return f.RelatesToShape("LINESTRING (1 0, 1 1, 1 2)", ravendb.SpatialRelationIntersects)
}
q = q.Spatial3("WKT", fn)
q = q.WaitForNonStaleResults(0)
count, err := q.Count()
assert.NoError(t, err)
assert.Equal(t, count, 1)
q = session.QueryIndex(index.IndexName)
q = q.RelatesToShape("WKT", "LINESTRING (1 0, 1 1, 1 2)", ravendb.SpatialRelationIntersects)
q = q.WaitForNonStaleResults(0)
count, err = q.Count()
assert.NoError(t, err)
assert.Equal(t, count, 1)
session.Close()
}
}
func simonBartlettCirclesShouldNotIntersect(t *testing.T, driver *RavenTestDriver) {
var err error
store := driver.getDocumentStoreMust(t)
defer store.Close()
index := NewGeoIndex()
err = store.ExecuteIndex(index, "")
assert.NoError(t, err)
{
session := openSessionMust(t, store)
// 110km is approximately 1 degree
geoDocument := &GeoDocument{
Wkt: "CIRCLE(0.000000 0.000000 d=110)",
}
err = session.Store(geoDocument)
assert.NoError(t, err)
err = session.SaveChanges()
assert.NoError(t, err)
session.Close()
}
driver.waitForIndexing(store, "", 0)
{
session := openSessionMust(t, store)
// Should not intersect, as there is 1 Degree between the two shapes
q := session.QueryIndex(index.IndexName)
fn := func(f *ravendb.SpatialCriteriaFactory) ravendb.SpatialCriteria {
return f.RelatesToShape("CIRCLE(0.000000 3.000000 d=110)", ravendb.SpatialRelationIntersects)
}
q = q.Spatial3("WKT", fn)
q = q.WaitForNonStaleResults(0)
count, err := q.Count()
assert.NoError(t, err)
assert.Equal(t, count, 0)
q = session.QueryIndex(index.IndexName)
q = q.RelatesToShape("WKT", "CIRCLE(0.000000 3.000000 d=110)", ravendb.SpatialRelationIntersects)
q = q.WaitForNonStaleResults(0)
count, err = q.Count()
assert.NoError(t, err)
assert.Equal(t, count, 0)
session.Close()
}
}
type GeoDocument struct {
Wkt string `json:"WKT"`
}
func NewGeoIndex() *ravendb.IndexCreationTask {
res := ravendb.NewIndexCreationTask("GeoIndex")
res.Map = "docs.GeoDocuments.Select(doc => new {\n" +
" WKT = this.CreateSpatialField(doc.WKT)\n" +
"})"
spatialOptions := ravendb.NewSpatialOptions()
spatialOptions.Strategy = ravendb.SpatialSearchStrategyGeohashPrefixTree
res.SpatialOptionsStrings["WKT"] = spatialOptions
return res
}
func TestSimonBartlett(t *testing.T) {
driver := createTestDriver(t)
destroy := func() { destroyDriver(t, driver) }
defer recoverTest(t, destroy)
// matches the order of Java tests
simonBartlettCirclesShouldNotIntersect(t, driver)
simonBartlettLineStringsShouldIntersect(t, driver)
}