40
CPSC 335 CPSC 335 Trees for spatial data representation and searching

CPSC 335 Trees for spatial data representation and searching

Embed Size (px)

Citation preview

Page 1: CPSC 335 Trees for spatial data representation and searching

CPSC 335CPSC 335

Trees for spatial data representation and searching

Page 2: CPSC 335 Trees for spatial data representation and searching

OverviewOverview

Spatial data structuresInterval treesK-d treesGrids and Grid files using B-treesR-trees

Page 3: CPSC 335 Trees for spatial data representation and searching

TreesTreesBST – search trees, O(n)AVL, IPR – balanced O(log n)B-trees – for indexing and

searching in data bases:◦Grow from the leaf level◦More compact – faster search

B+, B* - used for indexing, store data in leaves, nodes are more full

Page 4: CPSC 335 Trees for spatial data representation and searching

Spatial data applicationsSpatial data applicationsGIS (Geographic Information

Systems)CAD (Computer Aided Design)VLSI (Very Large Scale

Integration, IBM)RoboticsImage Processing

Page 5: CPSC 335 Trees for spatial data representation and searching

Spatial objectsSpatial objects

pointsegmentlinecirclespherepolygon

◦ Convex, concave◦ Simple, Non-simple◦ With holes, without holes

polyhedron

Page 6: CPSC 335 Trees for spatial data representation and searching

Operations on spatial Operations on spatial objectsobjectsStoredDisplayedManipulatedQueried

Page 7: CPSC 335 Trees for spatial data representation and searching

Examples of applicationsExamples of applications

0 100 Km.

Population, ’96

P o p u la tio n D is tr ib u tio n in A lb e rta , 1 9 9 6 ce n su s

Page 8: CPSC 335 Trees for spatial data representation and searching

Data collectionData collectionfrom GPS (Global Positioning

Systems) – BMP, GIF, GPEG, etc…from existing maps, geometric

(vector) representationfrom experiments (physical,

biological, mechanical) - attributes

generated for experiments – data files text, images)

Page 9: CPSC 335 Trees for spatial data representation and searching

Operations on spatial dataOperations on spatial dataSpatial queries Point locationStabbing query (report all

intervals/polygons contain the point)

Page 10: CPSC 335 Trees for spatial data representation and searching

Spatial queries (2D)Spatial queries (2D)Point query – find an object

containing a point (find a Voronoi region containing a point)

Window query – find an object overlapping a rectangle

Spatial join – join parts of objects satisfying some relationship (intersection, adjacency, containment)

Page 11: CPSC 335 Trees for spatial data representation and searching

OverviewOverview

Spatial data structuresInterval treesK-d treesGrids and Grid files using B-treesR-trees

Page 12: CPSC 335 Trees for spatial data representation and searching

Interval treesInterval trees

Geometric, 1-dimensional tree Interval is defined by (x1,x2) Split at the middle (5), again at the middle (3,7),

again at the middle (2,8) All intervals intersecting a middle point are stored

at the corresponding root (sorted).

1 2 3 4 5 6 7 8 9

(4,6) (4,8)

(6,9)

(7.5,8.5)

(2,4)

Page 13: CPSC 335 Trees for spatial data representation and searching

Interval treesInterval treesFinding intervals – by finding x1, x2

against the nodesFind interval containing specific value

– from the rootSort intervals within each node of the

tree according to their coordinatesCost of the “stabbing query”– finding

all intervals containing the specified value is O(log n + k), where k is the number of reported intervals.

Page 14: CPSC 335 Trees for spatial data representation and searching

ConstructionConstruction We start by taking the entire range of all the

intervals and dividing it in half at x_center (in practice, x_center could be picked as MEDIAN to keep the tree relatively balanced).

This gives three sets of intervals, those completely to the left of x_center which we'll call S_left, those completely to the right of x_center which we'll call S_right, and those overlapping x_center which we'll call S_center.

The intervals in S_left and S_right are recursively divided in the same manner until there are no intervals left.

The intervals in S_center that overlap the center point are stored in a separate data structure linked to the node in the interval tree.

Page 15: CPSC 335 Trees for spatial data representation and searching

Resulting tree data Resulting tree data structurestructureThe result is a binary tree with each node

storing:A center point A pointer to another node containing all

intervals completely to the left of the center point

A pointer to another node containing all intervals completely to the right of the center point

All intervals overlapping the center point sorted by their beginning point

All intervals overlapping the center point sorted by their ending point

Page 16: CPSC 335 Trees for spatial data representation and searching

Interval Tree using Interval Tree using MEDIANMEDIANLet I:={[x1:x1’], [x2:x2’], …, [xn:xn’]}

be a set of closed intervals. Let xmid be the Median of the 2n

interval endpoints◦At most half of the interval endpoints

lies to the left of xmid and at most half to the right.

Then the resulting Interval Tree is more Balanced than standard Interval Tree

Page 17: CPSC 335 Trees for spatial data representation and searching

Example of interval tree Example of interval tree using Medianusing Median

Page 18: CPSC 335 Trees for spatial data representation and searching

PropertiesPropertiesAn interval tree for a set I of n

intervals use O(n) storage and can be built in O(nlogn) time.

Using the interval tree we can report all intervals that contain a query point in O(logn+k) time, where k is the number of reported intervals.

Page 19: CPSC 335 Trees for spatial data representation and searching

OverviewOverview

Spatial data structuresInterval treesK-d treesGrids and Grid files using B-treesR-trees

Page 20: CPSC 335 Trees for spatial data representation and searching

K-d treeK-d treeUsed for point location and

multiple database quesries, k –number of the attributes to perform the search

Geometric interpretation – to perform search in 2D space – 2-d tree

