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
|
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}}
---
- [1, [0, 0]]
...
s:insert{2,{0,10}}
---
- [2, [0, 10]]
...
s:insert{3,{0,50}}
---
- [3, [0, 50]]
...
s:insert{4,{10,0}}
---
- [4, [10, 0]]
...
s:insert{5,{50,0}}
---
- [5, [50, 0]]
...
s:insert{6,{10,10}}
---
- [6, [10, 10]]
...
s:insert{7,{10,50}}
---
- [7, [10, 50]]
...
s:insert{8,{50,10}}
---
- [8, [50, 10]]
...
s:insert{9,{50,50}}
---
- [9, [50, 50]]
...
-- select all records
s.index.spatial:select({}, {iterator = 'ALL'})
---
- - [1, [0, 0]]
- [2, [0, 10]]
- [3, [0, 50]]
- [4, [10, 0]]
- [5, [50, 0]]
- [6, [10, 10]]
- [7, [10, 50]]
- [8, [50, 10]]
- [9, [50, 50]]
...
-- select records belonging to rectangle (0,0,10,10)
s.index.spatial:select({0,0,10,10}, {iterator = 'LE'})
---
- - [1, [0, 0]]
- [2, [0, 10]]
- [4, [10, 0]]
- [6, [10, 10]]
...
-- select records with coordinates (10,10)
s.index.spatial:select({10,10}, {iterator = 'EQ'})
---
- - [6, [10, 10]]
...
-- select neighbors of point (5,5)
s.index.spatial:select({5,5}, {iterator = 'NEIGHBOR'})
---
- - [1, [0, 0]]
- [2, [0, 10]]
- [4, [10, 0]]
- [6, [10, 10]]
- [3, [0, 50]]
- [5, [50, 0]]
- [7, [10, 50]]
- [8, [50, 10]]
- [9, [50, 50]]
...
s:drop()
---
...
|