SlideShare une entreprise Scribd logo
1  sur  97
Télécharger pour lire hors ligne
Spatial Indexing
Kristian Torp
Department of Computer Science
Aalborg University
people.cs.aau.dk/˜torp
torp@cs.aau.dk
November 19, 2015
daisy.aau.dk
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 1 / 54
Outline
1 Introduction
2 Space-filling Curves (SFC)
3 R-Tree
Minimum-Bounding Rectangle (MBR)
Range Search
4 Quadtrees
5 Summary
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 2 / 54
Learning Goals
The Problem
Existing indexes good for scalar values, e.g., 42 and ’Hello, World’
Existing indexes not good complex data, e.g., geometries and time
series
Quiz
Which index structures do you know?
Goals
Overview of spatial indexing techniques
Understand how spatial indexing different from “plain” indexing
Understand the basic spatial indexing techniques
Be able to construct a spatial index on PostgreSQL
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 3 / 54
Outline
1 Introduction
2 Space-filling Curves (SFC)
3 R-Tree
Minimum-Bounding Rectangle (MBR)
Range Search
4 Quadtrees
5 Summary
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 4 / 54
Spatial Query Types
c1
c2 c3 c4
c5
c6
c7
c1
c2 c3 c4
c5
c6
c7
Range Nearest Neighbor
c1
c2 c3 c4
c5
c6
c7
f1 f2
f3
f4c1
c2 c3 c4
c5
c6
c7
Within Spatial Join
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 5 / 54
Spatial Indexing
Purposes of Spatial Index Structure
Should speed-up the most typical spatial queries
Should not take up too much space
Should efficiently support modifications
Assumptions
Spatial query only covers small part of the “world”
Spatial data is queried more often then modified
Note
Indexing necessary to make queries run faster
Hashing does not work well for spatial data types
You can index spatial data using conventional (B+-tree) indexes
It is often slow!
Will see how can be used with space-filling curves
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 6 / 54
Overview of Spatial Indexing Techniques
Techniques
Space-filling curves (a set of approaches)
Old wine, recycled bottles
R-trees (a large family of index structures)
A generalization of the B+
-tree
Quadtrees (a family of index structures)
Old wine, new bottles
Other Domains
Image processing, e.g., medical and biometrics
Image recognition, e.g., letters and books
Gaming, e.g., for the terrain, buildings, and roads
Chip design, e.g., integrated circuits, think AMD, ARM, and Intel
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 7 / 54
Create Spatial Index
Example (Table with Spatial Data Column)
create table landscape (
geo name varchar (20) primary key ,
geo geometry not n u l l
) ;
Example (Create B+
-tree Index on PostgreSQL)
create index landscape geo name
on landscape ( geo name ) ;
Example (Create R-tree Index on PostgreSQL)
create index landscape geo
on landscape using g i s t ( geo ) ;
Note
GIST = Generalized Search Trees = R-tree = spatial index
From SQL interface not a big think!
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 8 / 54
Outline
1 Introduction
2 Space-filling Curves (SFC)
3 R-Tree
Minimum-Bounding Rectangle (MBR)
Range Search
4 Quadtrees
5 Summary
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 9 / 54
The Basic Idea: SFC
Example (Division of World)
0 1 2 3 4
0
1
2
3
4
The Basic Idea: SFC
Example (Division of World)
0 1 2 3 4
0
1
2
3
4
0 1
23
4
5 6
7 8
9 10
11
1213
14 15
The Basic Idea: SFC
Example (Division of World)
0 1 2 3 4
0
1
2
3
4
0 1
23
4
5 6
7 8
9 10
11
1213
14 15
The Basic Idea: SFC
Example (Division of World)
0 1 2 3 4
0
1
2
3
4
0 1
23
4
5 6
7 8
9 10
11
1213
14 15
a
The Basic Idea: SFC
Example (Division of World)
0 1 2 3 4
0
1
2
3
4
0 1
23
4
5 6
7 8
9 10
11
1213
14 15
a
b
The Basic Idea: SFC
Example (Division of World)
0 1 2 3 4
0
1
2
3
4
0 1
23
4
5 6
7 8
9 10
11
1213
14 15
a
b
c
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 10 / 54
SFC for Indexing Spatial Objects
Example (Space-filling Curve)
0 1 2 3 4
0
1
2
3
4
0 1
23
4
5 6
7 8
9 10
11
1213
14 15
a
b
c
ObjectName Idx Coor
a 10 (3.7, 3.7)
b 7 (1.2, 2.7)
c 1 (ref)
c 2 (ref)
c 13 (ref)
c 14 (ref)
Variations
This is a Hilbert space-filling curve
Index and spatial data typically split in two tables
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 11 / 54
Spatial Query using SFC
Example (Space-filling Curve)
0 1 2 3 4
0
1
2
3
4
0 1
23
4
5 6
7 8
9 10
11
1213
14 15
a
b
c
ObjectName Idx Coor
a 10 (3.7, 3.7)
b 7 (1.2, 2.7)
c 1 (ref)
c 2 (ref)
c 13 (ref)
c 14 (ref)
Example (Spatial Query is Plain SQL Query)
select d i s t i n c t ObjectName
from t a b s f c h i l b e r t −− table where s p a t i a l index stored
where idx between 0 and 3
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 12 / 54
Hilbert, Peano, and Sierpinski SFCs
Example
Hilbert Peano Sierpinsk
Order= 4 Order = 3 Order = 3
Note
There are several variations of these SFCs
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 13 / 54
SFC Indexing
Example
0 1 2 3 4
0
1
2
3
4
0 1
23
4
5 6
7 8
9 10
11
1213
14 15
x
y
z
v
ObjectName Idx
x ?
y ?
z ?
v ?
Note
Point, linestring, and polygon supported
Best support for points
Why?
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 14 / 54
Motivation for using SFCs
Why?
Reuse B+-tree index structure
Reuse B+-tree concurrency algorithm
Extremely complicated to make efficient
Some operations can be very efficiently implemented
When first in main memory
Add spatial index support to a “plain” DBMS
Note
Space-filling curves can be combined with quadtrees
Space-filling curves can be combined with R-tree
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 15 / 54
2D Hilbert Curves of Different Orders
Example (Order 2 to 7)
Large Geometries
How many index values for a large geometry?
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 16 / 54
3D Hilbert Curve
[http://www.math.uwaterloo.ca/ wgilbert/Research/HilbertCurve/HilbertCurve.html]
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 17 / 54
Summary: SFC
Note
Space division
Reduces from nD/3D/2D to 1D (integers)
The numbers are indexed using a B+
-tree
There are many variations of space-filling curves
Hilbert, Moore, Peano, and Sierpinksi
Very simple to implement
Main disadvantages: Spatial close, index distant
Concurrency control already implemented
Not optimal when index must be stored on disk (block device)
Quiz
Did you notice anything about the dimension sizes?
Can you give a reason why?
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 18 / 54
Outline
1 Introduction
2 Space-filling Curves (SFC)
3 R-Tree
Minimum-Bounding Rectangle (MBR)
Range Search
4 Quadtrees
5 Summary
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 19 / 54
Outline
1 Introduction
2 Space-filling Curves (SFC)
3 R-Tree
Minimum-Bounding Rectangle (MBR)
Range Search
4 Quadtrees
5 Summary
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 20 / 54
Examples of MBRs
Example (MBRs for Various Shapes)
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
6
7
8
Note
Four coordinates to index all spatial objects in 2D
Leads to false positives
Examples of MBRs
Example (MBRs for Various Shapes)
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
6
7
8
Note
Four coordinates to index all spatial objects in 2D
Leads to false positives
Examples of MBRs
Example (MBRs for Various Shapes)
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
6
7
8
Note
Four coordinates to index all spatial objects in 2D
Leads to false positives
Examples of MBRs
Example (MBRs for Various Shapes)
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
6
7
8
Note
Four coordinates to index all spatial objects in 2D
Leads to false positives
Examples of MBRs
Example (MBRs for Various Shapes)
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
6
7
8
Note
Four coordinates to index all spatial objects in 2D
Leads to false positives
Examples of MBRs
Example (MBRs for Various Shapes)
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
6
7
8
Note
Four coordinates to index all spatial objects in 2D
Leads to false positives
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 21 / 54
Insert
Example (R-tree)
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
1
2
A
Note
Assuming maximum 3 values per node
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 22 / 54
Insert
Example (R-tree)
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
1
2
3
A
Note
Assuming maximum 3 values per node
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 22 / 54
Insert
Example (R-tree)
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
1
2
3
4
A
B
Note
Assuming maximum 3 values per node
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 22 / 54
Insert
Example (R-tree)
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
1
2
3
45
A
B
Note
Assuming maximum 3 values per node
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 22 / 54
Insert
Example (R-tree)
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
1
2
3
45
6A
B
Note
Assuming maximum 3 values per node
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 22 / 54
Insert
Example (R-tree)
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
1
2
3
45
6
7
A
B C
Note
Assuming maximum 3 values per node
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 22 / 54
Quiz: Good MBR?
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
1 2
3
A
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
1 2
3 A
A B
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
1 2
3
A
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
1 2
3
A
C D
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 23 / 54
Delete
Example (R-tree)
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
1
2
3
45
6
7
A
B C
Note
Assuming minimum 2 values and maximum 3 values per node
Delete 1 ⇒ shrink A
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 24 / 54
Delete
Example (R-tree)
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
2
3
45
6
7
A
B C
Note
Delete 6
Underflow in A merge with other MBR at same level
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 24 / 54
Delete
Example (R-tree)
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
2
3
45
7
B
C
Note
Delete 3
Underflow in B merge with other MBR at same level
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 24 / 54
Delete
Example (R-tree)
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
2
45
7
B
C
Note
There are many details
Picking good candidate for merge is hard
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 24 / 54
A Complete R-tree
Example (R-tree)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
0
1
2
3
4
5
6
7
8
9
10
1
2
3
I II - -
A B C -
1 2 3 - 4 5 6 - 7 8 9 -
D E F -
10 11 12 - 13 14 15 - 16 17 18 -
A Complete R-tree
Example (R-tree)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
0
1
2
3
4
5
6
7
8
9
10
1
2
3
A
I II - -
A B C -
1 2 3 - 4 5 6 - 7 8 9 -
D E F -
10 11 12 - 13 14 15 - 16 17 18 -
A Complete R-tree
Example (R-tree)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
0
1
2
3
4
5
6
7
8
9
10
1
2
3
A
4
5
6
I II - -
A B C -
1 2 3 - 4 5 6 - 7 8 9 -
D E F -
10 11 12 - 13 14 15 - 16 17 18 -
A Complete R-tree
Example (R-tree)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
0
1
2
3
4
5
6
7
8
9
10
1
2
3
A
4
5
6
B
I II - -
A B C -
1 2 3 - 4 5 6 - 7 8 9 -
D E F -
10 11 12 - 13 14 15 - 16 17 18 -
A Complete R-tree
Example (R-tree)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
0
1
2
3
4
5
6
7
8
9
10
1
2
3
A
4
5
6
B
7
8 9
I II - -
A B C -
1 2 3 - 4 5 6 - 7 8 9 -
D E F -
10 11 12 - 13 14 15 - 16 17 18 -
A Complete R-tree
Example (R-tree)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
0
1
2
3
4
5
6
7
8
9
10
1
2
3
A
4
5
6
B
7
8 9
C
I II - -
A B C -
1 2 3 - 4 5 6 - 7 8 9 -
D E F -
10 11 12 - 13 14 15 - 16 17 18 -
A Complete R-tree
Example (R-tree)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
0
1
2
3
4
5
6
7
8
9
10
1
2
3
A
4
5
6
B
7
8 9
C
I
I II - -
A B C -
1 2 3 - 4 5 6 - 7 8 9 -
D E F -
10 11 12 - 13 14 15 - 16 17 18 -
A Complete R-tree
Example (R-tree)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
0
1
2
3
4
5
6
7
8
9
10
1
2
3
A
4
5
6
B
7
8 9
C
I
10
11
12
I II - -
A B C -
1 2 3 - 4 5 6 - 7 8 9 -
D E F -
10 11 12 - 13 14 15 - 16 17 18 -
A Complete R-tree
Example (R-tree)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
0
1
2
3
4
5
6
7
8
9
10
1
2
3
A
4
5
6
B
7
8 9
C
I
10
11
12
D
I II - -
A B C -
1 2 3 - 4 5 6 - 7 8 9 -
D E F -
10 11 12 - 13 14 15 - 16 17 18 -
A Complete R-tree
Example (R-tree)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
0
1
2
3
4
5
6
7
8
9
10
1
2
3
A
4
5
6
B
7
8 9
C
I
10
11
12
D
13
14 15
I II - -
A B C -
1 2 3 - 4 5 6 - 7 8 9 -
D E F -
10 11 12 - 13 14 15 - 16 17 18 -
A Complete R-tree
Example (R-tree)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
0
1
2
3
4
5
6
7
8
9
10
1
2
3
A
4
5
6
B
7
8 9
C
I
10
11
12
D
13
14 15
E
I II - -
A B C -
1 2 3 - 4 5 6 - 7 8 9 -
D E F -
10 11 12 - 13 14 15 - 16 17 18 -
A Complete R-tree
Example (R-tree)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
0
1
2
3
4
5
6
7
8
9
10
1
2
3
A
4
5
6
B
7
8 9
C
I
10
11
12
D
13
14 15
E
16
17
18
I II - -
A B C -
1 2 3 - 4 5 6 - 7 8 9 -
D E F -
10 11 12 - 13 14 15 - 16 17 18 -
A Complete R-tree
Example (R-tree)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
0
1
2
3
4
5
6
7
8
9
10
1
2
3
A
4
5
6
B
7
8 9
C
I
10
11
12
D
13
14 15
E
16
17
18
F
I II - -
A B C -
1 2 3 - 4 5 6 - 7 8 9 -
D E F -
10 11 12 - 13 14 15 - 16 17 18 -
A Complete R-tree
Example (R-tree)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
0
1
2
3
4
5
6
7
8
9
10
1
2
3
A
4
5
6
B
7
8 9
C
I
10
11
12
D
13
14 15
E
16
17
18
FII
I II - -
A B C -
1 2 3 - 4 5 6 - 7 8 9 -
D E F -
10 11 12 - 13 14 15 - 16 17 18 -
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 25 / 54
Clustering of Rectangles
Example (Clustering One)
a
b
c
d
Example (Clustering Two)
a
b
c
d
Questions
Which clustering of rectangles is best?
What are the evaluation criteria?
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 26 / 54
R-tree Node Properties
Parameters
M is maximum fanout and determined by page size
m is minimum fanout
Typically 0.4-0.5 of M
R-tree Properties
The root node has minimum two children, unless it is a leaf
All non-root nodes have m and M children
Leaf-node entries <MBR, oid> MBR for the data object
Non-leaf node <MBR, ptr> MBR contains all child nodes
All leaf nodes at the same level
Note
R-tree properties similar to B+-tree properties
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 27 / 54
R-tree: Online Demo
R-tree Online Demo Applet
gis.umb.no/gis/applets/rtree2/jdk1.1/
Questions
What are the m and M?
What happens when you insert within an MBR?
What happens when you insert outside an MBR?
What happens if you delete from an MBR such that there are less
than m objects?
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 28 / 54
Outline
1 Introduction
2 Space-filling Curves (SFC)
3 R-Tree
Minimum-Bounding Rectangle (MBR)
Range Search
4 Quadtrees
5 Summary
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 29 / 54
Filter and Refine
Two-Step Filtering
R-Tree
Intermediate
Filter
Geometry
Comparison
Result
False Hits
Primary Filter Secondary Filter
Two-Step Process
Use MBR for checking for potential overlap (fast)
Use actual geometry to check for real overlap (slow)
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 30 / 54
MBRs for Overlap
O1 O2
O3
O4
O5
Which objects are in the result?
Which objects are not in the result?
Which objects may be in the result?
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 31 / 54
Range Search
Example (R-tree)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
0
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6 7
8 9
A
B
C
I
I II - -
A B C -
1 2 3 - 4 5 6 - 7 8 9 -
D E F -
10 11 12 - 13 14 15 - 16 17 18 -
Range Search
Example (R-tree)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
0
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6 7
8 9
A
B
C
I
10
11
12
13
14 15
16
17
18
D E
FII
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 32 / 54
Range Search
Example (R-tree)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
0
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6 7
8 9
A
B
C
I
10
11
12
13
14 15
16
17
18
D E
FII
I II - -
A B C -
1 2 3 - 4 5 6 - 7 8 9 -
D E F -
10 11 12 - 13 14 15 - 16 17 18 -
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 32 / 54
Range Search, One
Example (R-tree)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
0
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6 7
8 9
A
B
C
I
10
11
12
13
14 15
16
17
18
D E
FII
I II - -
A B C -
1 2 3 - 4 5 6 - 7 8 9 -
D E F -
10 11 12 - 13 14 15 - 16 17 18 -
Range Search, One
Example (R-tree)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
0
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6 7
8 9
A
B
C
I
10
11
12
13
14 15
16
17
18
D E
FIIQ1
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 33 / 54
Range Search, One
Example (R-tree)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
0
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6 7
8 9
A
B
C
I
10
11
12
13
14 15
16
17
18
D E
FIIQ1
I II - -
A B C -
1 2 3 - 4 5 6 - 7 8 9 -
D E F -
10 11 12 - 13 14 15 - 16 17 18 -
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 33 / 54
Range Search, Two
Example (R-tree)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
0
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6 7
8 9
A
B
C
I
10
11
12
13
14 15
16
17
18
D E
FII
I II - -
A B C -
1 2 3 - 4 5 6 - 7 8 9 -
D E F -
10 11 12 - 13 14 15 - 16 17 18 -
Range Search, Two
Example (R-tree)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
0
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6 7
8 9
A
B
C
I
10
11
12
13
14 15
16
17
18
D E
FII
Q2
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 34 / 54
Range Search, Two
Example (R-tree)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
0
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6 7
8 9
A
B
C
I
10
11
12
13
14 15
16
17
18
D E
FII
Q2
I II - -
A B C -
1 2 3 - 4 5 6 - 7 8 9 -
D E F -
10 11 12 - 13 14 15 - 16 17 18 -
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 34 / 54
Quiz: Range Query
Example (R-tree)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
0
1
2
3
4
5
6
7
8
9
10
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 2930
31 32
33
34
35
36 37
A B
C D
E F
G
H
I
J
K
L
M
I
II
III
IV
Q
Quiz
Which MBRs are examined?
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 35 / 54
R-tree versus R+
-tree and R∗
-tree
R∗
-tree
Like R-tree just insert algorithm changed
Minimize area of each MBR
Minimize overlap between MBRs
Maximize storage usage
Maximize square-ness of MBRs
Overall: Slower modifications, faster search
R+
-tree
No overlap between MBRs for non-leaf node
Indexed object may be inserted more than once
Multi-path not needed for search
Overall: Higher tree / faster search
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 36 / 54
Summary: R-tree
Note
Data division
Multi-level index (a tree!)
There are many variations of the R-tree, e.g., R+-tree and R∗-tree
Very complicated to implement
Concurrency control very complicated to implement
Very good when index must be stored on disk (block device)
Good index structure for in-memory databases
Many (hundreds) of index structures derived from R-tree
Performance
The R-tree typically outperforms quadtrees and SFC!
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 37 / 54
Outline
1 Introduction
2 Space-filling Curves (SFC)
3 R-Tree
Minimum-Bounding Rectangle (MBR)
Range Search
4 Quadtrees
5 Summary
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 38 / 54
Basic Idea
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
6
7
8
1
2 3
4
Basic Idea
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
6
7
8
1
2 3
4
Basic Idea
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
6
7
8
1
2 3
4
5
6
7
Basic Idea
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
6
7
8
1
2 3
4
5
6
7
Basic Idea
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
6
7
8
1
2 3
4
5
6
7
8
9
Basic Idea
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
6
7
8
1
2 3
4
5
6
7
8
9
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 39 / 54
The Quad and Tree in Quadtree
Quad
0 1
2 3
10 11
12 13
30 31
32 33
120 121
122 123
Tree
All
0 1
10 11 12
120 121 122 123
13
2 3
30 31 32 33
Note
One entry for each point
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 40 / 54
Rectangles in a Quadtree
The Data
0 1
2 3
10 11
12 13
120 121
122 123
A
B
C
D
E
F
G H
The Quadtree
All
0:A,E 1:C,D
10 11 12:F
120 121 122:G 123:H
13
2:A,B 3:B,D
Note
Each rectangle in multiple subtrees
Where is the worst place a rectangle can be placed?
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 41 / 54
Quiz: Indexing Rectangles
The Data
0 1
2 3
10 11
12 13
30 31
32 33
120 121
122 123
130 131
132 133
A B
C
D
E
F
Which Index Values?
A?
B?
C?
D?
E?
F?
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 42 / 54
Quiz: Indexing Rectangles
The Data
0 1
2 3
10 11
12 13
30 31
32 33
120 121
122 123
130 131
132 133
A B
C
D
E
F
Which Index Values?
A?
B?
C?
D?
E?
F?
Trade off
Accurate (smallest quads)
Space usage (biggest quads)
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 42 / 54
Complicated Polygon in a Quadtree, One
Data
0 1
2 3
20 21
22 23
30 31
32 33
10 11
12 13
120 121
122 123
210 211
212 213
Index
0 1
2 3
20 21
22 23
30 31
32 33
10 11
12 13
120 121
122 123
210 211
212 213
Note
Many entries for a single object
Assuming maximum three levels in index
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 43 / 54
Complicated Polygon in a Quadtree, Two
Data
0 1
2 3
10 11
12 13
20 21
22 23
30 31
32 33
120 121
122 123
Index
0 1
2 3
10 11
12 13
20 21
22 23
30 31
32 33
120 121
122 123
Note
Another example
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 44 / 54
Linestrings in a Quadtree
Data
0 1
2 3
10 11
12 13
20 21
22 23
30 31
32 33
120 121
122 123
130 131
132 133
210 211
212 213
220 221
222 223
230 231
232 233
300 301
302 303
Index
0 1
2 3
10 11
12 13
20 21
22 23
30 31
32 33
120 121
122 123
130 131
132 133
210 211
212 213
220 221
222 223
230 231
232 233
300 301
302 303
Note
Long lines are a challenge for quadtrees
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 45 / 54
SQL Server 2008 R2 Spatial Grid
[http://sqlskills.com/blogs/paul/post/SQL-Server-2008-Spatial-indexes.aspx]
Note
Maximum 4 levels
Small = 4x4, Medium = 8x8, Large 16x16
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 46 / 54
SQL Server 2008 R2: Complex Object
[http://social.technet.microsoft.com]
Questions
Why different granularities?
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 47 / 54
Quadtree Demo
PR Quadtree Demo
donar.umiacs.umd.edu/quadtree/points/prquad.html
Questions
What can you note about the sizes of the regions when split?
Is the tree balanced?
PMR Quadtree Demo
donar.umiacs.umd.edu/quadtree/rectangles/PMR.html
Questions
What happens when you place a rectangle in the middle of an empty
region?
Is the tree balanced?
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 48 / 54
Which Quadtree are Legal?
A B
C D
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 49 / 54
Quadtree: Comments
Note
Space division
Can be used for all types of spatial objects
There are many variations of the quad tree
The version here is called the PR quadtree
Variation of quadtree is used in SQL Server 2008 R2
Data structure is fairly simple to implement
Concurrency control is fairly simple to implement
Not optimal when index must be stored on disk (block device)
Quiz
Why are there multiple levels in a quadtree?
Did you notice anything about the dimension sizes?
Can you give a reason why?
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 50 / 54
Outline
1 Introduction
2 Space-filling Curves (SFC)
3 R-Tree
Minimum-Bounding Rectangle (MBR)
Range Search
4 Quadtrees
5 Summary
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 51 / 54
Comparison of Indexing Methods
Support for Data Types
SFC Quadtree R-tree
Point Good Good Good
Linestring Okay Okay Good
Polygon Okay Okay Good
Support for Queries
SFC Quadtree R-tree
Point Good Good Good
Range Bad Okay Good
Join Okay Okay Good
NN Okay Okay Okay
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 52 / 54
Summary: Spatial Indexing
Note
The R-tree is the industry “work horse”
Good 2D and 3D
Breaks around∼ 10D, called the dimensional curse
Quadtree used because simple to implement
Particular good if all data is in main memory
Very good demo at donar.umiacs.umd.edu/quadtree/index.html
Space-filling curves may be exactly sufficient for your app!
Simple to implement
Much faster than full table scans
Important Concepts
Data and space division
Minimum bounding rectangle (MBR)
Split
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 53 / 54
More Information
Web Links
R-tree at Wikipedia at en.wikipedia.org/wiki/R-tree
Good overview with many links to additional material
R-tree demo at gis.umb.no/gis/applets/rtree2/jdk1.1/
Quadtree and R-Tree demo at
donar.umiacs.umd.edu/quadtree/index.html
What new spatial next SQL Server social.technet.microsoft.
com/wiki/contents/articles/4136.aspx
Research Related
The original R-tree paper
www-db.deis.unibo.it/courses/SI-LS/papers/Gut84.pdf
The first R∗-tree paper epub.ub.uni-muenchen.de/4256/1/31.pdf
Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 54 / 54

Contenu connexe

Tendances

Tendances (20)

Hadoop Architecture
Hadoop ArchitectureHadoop Architecture
Hadoop Architecture
 
SPATIAL DATABASES.pptx
SPATIAL DATABASES.pptxSPATIAL DATABASES.pptx
SPATIAL DATABASES.pptx
 
Data Preprocessing
Data PreprocessingData Preprocessing
Data Preprocessing
 
Object oriented database concepts
Object oriented database conceptsObject oriented database concepts
Object oriented database concepts
 
Data mining and data warehouse lab manual updated
Data mining and data warehouse lab manual updatedData mining and data warehouse lab manual updated
Data mining and data warehouse lab manual updated
 
Indexing and Hashing
Indexing and HashingIndexing and Hashing
Indexing and Hashing
 
Temporal databases
Temporal databasesTemporal databases
Temporal databases
 
Spatial data mining
Spatial data miningSpatial data mining
Spatial data mining
 
Introduction to Data Warehouse
Introduction to Data WarehouseIntroduction to Data Warehouse
Introduction to Data Warehouse
 
Multidimensional schema
Multidimensional schemaMultidimensional schema
Multidimensional schema
 
Principles of data visualisation 2021
Principles of data visualisation 2021Principles of data visualisation 2021
Principles of data visualisation 2021
 
OLAP operations
OLAP operationsOLAP operations
OLAP operations
 
1.2 steps and functionalities
1.2 steps and functionalities1.2 steps and functionalities
1.2 steps and functionalities
 
1.7 data reduction
1.7 data reduction1.7 data reduction
1.7 data reduction
 
Introduction to Database Management System.pdf
Introduction to Database Management System.pdfIntroduction to Database Management System.pdf
Introduction to Database Management System.pdf
 
Metadata ppt
Metadata pptMetadata ppt
Metadata ppt
 
5.1 mining data streams
5.1 mining data streams5.1 mining data streams
5.1 mining data streams
 
Object Based Databases
Object Based DatabasesObject Based Databases
Object Based Databases
 
Introduction to Data Visualization
Introduction to Data VisualizationIntroduction to Data Visualization
Introduction to Data Visualization
 
Encapsulation of operations, methods & persistence
Encapsulation of operations, methods & persistenceEncapsulation of operations, methods & persistence
Encapsulation of operations, methods & persistence
 

En vedette

Thesis Powerpoint
Thesis PowerpointThesis Powerpoint
Thesis Powerpoint
neha47
 
Thesis Power Point Presentation
Thesis Power Point PresentationThesis Power Point Presentation
Thesis Power Point Presentation
riddhikapandya1985
 

En vedette (10)

The DE-9IM Matrix in Details using ST_Relate: In Picture and SQL
The DE-9IM Matrix in Details using ST_Relate: In Picture and SQLThe DE-9IM Matrix in Details using ST_Relate: In Picture and SQL
The DE-9IM Matrix in Details using ST_Relate: In Picture and SQL
 
VO Course 11: Spatial indexing
VO Course 11: Spatial indexingVO Course 11: Spatial indexing
VO Course 11: Spatial indexing
 
SQLBits X SQL Server 2012 Spatial Indexing
SQLBits X SQL Server 2012 Spatial IndexingSQLBits X SQL Server 2012 Spatial Indexing
SQLBits X SQL Server 2012 Spatial Indexing
 
Enabling Access to Big Geospatial Data with LocationTech and Apache projects
Enabling Access to Big Geospatial Data with LocationTech and Apache projectsEnabling Access to Big Geospatial Data with LocationTech and Apache projects
Enabling Access to Big Geospatial Data with LocationTech and Apache projects
 
Spatial Data processing with Hadoop
Spatial Data processing with HadoopSpatial Data processing with Hadoop
Spatial Data processing with Hadoop
 
RTree Spatial Indexing with MongoDB - MongoDC
RTree Spatial Indexing with MongoDB - MongoDC RTree Spatial Indexing with MongoDB - MongoDC
RTree Spatial Indexing with MongoDB - MongoDC
 
Thesis powerpoint
Thesis powerpointThesis powerpoint
Thesis powerpoint
 
Geo tagging & spatial indexing of text-specified data
Geo tagging & spatial indexing of text-specified dataGeo tagging & spatial indexing of text-specified data
Geo tagging & spatial indexing of text-specified data
 
Thesis Powerpoint
Thesis PowerpointThesis Powerpoint
Thesis Powerpoint
 
Thesis Power Point Presentation
Thesis Power Point PresentationThesis Power Point Presentation
Thesis Power Point Presentation
 

Similaire à Spatial Indexing

CS8091-Big Data Analytics.pdf
CS8091-Big Data Analytics.pdfCS8091-Big Data Analytics.pdf
CS8091-Big Data Analytics.pdf
ssuserad38541
 
SIGMOD 2013 - Patricia's talk on "Value invention for Data Exchange"
SIGMOD 2013 - Patricia's talk on "Value invention for Data Exchange"SIGMOD 2013 - Patricia's talk on "Value invention for Data Exchange"
SIGMOD 2013 - Patricia's talk on "Value invention for Data Exchange"
Boris Glavic
 

Similaire à Spatial Indexing (20)

Ontop: Answering SPARQL Queries over Relational Databases
Ontop: Answering SPARQL Queries over Relational DatabasesOntop: Answering SPARQL Queries over Relational Databases
Ontop: Answering SPARQL Queries over Relational Databases
 
Data structure-question-bank
Data structure-question-bankData structure-question-bank
Data structure-question-bank
 
OLAP Basics and Fundamentals by Bharat Kalia
OLAP Basics and Fundamentals by Bharat Kalia OLAP Basics and Fundamentals by Bharat Kalia
OLAP Basics and Fundamentals by Bharat Kalia
 
Decentralized Evolution and Consolidation of RDF Graphs
Decentralized Evolution and Consolidation of RDF GraphsDecentralized Evolution and Consolidation of RDF Graphs
Decentralized Evolution and Consolidation of RDF Graphs
 
Big Data and Geospatial with HPCC Systems
Big Data and Geospatial with HPCC SystemsBig Data and Geospatial with HPCC Systems
Big Data and Geospatial with HPCC Systems
 
CS8091-Big Data Analytics.pdf
CS8091-Big Data Analytics.pdfCS8091-Big Data Analytics.pdf
CS8091-Big Data Analytics.pdf
 
Compact Representation of Large RDF Data Sets for Publishing and Exchange
Compact Representation of Large RDF Data Sets for Publishing and ExchangeCompact Representation of Large RDF Data Sets for Publishing and Exchange
Compact Representation of Large RDF Data Sets for Publishing and Exchange
 
On unifying query languages for RDF streams
On unifying query languages for RDF streamsOn unifying query languages for RDF streams
On unifying query languages for RDF streams
 
Introduction to XPath
Introduction to XPathIntroduction to XPath
Introduction to XPath
 
Inductive Triple Graphs: A purely functional approach to represent RDF
Inductive Triple Graphs: A purely functional approach to represent RDFInductive Triple Graphs: A purely functional approach to represent RDF
Inductive Triple Graphs: A purely functional approach to represent RDF
 
Dagobahic2020orange
Dagobahic2020orangeDagobahic2020orange
Dagobahic2020orange
 
SIGMOD 2013 - Patricia's talk on "Value invention for Data Exchange"
SIGMOD 2013 - Patricia's talk on "Value invention for Data Exchange"SIGMOD 2013 - Patricia's talk on "Value invention for Data Exchange"
SIGMOD 2013 - Patricia's talk on "Value invention for Data Exchange"
 
Introduction to DTD
Introduction to DTDIntroduction to DTD
Introduction to DTD
 
L'ingénierie dans les nuages
L'ingénierie dans les nuagesL'ingénierie dans les nuages
L'ingénierie dans les nuages
 
Logic
LogicLogic
Logic
 
[DL輪読会]Hindsight Experience Replayを応用した再ラベリングによる効率的な強化学習
[DL輪読会]Hindsight Experience Replayを応用した再ラベリングによる効率的な強化学習[DL輪読会]Hindsight Experience Replayを応用した再ラベリングによる効率的な強化学習
[DL輪読会]Hindsight Experience Replayを応用した再ラベリングによる効率的な強化学習
 
Temporal Databases: Data Models
Temporal Databases: Data ModelsTemporal Databases: Data Models
Temporal Databases: Data Models
 
Histogram
HistogramHistogram
Histogram
 
A middleware for storing massive RDF graphs into NoSQL
A middleware for storing massive RDF graphs into NoSQLA middleware for storing massive RDF graphs into NoSQL
A middleware for storing massive RDF graphs into NoSQL
 
Geographica: A Benchmark for Geospatial RDF Stores
Geographica: A Benchmark for Geospatial RDF StoresGeographica: A Benchmark for Geospatial RDF Stores
Geographica: A Benchmark for Geospatial RDF Stores
 

Plus de torp42 (6)

SQL/XML on Oracle
SQL/XML on OracleSQL/XML on Oracle
SQL/XML on Oracle
 
XML on SQL Server
XML on SQL ServerXML on SQL Server
XML on SQL Server
 
Entity-Relationship Diagrams ERD
Entity-Relationship Diagrams ERDEntity-Relationship Diagrams ERD
Entity-Relationship Diagrams ERD
 
Introduction to XML and Databases
Introduction to XML and DatabasesIntroduction to XML and Databases
Introduction to XML and Databases
 
Temporal Databases: Modifications
Temporal Databases: ModificationsTemporal Databases: Modifications
Temporal Databases: Modifications
 
Temporal Databases: Queries
Temporal Databases: QueriesTemporal Databases: Queries
Temporal Databases: Queries
 

Dernier

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 

Spatial Indexing

  • 1. Spatial Indexing Kristian Torp Department of Computer Science Aalborg University people.cs.aau.dk/˜torp torp@cs.aau.dk November 19, 2015 daisy.aau.dk Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 1 / 54
  • 2. Outline 1 Introduction 2 Space-filling Curves (SFC) 3 R-Tree Minimum-Bounding Rectangle (MBR) Range Search 4 Quadtrees 5 Summary Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 2 / 54
  • 3. Learning Goals The Problem Existing indexes good for scalar values, e.g., 42 and ’Hello, World’ Existing indexes not good complex data, e.g., geometries and time series Quiz Which index structures do you know? Goals Overview of spatial indexing techniques Understand how spatial indexing different from “plain” indexing Understand the basic spatial indexing techniques Be able to construct a spatial index on PostgreSQL Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 3 / 54
  • 4. Outline 1 Introduction 2 Space-filling Curves (SFC) 3 R-Tree Minimum-Bounding Rectangle (MBR) Range Search 4 Quadtrees 5 Summary Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 4 / 54
  • 5. Spatial Query Types c1 c2 c3 c4 c5 c6 c7 c1 c2 c3 c4 c5 c6 c7 Range Nearest Neighbor c1 c2 c3 c4 c5 c6 c7 f1 f2 f3 f4c1 c2 c3 c4 c5 c6 c7 Within Spatial Join Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 5 / 54
  • 6. Spatial Indexing Purposes of Spatial Index Structure Should speed-up the most typical spatial queries Should not take up too much space Should efficiently support modifications Assumptions Spatial query only covers small part of the “world” Spatial data is queried more often then modified Note Indexing necessary to make queries run faster Hashing does not work well for spatial data types You can index spatial data using conventional (B+-tree) indexes It is often slow! Will see how can be used with space-filling curves Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 6 / 54
  • 7. Overview of Spatial Indexing Techniques Techniques Space-filling curves (a set of approaches) Old wine, recycled bottles R-trees (a large family of index structures) A generalization of the B+ -tree Quadtrees (a family of index structures) Old wine, new bottles Other Domains Image processing, e.g., medical and biometrics Image recognition, e.g., letters and books Gaming, e.g., for the terrain, buildings, and roads Chip design, e.g., integrated circuits, think AMD, ARM, and Intel Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 7 / 54
  • 8. Create Spatial Index Example (Table with Spatial Data Column) create table landscape ( geo name varchar (20) primary key , geo geometry not n u l l ) ; Example (Create B+ -tree Index on PostgreSQL) create index landscape geo name on landscape ( geo name ) ; Example (Create R-tree Index on PostgreSQL) create index landscape geo on landscape using g i s t ( geo ) ; Note GIST = Generalized Search Trees = R-tree = spatial index From SQL interface not a big think! Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 8 / 54
  • 9. Outline 1 Introduction 2 Space-filling Curves (SFC) 3 R-Tree Minimum-Bounding Rectangle (MBR) Range Search 4 Quadtrees 5 Summary Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 9 / 54
  • 10. The Basic Idea: SFC Example (Division of World) 0 1 2 3 4 0 1 2 3 4
  • 11. The Basic Idea: SFC Example (Division of World) 0 1 2 3 4 0 1 2 3 4 0 1 23 4 5 6 7 8 9 10 11 1213 14 15
  • 12. The Basic Idea: SFC Example (Division of World) 0 1 2 3 4 0 1 2 3 4 0 1 23 4 5 6 7 8 9 10 11 1213 14 15
  • 13. The Basic Idea: SFC Example (Division of World) 0 1 2 3 4 0 1 2 3 4 0 1 23 4 5 6 7 8 9 10 11 1213 14 15 a
  • 14. The Basic Idea: SFC Example (Division of World) 0 1 2 3 4 0 1 2 3 4 0 1 23 4 5 6 7 8 9 10 11 1213 14 15 a b
  • 15. The Basic Idea: SFC Example (Division of World) 0 1 2 3 4 0 1 2 3 4 0 1 23 4 5 6 7 8 9 10 11 1213 14 15 a b c Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 10 / 54
  • 16. SFC for Indexing Spatial Objects Example (Space-filling Curve) 0 1 2 3 4 0 1 2 3 4 0 1 23 4 5 6 7 8 9 10 11 1213 14 15 a b c ObjectName Idx Coor a 10 (3.7, 3.7) b 7 (1.2, 2.7) c 1 (ref) c 2 (ref) c 13 (ref) c 14 (ref) Variations This is a Hilbert space-filling curve Index and spatial data typically split in two tables Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 11 / 54
  • 17. Spatial Query using SFC Example (Space-filling Curve) 0 1 2 3 4 0 1 2 3 4 0 1 23 4 5 6 7 8 9 10 11 1213 14 15 a b c ObjectName Idx Coor a 10 (3.7, 3.7) b 7 (1.2, 2.7) c 1 (ref) c 2 (ref) c 13 (ref) c 14 (ref) Example (Spatial Query is Plain SQL Query) select d i s t i n c t ObjectName from t a b s f c h i l b e r t −− table where s p a t i a l index stored where idx between 0 and 3 Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 12 / 54
  • 18. Hilbert, Peano, and Sierpinski SFCs Example Hilbert Peano Sierpinsk Order= 4 Order = 3 Order = 3 Note There are several variations of these SFCs Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 13 / 54
  • 19. SFC Indexing Example 0 1 2 3 4 0 1 2 3 4 0 1 23 4 5 6 7 8 9 10 11 1213 14 15 x y z v ObjectName Idx x ? y ? z ? v ? Note Point, linestring, and polygon supported Best support for points Why? Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 14 / 54
  • 20. Motivation for using SFCs Why? Reuse B+-tree index structure Reuse B+-tree concurrency algorithm Extremely complicated to make efficient Some operations can be very efficiently implemented When first in main memory Add spatial index support to a “plain” DBMS Note Space-filling curves can be combined with quadtrees Space-filling curves can be combined with R-tree Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 15 / 54
  • 21. 2D Hilbert Curves of Different Orders Example (Order 2 to 7) Large Geometries How many index values for a large geometry? Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 16 / 54
  • 22. 3D Hilbert Curve [http://www.math.uwaterloo.ca/ wgilbert/Research/HilbertCurve/HilbertCurve.html] Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 17 / 54
  • 23. Summary: SFC Note Space division Reduces from nD/3D/2D to 1D (integers) The numbers are indexed using a B+ -tree There are many variations of space-filling curves Hilbert, Moore, Peano, and Sierpinksi Very simple to implement Main disadvantages: Spatial close, index distant Concurrency control already implemented Not optimal when index must be stored on disk (block device) Quiz Did you notice anything about the dimension sizes? Can you give a reason why? Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 18 / 54
  • 24. Outline 1 Introduction 2 Space-filling Curves (SFC) 3 R-Tree Minimum-Bounding Rectangle (MBR) Range Search 4 Quadtrees 5 Summary Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 19 / 54
  • 25. Outline 1 Introduction 2 Space-filling Curves (SFC) 3 R-Tree Minimum-Bounding Rectangle (MBR) Range Search 4 Quadtrees 5 Summary Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 20 / 54
  • 26. Examples of MBRs Example (MBRs for Various Shapes) 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 Note Four coordinates to index all spatial objects in 2D Leads to false positives
  • 27. Examples of MBRs Example (MBRs for Various Shapes) 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 Note Four coordinates to index all spatial objects in 2D Leads to false positives
  • 28. Examples of MBRs Example (MBRs for Various Shapes) 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 Note Four coordinates to index all spatial objects in 2D Leads to false positives
  • 29. Examples of MBRs Example (MBRs for Various Shapes) 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 Note Four coordinates to index all spatial objects in 2D Leads to false positives
  • 30. Examples of MBRs Example (MBRs for Various Shapes) 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 Note Four coordinates to index all spatial objects in 2D Leads to false positives
  • 31. Examples of MBRs Example (MBRs for Various Shapes) 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 Note Four coordinates to index all spatial objects in 2D Leads to false positives Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 21 / 54
  • 32. Insert Example (R-tree) 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 1 2 A Note Assuming maximum 3 values per node Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 22 / 54
  • 33. Insert Example (R-tree) 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 1 2 3 A Note Assuming maximum 3 values per node Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 22 / 54
  • 34. Insert Example (R-tree) 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 1 2 3 4 A B Note Assuming maximum 3 values per node Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 22 / 54
  • 35. Insert Example (R-tree) 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 1 2 3 45 A B Note Assuming maximum 3 values per node Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 22 / 54
  • 36. Insert Example (R-tree) 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 1 2 3 45 6A B Note Assuming maximum 3 values per node Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 22 / 54
  • 37. Insert Example (R-tree) 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 1 2 3 45 6 7 A B C Note Assuming maximum 3 values per node Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 22 / 54
  • 38. Quiz: Good MBR? 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 1 2 3 A 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 1 2 3 A A B 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 1 2 3 A 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 1 2 3 A C D Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 23 / 54
  • 39. Delete Example (R-tree) 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 1 2 3 45 6 7 A B C Note Assuming minimum 2 values and maximum 3 values per node Delete 1 ⇒ shrink A Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 24 / 54
  • 40. Delete Example (R-tree) 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 2 3 45 6 7 A B C Note Delete 6 Underflow in A merge with other MBR at same level Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 24 / 54
  • 41. Delete Example (R-tree) 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 2 3 45 7 B C Note Delete 3 Underflow in B merge with other MBR at same level Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 24 / 54
  • 42. Delete Example (R-tree) 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 2 45 7 B C Note There are many details Picking good candidate for merge is hard Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 24 / 54
  • 43. A Complete R-tree Example (R-tree) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 1 2 3 4 5 6 7 8 9 10 1 2 3 I II - - A B C - 1 2 3 - 4 5 6 - 7 8 9 - D E F - 10 11 12 - 13 14 15 - 16 17 18 -
  • 44. A Complete R-tree Example (R-tree) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 1 2 3 4 5 6 7 8 9 10 1 2 3 A I II - - A B C - 1 2 3 - 4 5 6 - 7 8 9 - D E F - 10 11 12 - 13 14 15 - 16 17 18 -
  • 45. A Complete R-tree Example (R-tree) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 1 2 3 4 5 6 7 8 9 10 1 2 3 A 4 5 6 I II - - A B C - 1 2 3 - 4 5 6 - 7 8 9 - D E F - 10 11 12 - 13 14 15 - 16 17 18 -
  • 46. A Complete R-tree Example (R-tree) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 1 2 3 4 5 6 7 8 9 10 1 2 3 A 4 5 6 B I II - - A B C - 1 2 3 - 4 5 6 - 7 8 9 - D E F - 10 11 12 - 13 14 15 - 16 17 18 -
  • 47. A Complete R-tree Example (R-tree) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 1 2 3 4 5 6 7 8 9 10 1 2 3 A 4 5 6 B 7 8 9 I II - - A B C - 1 2 3 - 4 5 6 - 7 8 9 - D E F - 10 11 12 - 13 14 15 - 16 17 18 -
  • 48. A Complete R-tree Example (R-tree) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 1 2 3 4 5 6 7 8 9 10 1 2 3 A 4 5 6 B 7 8 9 C I II - - A B C - 1 2 3 - 4 5 6 - 7 8 9 - D E F - 10 11 12 - 13 14 15 - 16 17 18 -
  • 49. A Complete R-tree Example (R-tree) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 1 2 3 4 5 6 7 8 9 10 1 2 3 A 4 5 6 B 7 8 9 C I I II - - A B C - 1 2 3 - 4 5 6 - 7 8 9 - D E F - 10 11 12 - 13 14 15 - 16 17 18 -
  • 50. A Complete R-tree Example (R-tree) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 1 2 3 4 5 6 7 8 9 10 1 2 3 A 4 5 6 B 7 8 9 C I 10 11 12 I II - - A B C - 1 2 3 - 4 5 6 - 7 8 9 - D E F - 10 11 12 - 13 14 15 - 16 17 18 -
  • 51. A Complete R-tree Example (R-tree) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 1 2 3 4 5 6 7 8 9 10 1 2 3 A 4 5 6 B 7 8 9 C I 10 11 12 D I II - - A B C - 1 2 3 - 4 5 6 - 7 8 9 - D E F - 10 11 12 - 13 14 15 - 16 17 18 -
  • 52. A Complete R-tree Example (R-tree) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 1 2 3 4 5 6 7 8 9 10 1 2 3 A 4 5 6 B 7 8 9 C I 10 11 12 D 13 14 15 I II - - A B C - 1 2 3 - 4 5 6 - 7 8 9 - D E F - 10 11 12 - 13 14 15 - 16 17 18 -
  • 53. A Complete R-tree Example (R-tree) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 1 2 3 4 5 6 7 8 9 10 1 2 3 A 4 5 6 B 7 8 9 C I 10 11 12 D 13 14 15 E I II - - A B C - 1 2 3 - 4 5 6 - 7 8 9 - D E F - 10 11 12 - 13 14 15 - 16 17 18 -
  • 54. A Complete R-tree Example (R-tree) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 1 2 3 4 5 6 7 8 9 10 1 2 3 A 4 5 6 B 7 8 9 C I 10 11 12 D 13 14 15 E 16 17 18 I II - - A B C - 1 2 3 - 4 5 6 - 7 8 9 - D E F - 10 11 12 - 13 14 15 - 16 17 18 -
  • 55. A Complete R-tree Example (R-tree) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 1 2 3 4 5 6 7 8 9 10 1 2 3 A 4 5 6 B 7 8 9 C I 10 11 12 D 13 14 15 E 16 17 18 F I II - - A B C - 1 2 3 - 4 5 6 - 7 8 9 - D E F - 10 11 12 - 13 14 15 - 16 17 18 -
  • 56. A Complete R-tree Example (R-tree) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 1 2 3 4 5 6 7 8 9 10 1 2 3 A 4 5 6 B 7 8 9 C I 10 11 12 D 13 14 15 E 16 17 18 FII I II - - A B C - 1 2 3 - 4 5 6 - 7 8 9 - D E F - 10 11 12 - 13 14 15 - 16 17 18 - Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 25 / 54
  • 57. Clustering of Rectangles Example (Clustering One) a b c d Example (Clustering Two) a b c d Questions Which clustering of rectangles is best? What are the evaluation criteria? Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 26 / 54
  • 58. R-tree Node Properties Parameters M is maximum fanout and determined by page size m is minimum fanout Typically 0.4-0.5 of M R-tree Properties The root node has minimum two children, unless it is a leaf All non-root nodes have m and M children Leaf-node entries <MBR, oid> MBR for the data object Non-leaf node <MBR, ptr> MBR contains all child nodes All leaf nodes at the same level Note R-tree properties similar to B+-tree properties Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 27 / 54
  • 59. R-tree: Online Demo R-tree Online Demo Applet gis.umb.no/gis/applets/rtree2/jdk1.1/ Questions What are the m and M? What happens when you insert within an MBR? What happens when you insert outside an MBR? What happens if you delete from an MBR such that there are less than m objects? Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 28 / 54
  • 60. Outline 1 Introduction 2 Space-filling Curves (SFC) 3 R-Tree Minimum-Bounding Rectangle (MBR) Range Search 4 Quadtrees 5 Summary Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 29 / 54
  • 61. Filter and Refine Two-Step Filtering R-Tree Intermediate Filter Geometry Comparison Result False Hits Primary Filter Secondary Filter Two-Step Process Use MBR for checking for potential overlap (fast) Use actual geometry to check for real overlap (slow) Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 30 / 54
  • 62. MBRs for Overlap O1 O2 O3 O4 O5 Which objects are in the result? Which objects are not in the result? Which objects may be in the result? Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 31 / 54
  • 63. Range Search Example (R-tree) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 A B C I I II - - A B C - 1 2 3 - 4 5 6 - 7 8 9 - D E F - 10 11 12 - 13 14 15 - 16 17 18 -
  • 64. Range Search Example (R-tree) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 A B C I 10 11 12 13 14 15 16 17 18 D E FII Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 32 / 54
  • 65. Range Search Example (R-tree) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 A B C I 10 11 12 13 14 15 16 17 18 D E FII I II - - A B C - 1 2 3 - 4 5 6 - 7 8 9 - D E F - 10 11 12 - 13 14 15 - 16 17 18 - Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 32 / 54
  • 66. Range Search, One Example (R-tree) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 A B C I 10 11 12 13 14 15 16 17 18 D E FII I II - - A B C - 1 2 3 - 4 5 6 - 7 8 9 - D E F - 10 11 12 - 13 14 15 - 16 17 18 -
  • 67. Range Search, One Example (R-tree) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 A B C I 10 11 12 13 14 15 16 17 18 D E FIIQ1 Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 33 / 54
  • 68. Range Search, One Example (R-tree) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 A B C I 10 11 12 13 14 15 16 17 18 D E FIIQ1 I II - - A B C - 1 2 3 - 4 5 6 - 7 8 9 - D E F - 10 11 12 - 13 14 15 - 16 17 18 - Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 33 / 54
  • 69. Range Search, Two Example (R-tree) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 A B C I 10 11 12 13 14 15 16 17 18 D E FII I II - - A B C - 1 2 3 - 4 5 6 - 7 8 9 - D E F - 10 11 12 - 13 14 15 - 16 17 18 -
  • 70. Range Search, Two Example (R-tree) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 A B C I 10 11 12 13 14 15 16 17 18 D E FII Q2 Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 34 / 54
  • 71. Range Search, Two Example (R-tree) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 A B C I 10 11 12 13 14 15 16 17 18 D E FII Q2 I II - - A B C - 1 2 3 - 4 5 6 - 7 8 9 - D E F - 10 11 12 - 13 14 15 - 16 17 18 - Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 34 / 54
  • 72. Quiz: Range Query Example (R-tree) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 1 2 3 4 5 6 7 8 9 10 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 2930 31 32 33 34 35 36 37 A B C D E F G H I J K L M I II III IV Q Quiz Which MBRs are examined? Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 35 / 54
  • 73. R-tree versus R+ -tree and R∗ -tree R∗ -tree Like R-tree just insert algorithm changed Minimize area of each MBR Minimize overlap between MBRs Maximize storage usage Maximize square-ness of MBRs Overall: Slower modifications, faster search R+ -tree No overlap between MBRs for non-leaf node Indexed object may be inserted more than once Multi-path not needed for search Overall: Higher tree / faster search Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 36 / 54
  • 74. Summary: R-tree Note Data division Multi-level index (a tree!) There are many variations of the R-tree, e.g., R+-tree and R∗-tree Very complicated to implement Concurrency control very complicated to implement Very good when index must be stored on disk (block device) Good index structure for in-memory databases Many (hundreds) of index structures derived from R-tree Performance The R-tree typically outperforms quadtrees and SFC! Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 37 / 54
  • 75. Outline 1 Introduction 2 Space-filling Curves (SFC) 3 R-Tree Minimum-Bounding Rectangle (MBR) Range Search 4 Quadtrees 5 Summary Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 38 / 54
  • 76. Basic Idea 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 1 2 3 4
  • 77. Basic Idea 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 1 2 3 4
  • 78. Basic Idea 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7
  • 79. Basic Idea 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7
  • 80. Basic Idea 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 9
  • 81. Basic Idea 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 9 Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 39 / 54
  • 82. The Quad and Tree in Quadtree Quad 0 1 2 3 10 11 12 13 30 31 32 33 120 121 122 123 Tree All 0 1 10 11 12 120 121 122 123 13 2 3 30 31 32 33 Note One entry for each point Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 40 / 54
  • 83. Rectangles in a Quadtree The Data 0 1 2 3 10 11 12 13 120 121 122 123 A B C D E F G H The Quadtree All 0:A,E 1:C,D 10 11 12:F 120 121 122:G 123:H 13 2:A,B 3:B,D Note Each rectangle in multiple subtrees Where is the worst place a rectangle can be placed? Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 41 / 54
  • 84. Quiz: Indexing Rectangles The Data 0 1 2 3 10 11 12 13 30 31 32 33 120 121 122 123 130 131 132 133 A B C D E F Which Index Values? A? B? C? D? E? F? Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 42 / 54
  • 85. Quiz: Indexing Rectangles The Data 0 1 2 3 10 11 12 13 30 31 32 33 120 121 122 123 130 131 132 133 A B C D E F Which Index Values? A? B? C? D? E? F? Trade off Accurate (smallest quads) Space usage (biggest quads) Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 42 / 54
  • 86. Complicated Polygon in a Quadtree, One Data 0 1 2 3 20 21 22 23 30 31 32 33 10 11 12 13 120 121 122 123 210 211 212 213 Index 0 1 2 3 20 21 22 23 30 31 32 33 10 11 12 13 120 121 122 123 210 211 212 213 Note Many entries for a single object Assuming maximum three levels in index Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 43 / 54
  • 87. Complicated Polygon in a Quadtree, Two Data 0 1 2 3 10 11 12 13 20 21 22 23 30 31 32 33 120 121 122 123 Index 0 1 2 3 10 11 12 13 20 21 22 23 30 31 32 33 120 121 122 123 Note Another example Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 44 / 54
  • 88. Linestrings in a Quadtree Data 0 1 2 3 10 11 12 13 20 21 22 23 30 31 32 33 120 121 122 123 130 131 132 133 210 211 212 213 220 221 222 223 230 231 232 233 300 301 302 303 Index 0 1 2 3 10 11 12 13 20 21 22 23 30 31 32 33 120 121 122 123 130 131 132 133 210 211 212 213 220 221 222 223 230 231 232 233 300 301 302 303 Note Long lines are a challenge for quadtrees Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 45 / 54
  • 89. SQL Server 2008 R2 Spatial Grid [http://sqlskills.com/blogs/paul/post/SQL-Server-2008-Spatial-indexes.aspx] Note Maximum 4 levels Small = 4x4, Medium = 8x8, Large 16x16 Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 46 / 54
  • 90. SQL Server 2008 R2: Complex Object [http://social.technet.microsoft.com] Questions Why different granularities? Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 47 / 54
  • 91. Quadtree Demo PR Quadtree Demo donar.umiacs.umd.edu/quadtree/points/prquad.html Questions What can you note about the sizes of the regions when split? Is the tree balanced? PMR Quadtree Demo donar.umiacs.umd.edu/quadtree/rectangles/PMR.html Questions What happens when you place a rectangle in the middle of an empty region? Is the tree balanced? Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 48 / 54
  • 92. Which Quadtree are Legal? A B C D Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 49 / 54
  • 93. Quadtree: Comments Note Space division Can be used for all types of spatial objects There are many variations of the quad tree The version here is called the PR quadtree Variation of quadtree is used in SQL Server 2008 R2 Data structure is fairly simple to implement Concurrency control is fairly simple to implement Not optimal when index must be stored on disk (block device) Quiz Why are there multiple levels in a quadtree? Did you notice anything about the dimension sizes? Can you give a reason why? Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 50 / 54
  • 94. Outline 1 Introduction 2 Space-filling Curves (SFC) 3 R-Tree Minimum-Bounding Rectangle (MBR) Range Search 4 Quadtrees 5 Summary Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 51 / 54
  • 95. Comparison of Indexing Methods Support for Data Types SFC Quadtree R-tree Point Good Good Good Linestring Okay Okay Good Polygon Okay Okay Good Support for Queries SFC Quadtree R-tree Point Good Good Good Range Bad Okay Good Join Okay Okay Good NN Okay Okay Okay Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 52 / 54
  • 96. Summary: Spatial Indexing Note The R-tree is the industry “work horse” Good 2D and 3D Breaks around∼ 10D, called the dimensional curse Quadtree used because simple to implement Particular good if all data is in main memory Very good demo at donar.umiacs.umd.edu/quadtree/index.html Space-filling curves may be exactly sufficient for your app! Simple to implement Much faster than full table scans Important Concepts Data and space division Minimum bounding rectangle (MBR) Split Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 53 / 54
  • 97. More Information Web Links R-tree at Wikipedia at en.wikipedia.org/wiki/R-tree Good overview with many links to additional material R-tree demo at gis.umb.no/gis/applets/rtree2/jdk1.1/ Quadtree and R-Tree demo at donar.umiacs.umd.edu/quadtree/index.html What new spatial next SQL Server social.technet.microsoft. com/wiki/contents/articles/4136.aspx Research Related The original R-tree paper www-db.deis.unibo.it/courses/SI-LS/papers/Gut84.pdf The first R∗-tree paper epub.ub.uni-muenchen.de/4256/1/31.pdf Kristian Torp (Aalborg University) Spatial Indexing November 19, 2015 54 / 54