Docsity

Spatial Indexing & Querying: Multi-Attribute Indexing & Nearest Neighbor Queries - Prof. H, Study notes of Data Structures and Algorithms

Toggle sidebar
bg1
nn0
Copyright © 1998 Hanan Samet
These notes may not be reproduced by any means (mechanical or elec-
tronic or any other) without the express written permission of Hanan Samet
RANKING IN SPATIAL DATABASES
GÍSLI R. HJALTASON
HANAN SAMET
COMPUTER SCIENCE DEPARTMENT AND
CENTER FOR AUTOMATION RESEARCH AND
INSTITUTE FOR ADVANCED COMPUTER STUDIES
UNIVERSITY OF MARYLAND
COLLEGE PARK, MARYLAND 20742-3411 USA
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16

Partial preview of the text

Download Spatial Indexing & Querying: Multi-Attribute Indexing & Nearest Neighbor Queries - Prof. H and more Study notes Data Structures and Algorithms in PDF only on Docsity!

Copyright © 1998 Hanan Samet

These notes may not be reproduced by any means (mechanical or elec- tronic or any other) without the express written permission of Hanan Samet

RANKING IN SPATIAL DATABASES

GÍSLI R. HJALTASON

HANAN SAMET

COMPUTER SCIENCE DEPARTMENT AND

CENTER FOR AUTOMATION RESEARCH AND

INSTITUTE FOR ADVANCED COMPUTER STUDIES

UNIVERSITY OF MARYLAND

COLLEGE PARK, MARYLAND 20742-3411 USA

RANKING PROBLEM

  • Ex: Find all the houses in the database in the order of their distance from location p or object o
  • Ex: Find the nearest city of population greater than 30,000 to Portland, Maine
  • If we use an index on the locational attributes corresponding to the location of the cities, then we want to obtain the cities in the order of their distance from Portland, Maine
  • The process ceases once the condition on the non- locational population attribute is satisfied
  • Query is also a partial ranking query
  • We are interested in a solution where if the closest record does not satisfy our query, then we can get the next clos- est record by continuing from where we last left off rather that having to restart from the reference point of the index
  • Used in browsing applications
    1. can restrict query region
    2. can vary nature of features retrieved as well as query object
    3. can serve as basis of incremental spatial join operations
  • Our solution is illustrated by an example spatial index making use of a disjoint decomposition (e.g., PR quad- tree) although implemented for other spatial indexes including R-trees

SPATIAL DATABASES

  • Distinguished from conventional databases, in part, by fact that some of the attributes are locational in which case they have a common dimensional unit which is distance in space
    1. distance unit is the same whether we are in one, two, or three dimensions, etc.
    2. if combine attributes and seek to find nearest record of type t to Chicago, then unit is distance regardless of whether there are one, two, three, ... (or even more) locational attributes associated with t
    3. nearest is not meaningful for combinations of non- locational attributes
    4. not all attributes with type distance are locational (e.g., size corresponding to pant length, height, waist, etc.)
  • Spatial databases are differentiated by the type of records that they store
    1. points (e.g., locations of features)
      • zero volumetric measure
      • discrete
    2. features (i.e., space occupied by the features)
      • nonzero volumetric measure (i.e., extent)
      • continuous
  • Records in a conventional database are always discrete
    1. can be viewed as points in a higher dimensional space
    2. difference is that for spatial attributes, dimensional unit is always distance in space

ORDERING DATA

  • Use a combination of the values of the locational attributes
  • Facilitates storage of records
  • Desirable for ordering to preserve proximity — i.e., records close to each other in the multidimensional space should also be close to each other in the ordering
  • Hashing is a way of achieving ordering
    1. explicit order
      • mapping from higher dimensional space to one- dimensional space
      • e.g., bit interleaving (Morton order), Peano-Hilbert, Sierpinski, etc.
      • result is a space-filling curve
      • no order has property that ALL records that are close to each other in the multidimensional space of the locational attributes are also close to each other in the range of the mapping
    2. implicit order
      • bucketing methods
      • sort records on the basis of the space they occupy and group into cells or buckets of finite capacity

nn

R-TREES

Objects grouped into hierarchies, stored in another structure such as a B-tree

Object has single bounding rectangle, yet area that it spans may be included in several bounding rectangles

Does not result in disjoint decomposition of space

a

b

c

d

e

f

g

h

i

1 b

Order ( m , M ) R-tree

  1. between m M /2 and M entries in each node except root
  2. (^) at least 2 entries in root unless a leaf node

2 r

R

R

R R

R3: a^ b R4: d g h R5: c^ i R6: e f

3 z

R3 R4 R5 R

R

R

R1: R2:

4 g

R0: R1 R

R

nn SEARCHING FOR A POINT OR LINE SEGMENT IN AN R-TREE

1 b

a b d g h c i e f

R1 R

R3 R4 R5 R

a

b

c

d

e

f

g

h

i

R

R R

R2 R

R

Q

May have to examine many nodes since a line segment can be contained in the covering rectangles of many nodes yet its record is contained in only one leaf node (e.g., i in R2, R3, R4, and R5)

Ex: Search for a line segment containing point Q

R3: R4: R5: R6:

R1: R2:

R0:

R

Q is in R

2 v

Q can be in both R1 and R

3 r

4 z

Searching R1 first means that R4 is searched but this leads to failure even though Q is part of i which is in R