Search components (x,y) interchange!

Page 21: CPSC 335 Trees for spatial data representation and searching

K-d treeK-d tree K-d tree a space-partitioning data structure for

organizing points in a k-dimensional space. The kd-tree is a binary tree in which every node is a

k-dimensional point. Every non-leaf node generates a splitting hyperplane that divides the space into two subspaces. Points left to the hyperplane represent the left sub-tree of that node and the points right to the hyperplane by the right sub-tree.

The hyperplane direction is chosen in the following way: every node split to sub-trees is associated with one of the k-dimensions, such that the hyperplane is perpendicular to that dimension vector. So, for example, if for a particular split the "x" axis is chosen, all points in the subtree with a smaller "x" value than the node will appear in the left subtree and all points with larger "x" value will be in the right sub tree.

Hyperplane direction ROTATES over all k dimensions!

Page 22: CPSC 335 Trees for spatial data representation and searching

K-d tree exampleK-d tree example

a

c

b

ed

d

b

f

f

c a e

Page 23: CPSC 335 Trees for spatial data representation and searching

K-d tree constructionK-d tree construction The canonical method of kd-tree construction is: As one moves down the tree, one cycles (rotates) through

the axes used to select the splitting planes. (For example, the root would have an x-aligned plane, the root's children would both have y-aligned planes, the root's grandchildren would all have z-aligned planes, the next level would have an x-aligned plane, and so on.)

Points are inserted by selecting the median of the points being put into the subtree, with respect to their coordinates in the axis being used to create the splitting plane.

This method leads to a balanced kd-tree, in which each leaf node is about the same distance from the root.

Note also that it is not required to select the median point. In that case, the result is simply that there is no guarantee that the tree will be balanced. A simple heuristic to avoid coding a complex linear-time median-finding algorithm nor using an O(n log n) sort is to use sort to find the median of a fixed number of randomly selected points to serve as the cut line. Practically this technique often results in nicely balanced trees.

Page 24: CPSC 335 Trees for spatial data representation and searching

OverviewOverview

Spatial data structuresInterval treesK-d treesGrids and Grid files using B-treesR-trees

Page 25: CPSC 335 Trees for spatial data representation and searching

Progressive MeshesProgressive Meshes

Developed by Hugues Hoppe, Microsoft Research Inc. Published first in SIGGRAPH 1996.

Page 26: CPSC 335 Trees for spatial data representation and searching

Terrain visualization Terrain visualization applicationsapplications

Page 27: CPSC 335 Trees for spatial data representation and searching

Geometric subdivisionGeometric subdivision

Problems with Geometric Subdivisions

Page 28: CPSC 335 Trees for spatial data representation and searching

ROAM principleROAM principle

The basic operating principle of ROAM

Page 29: CPSC 335 Trees for spatial data representation and searching

Quad-tree and Bin-tree for Quad-tree and Bin-tree for ROAM (real-time adaptive ROAM (real-time adaptive mesh)mesh)

Page 30: CPSC 335 Trees for spatial data representation and searching

The gridThe gridFixed grid:Stored as a 2D array, each entry

contains a link to a list of points (object) stored in a grid.

a,b

Page 31: CPSC 335 Trees for spatial data representation and searching

Page overflowPage overflow

Too many points in one grid cell:Split the cell!

Page 32: CPSC 335 Trees for spatial data representation and searching

Grid fileGrid fileExample of a grid file

Page 33: CPSC 335 Trees for spatial data representation and searching

Grid file vs. gridGrid file vs. gridIn a grid file, the index is dynamically

increased in size when overflow happens.

The space is split by a vertical or a horizontal line, and then further subdivided when overflow happens!

Index is dynamically growingBoundaries of cells of different sizes

are stores, thus point and stabbing queries are easy

Page 34: CPSC 335 Trees for spatial data representation and searching

Rectangle indexing with Rectangle indexing with gridsgridsRectangles may share different

grid cellsDuplicates are storedGrid cells are of fixed size

Page 35: CPSC 335 Trees for spatial data representation and searching

The quadtreeThe quadtreeInstead of using an array as an

index, use tree!

Quadtree decomposition – cells are indexed by using quaternary B-tree.

All cells are squares, not polygons.

Search in a tree is faster!

Page 36: CPSC 335 Trees for spatial data representation and searching

Linear quadtreeLinear quadtreeB+ index – actual references to

rectangles are stored in the leaves, saving more space+ access time

Label nodes according to Z or “pi” order

Page 37: CPSC 335 Trees for spatial data representation and searching

Linear quadtreeLinear quadtreeLevel of detail increases as the

number of quadtree decompositions increases!

Decompositions have indexes of a form:00,01,02,03,10,11,12,13, 2,300301 ,302 ,303 ,31 ,32 ,33 ◦Stores as Bplus tree

Page 38: CPSC 335 Trees for spatial data representation and searching

Finer GridFiner Grid

R-treeEach object s decomposed and

stored as a set of rectanglesObject decomposition: Larger

areas of a grid are treated as one element

Raster decomposition: Each smaller element s stored separately

Page 39: CPSC 335 Trees for spatial data representation and searching

R-treesR-treesR-tree

◦ Objects are grouped together according to topological properties not a grid.

◦ More flexibility.

R * tree- Optimizes◦ Node overlapping◦ Areas covered by the node

R+ tree – B+ tree, bounding rectangles do not intersect

Page 40: CPSC 335 Trees for spatial data representation and searching

ConclusionsConclusions

Spatial data structures such as Interval trees K-d trees Grids and Grid files using B-trees R-trees are used in variety of applications.

They are often balanced, good for searching, DB queryng, spatial queryng and utilize Index and B tree concepts.