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
|
s = box.schema.space.create('spatial')
---
...
_ = s:create_index('primary')
---
...
_ = s:create_index('spatial', { type = 'rtree', unique = false, parts = {2, 'array'}})
---
...
s:insert{1,{0,0,10,10}{
---
- error: '[string "s:insert{1,{0,0,10,10}{ "]:1: ''}'' expected near ''{'''
...
s:insert{2,{5,5,10,10}}
---
- [2, [5, 5, 10, 10]]
...
s:insert{3,{0,0,5,5}}
---
- [3, [0, 0, 5, 5]]
...
-- select all records
s.index.spatial:select({}, {iterator = 'ALL'})
---
- - [2, [5, 5, 10, 10]]
- [3, [0, 0, 5, 5]]
...
-- select records belonging to rectangle (0,0,5,5)
s.index.spatial:select({0,0,5,5}, {iterator = 'LE'})
---
- - [3, [0, 0, 5, 5]]
...
-- select records strict belonging to rectangle (0,0,5,5)
s.index.spatial:select({0,0,5,5}, {iterator = 'LT'})
---
- []
...
-- select records strict belonging to rectangle (4,4,11,11)
s.index.spatial:select({4,4,11,11}, {iterator = 'LT'})
---
- - [2, [5, 5, 10, 10]]
...
-- select records containing point (5,5)
s.index.spatial:select({5,5}, {iterator = 'GE'})
---
- - [2, [5, 5, 10, 10]]
- [3, [0, 0, 5, 5]]
...
-- select records containing rectangle (1,1,2,2)
s.index.spatial:select({1,1,2,2}, {iterator = 'GE'})
---
- - [3, [0, 0, 5, 5]]
...
-- select records strict containing rectangle (0,0,5,5)
s.index.spatial:select({0,0,5,5}, {iterator = 'GT'})
---
- []
...
-- select records overlapping rectangle (9,4,11,6)
s.index.spatial:select({9,4,11,6}, {iterator = 'OVERLAPS'})
---
- - [2, [5, 5, 10, 10]]
...
-- select records with coordinates (0,0,5,5)
s.index.spatial:select({0,0,5,5}, {iterator = 'EQ'})
---
- - [3, [0, 0, 5, 5]]
...
-- select neighbors of point (1,1)
s.index.spatial:select({1,1}, {iterator = 'NEIGHBOR'})
---
- - [3, [0, 0, 5, 5]]
- [2, [5, 5, 10, 10]]
...
s:drop()
---
...
|