forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspatial_options_factory.go
110 lines (96 loc) · 3.72 KB
/
spatial_options_factory.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
package ravendb
// NewGeographyDefaultOptions returns default geography SpatialOptions
func NewGeographyDefaultOptions() *SpatialOptions {
return NewGeographyDefaultOptionsWithRadius(SpatialUnitsKilometers)
}
// NewGeographyDefaultOptionsWithRadius returns default geography SpatialOptions
// with a a given radius
func NewGeographyDefaultOptionsWithRadius(circleRadiusUnits SpatialUnits) *SpatialOptions {
return NewGeographyGeohashPrefixTreeIndexWithRadius(0, circleRadiusUnits)
}
// NewGeograpyboundingBoxIndex returns geography SpatialOptions for a bounding box
func NewGeograpyboundingBoxIndex() *SpatialOptions {
return NewGeographyBoundingBoxIndexWithRadius(SpatialUnitsKilometers)
}
// NewGeographyBoundingBoxIndexWithRadius return geography SpatialOptions
// for a bounding box with a given radius
func NewGeographyBoundingBoxIndexWithRadius(circleRadiusUnits SpatialUnits) *SpatialOptions {
opts := NewSpatialOptions()
opts.Type = SpatialFieldGeography
opts.Strategy = SpatialSearchStrategyBoundingBox
opts.Units = circleRadiusUnits
return opts
}
// NewGeographyGeohashPrefixTreeIndex returns geography SpatialOptions for
// using geography geohash prefix tree index
func NewGeographyGeohashPrefixTreeIndex(maxTreeLevel int) *SpatialOptions {
return NewGeographyGeohashPrefixTreeIndexWithRadius(maxTreeLevel, SpatialUnitsKilometers)
}
// NewGeographyGeohashPrefixTreeIndexWithRadius returns geography SpatialOptions for
//// using geography geohash prefix tree index with a given circle radius
func NewGeographyGeohashPrefixTreeIndexWithRadius(maxTreeLevel int, circleRadiusUnits SpatialUnits) *SpatialOptions {
if maxTreeLevel == 0 {
maxTreeLevel = SpatialOptionsDefaultGeohashLevel
}
opts := NewSpatialOptions()
opts.Type = SpatialFieldGeography
opts.MaxTreeLevel = maxTreeLevel
opts.Strategy = SpatialSearchStrategyGeohashPrefixTree
opts.Units = circleRadiusUnits
return opts
}
// NewGeographyQuadPrefixTreeIndex returns geography SpatialOptions
// for quad prefix tree
func NewGeographyQuadPrefixTreeIndex(maxTreeLevel int) *SpatialOptions {
return NewGeographyQuadPrefixTreeIndexWithRadius(maxTreeLevel, SpatialUnitsKilometers)
}
// NewGeographyQuadPrefixTreeIndex returns geography SpatialOptions
// for quad prefix tree with a given radius
func NewGeographyQuadPrefixTreeIndexWithRadius(maxTreeLevel int, circleRadiusUnits SpatialUnits) *SpatialOptions {
if maxTreeLevel == 0 {
maxTreeLevel = SpatialOptionsDefaultQuadTreeLevel
}
opts := NewSpatialOptions()
opts.Type = SpatialFieldGeography
opts.MaxTreeLevel = maxTreeLevel
opts.Strategy = SpatialSearchStrategyQuadPrefixTree
opts.Units = circleRadiusUnits
return opts
}
// NewCartesianBoundingBoxIndex returns cartesian SpatialOptions
func NewCartesianBoundingBoxIndex() *SpatialOptions {
opts := NewSpatialOptions()
opts.Type = SpatialFieldCartesian
opts.Strategy = SpatialSearchStrategyBoundingBox
return opts
}
// NewCartesianQuadPrefixTreeIndex returns cartesian SpatialOptions for
// quad prefix tree index
func NewCartesianQuadPrefixTreeIndex(maxTreeLevel int, bounds *SpatialBounds) *SpatialOptions {
panicIf(maxTreeLevel <= 0, "maxTreeLevel must be > 0")
opts := NewSpatialOptions()
opts.Type = SpatialFieldCartesian
opts.MaxTreeLevel = maxTreeLevel
opts.Strategy = SpatialSearchStrategyQuadPrefixTree
opts.MinX = bounds.MinX
opts.MinY = bounds.MinY
opts.MaxX = bounds.MaxX
opts.MaxY = bounds.MaxY
return opts
}
// SpatialBounds describes bounds of a region
type SpatialBounds struct {
MinX float64
MaxX float64
MinY float64
MaxY float64
}
// NewSpatialBounds returns new SpatialBounds
func NewSpatialBounds(minX float64, minY float64, maxX float64, maxY float64) *SpatialBounds {
return &SpatialBounds{
MinX: minX,
MaxX: maxX,
MinY: minY,
MaxY: maxY,
}
}