5 g

Searching R2 finds that Q can only be in R

UNIFORM GRID

  • Ideal for uniformly distributed data
  • Supports set-theoretic operations
  • Spatial data (e.g., line segment data) is rarely uniformly distributed

PM1 QUADTREE

  • Vertex-based (one vertex per block)

a b

c

d

e

f

g

h

i

DECOMPOSITION RULE:

Partitioning occurs when a block contains more than one segment unless all the segments are incident at the same vertex which is also in the same block

  • Shape independent of order of insertion

PR QUADTREE

  • Decompose space until just one point per block

(52,10) Mobile

(62,77) Toronto

(82,65) Buffalo (5,45) Denver (27,35) Omaha (85,15) Atlanta

(35,42) Chicago

(90,5) Miami

A

B

D (^) F Toronto

C E

Buffalo Denver

Chicago Omaha Atlanta Miami

Mobile

BOTTOM-UP SOLUTION

  • Algorithm:
    1. locate block b containing query object q
    2. find nearest feature o by examining adjacent neighboring blocks of b in clockwise order
  • Depending on nature of the distance metric (e.g., Euclidean) may have to visit block not immediately adjacent to b
  • Obtain neighbors using neighbor-finding techniques which don’t restart search at root of the tree
  • Especially fast if nearest feature is in a brother of b
  • Worst case requires visiting all of the blocks around the node
  • If need to find the next closest feature, then have to restart search from the beginning rather than from where last left off

ALGORITHM REQUIREMENTS

  • Features can be of arbitrary type (points, rectangles, polygons, etc.)
  • Must have a distance function between:
    1. query object type and the feature type stored in the index ( feature metric )
    2. query object type and the container block type ( block metric )
  • Two distance functions must be consistent with each other
    1. means that for a feature f with distance d ( f , q )= s , then there must exist a block b containing f such that d ( b , q ) ≤ s
    2. always true if both distance functions are based on the same metric
      • e.g., Euclidean, Manhattan, Chessboard
    3. also implies that distance from a query object to the block that contains it is zero
  • Works in any dimension
  • Location of the query object q need not be in the space spanned by the dataset (e.g., outside a window whose features are to be ranked with respect to q )

(^1) nn16nn b ALGORITHM IncNearest(QueryObject,SpatialIndex)

  1. Queue ← NewPriorityQueue()
  2. Block ← RootBlock(SpatialIndex)
  3. Enqueue(Queue,Dist(Block,QueryObject),Block)
  4. while not IsEmpty(Queue) do
  5. Element ← Dequeue(Queue)
  6. if Element is a spatial object then
  7. while Element = First(Queue) do DeleteFirst(Queue)
  8. Report Element
  9. else if Element is a leaf block then
  10. for each Object in leaf block Element do
  11. if Dist(Object,QueryObject) ≥
  12. Dist(Element,QueryObject) then
  13. Enqueue(Queue,Dist(Object,QueryObject),Object)
  14. else /* Element is a non-leaf container block */
  15. for each Child block of container block Element
  16. in SpatialIndex do
    1. Enqueue(Queue,Dist(Child,QueryObject),Child)

2 r

  1. Lines 1-3 initialize the priority queue

3 z

  1. Line 8 reports a feature
    • coroutine-like behavior as control will resume here to get the next nearest

4 g

  1. Line 11 ensures that features that have already been reported are not put on the queue again
    • to work properly, blocks must be retrieved from the queue before spatial features at the same distance
    • otherwise, a feature at the same distance as the block might be retrieved again after the block has been processed and we would not know that it had already been reported

5 v

  1. Line 7 eliminates duplicate instances of a feature from the queue
    • possible for disjoint feature decompositions (e.g., PMR quadtree, R+-tree)
  • duplicates are in front by virtue of having an ordering on the queue
  • more efficient than checking for membership in queue

COMPARISON WITH OTHER WORK

  • Not more efficient than similar methods of Arya/Mount and Hoel/Samet
  • Works with arbitrary data structures including R-trees
  • Arya/Mount make use of a k-d tree along with a priority queue but the results of their complexity analysis only hold for an approximate answer
  • Unlike Arya/Mount we are not restricted to point features
  • Compare with algorithm of Roussopoulos/Kelley/Vincent
    1. restricted to R-trees
    2. restricted to points as query objects
    3. k is fixed a priori
      • need to restart algorithm if want the k +1 nearest neighbors
      • maybe don’t need all k neighbors
  • Algorithm of Hoel/Samet is only good for finding nearest neighbor

ANALYSIS

  1. Assume constant time to calculate distance metric
    • true for point query objects but not necessarily for more complex features such as polygons
  2. Assume a PMR quadtree
    • for line data, O ( N ) blocks for N lines
  3. Assume spatial index exists and thus ignore cost of building it
  4. Worst case queue size arises when:
    • all features in queue are at a distance of at least d from q , and
    • all leaf blocks containing the features are at a dis- tance less than d from q
    • implies all features are inserted into the queue before finding the nearest one — i.e., O ( N ) space
    • if must rank all features, then O ( N log M ) execution time a. M is maximum queue size b. O ( N log N ) worst-case time which compares favorably with one-dimensional sorting
    • circular feature configuration is only bad if query object is at the center of the circle
    • highly unlikely for both the features to be in a circle and the query object to be at its center