M - Intranet - Department of Computer Science: Login

intranet.cs.aau.dk

M - Intranet - Department of Computer Science: Login

SW6Database Systems (DBS)17. Spatial Databases II (Spatial Queries)Hua LuDepartment of Computer ScienceAalborg UniversitySpring 20111


• Nearest Neighbor Queries• Distance Metrics in R-treeAgenda• Branch-and-Bound NN Search• Best-First NN Search• Spatial Join• Summary2


Stadt StühlingenH 14aLandkreis Waldshut Az.: 767.32§ 9 Gemeindevorstand1. Die Verwaltung der Jagdgenossenschaft wurde nach § 6 Abs. 5 LJagdG für unbestimmte Zeit aufden Gemeindevorstand übertragen. Gemeindevorstand ist der Gemeinderat. DerGemeindevorstand vertritt die Jagdgenossenschaft gerichtlich und außergerichtlich.2. Der Gemeindevorstand kann entsprechend den Vorschriften der Gemeindeordnung denBürgermeister und Dritte mit der Erledigung von Aufgaben aus seinem Zuständigkeitsbereichbeauftragen.§ 10 Aufgaben des Gemeindevorstands1. Der Gemeindevorstand hat die Interessen der Jagdgenossenschaft im Rahmen des § 3wahrzunehmen. Er ist an die Beschlüsse der Versammlung der Jagdgenossen gebunden, soweitsich diese im Rahmen der Gesetze halten.2. Der Gemeindevorstand ist befugt, in eigener Zuständigkeit dringende Angelegenheiten zuerledigen und unaufschiebbare Geschäfte zu vollziehen.3. Der Gemeindevorstand hat insbesondere folgende Aufgaben zu erfüllen:a) Einberufung und Leitung der Versammlung der Jagdgenossen,b) Durchführung der Beschlüsse der Versammlung der Jagdgenossen,c) Führung des Haushalts-, Kassen- und Rechnungswesens,d) Führung des Schriftwechsels und Beurkundung von Beschlüssen,e) Vornahme der Bekanntmachungen bzw. ortsüblichen Bekanntgaben,f) Verpachtung des gemeinschaftlichen Jagdbezirks,g) Entscheidung über das Einvernehmen zum Abschussplan,h) Abrundung des gemeinschaftlichen Jagdbezirks.§ 11 Verzeichnis der Jagdgenossen (Jagdkataster)1. Der Gemeindevorstand hat ein Verzeichnis aller Mitglieder der Jagdgenossenschaft(Jagdgenossen), unter Angabe der jeweiligen Grundflächenanteile am gemeinschaftlichenJagdbezirk (Jagdkataster), zu erstellen.2. Das Verzeichnis ist jeweils mindestens vor der Einberufung einer neuenJagdgenossenschaftsversammlung fortzuschreiben.§ 12 Verfahren bei der JagdverpachtungDer gemeinschaftliche Jagdbezirk wird durch freihändige Vergabe und Verlängerung laufenderPachtverträge verpachtet.§ 13 Abschussplanung1. Der Gemeindevorstand legt den vom / von den Jagdausübungsberechtigten für das kommendeJagdjahr (§ 17), bei Rehwild für die kommenden 3 Jagdjahre, aufgestellten Abschussplan auf dieDauer von einer Woche zur kostenlosen Einsichtnahme für Mitglieder der Jagdgenossenschaft aus.3 Ergänzung 11/2010


Straightforward Solution for NN search• Problem setting• Given a spatial relation R of objects• Given a query point q, find the NN of q in R• Straightforward solution• Compare q with each object in R• Keep track of the object with minimum distance to q• Incurs high cost when the size of R is very large• Our goal: reduce the cost of NN search, by using the R-g htreeefdbcaqkji5


MINDIST Computation• MINDIST(p, R) is the minimum distance between pand R with corner points l and u• the closest point in R is at least this distance awayRll=(l 1 , l 2 , …, l d )u=(u 1 , u 2 , …, u d )upMINDIST = 0pMINDIST ( p,R)pdi1r i = l i , if p i < l i= u i , if p i > u i( p i r i= p i , otherwise2)oR, MINDIST ( p,R) ( p,o)6


MINMAXDIST• MINMAXDIST(p, R) definition• For each dimension, find the closest face, compute the distance to thefurthest point on this face.• Take the minimum of all these (d) distances.• MINMAXDIST(p, R) is the smallest possible upper bound ofdistances from p to R• MINMAXDIST guarantees that there is at least one object in Rwith a distance to p smaller or equal to it.oR, ( p,o) MINMAXDIST ( p,R)MINMAXDISTpR7


MINDIST and MINMAXDIST• MINDIST(p, R) ≤ ||(p, p.NN)|| ≤ MINMAXDIST(p, R)R1MINMAXDISTR3MINDISTMINDISTpMINDISTMINMAXDISTR2MINMAXDIST8


• Nearest Neighbor Queries• Distance Metrics in R-treeAgenda• Branch-and-Bound NN Search• Best-First NN Search• Spatial Join• Summary9


• Downward pruning 1Pruning in NN Search• An MBR R is discarded if there exists another R’ s.t.MINDIST(q, R) > MINMAXDIST(q, R’)• Downward pruning 2• An object o is discarded if there exists an R s.t.the Actual-Dist(q, o) > MINMAXDIST(q, R)• Upward pruning• An MBR R is discarded if an object o is found s.t.MINDIST(q, R) > Actual-Dist(q, o)10


• Downward pruning 1Pruning 1 Example• An MBR R is discarded if there exists another R’ s.t.MINDIST(q, R) > MINMAXDIST(q, R’)RMINDISTqR’MINMAXDIST11


• Downward pruning 2Pruning 2 Example• An object o is discarded if there exists an R s.t.the Actual-Dist(q, o) > MINMAXDIST(q, R)oActual-DistqMINMAXDISTR12


• Upward pruningPruning 3 Example• An MBR R is discarded if an object o is found s.t.MINDIST(q, R) > Actual-Dist(q, o)RMINDISTqActual-DistO13


Ordering Distance• MINDIST is an optimistic distance in the sense that itunderestimates the distances between p and objects inan MBR.• Whereas MINMAXDIST is a pessimistic one, in thesense that it overestimate such distances.MINDISTPMINMAXDIST14


Branch-and-Bound NN Search Algorithm1. Initialize the nearest distance as infinite distance2. Traverse the R-tree depth-first starting from the root. At eachIndex node, sort all MBRs using an ordering metric and putthem in an Active Branch List (ABL).3. Apply pruning rules 1 and 2 to ABL4. Visit the MBRs from the ABL following the order until it isempty5. If Leaf node, compute actual distances, compare with the bestNN so far, update if necessary.6. At the return from the recursion, use pruning rule 37. When the ABL is empty, the NN search returns.• Sorting ABL is not necessary. We can even avoid ABL.15


Branch-and-Bound NN Example (1)108642y a xiseM1fdbcgmm 2m 13ham0 2 4 6 8 10qksearchregionm 5M 24j m 6iM 3o NN = NULLdist(q, o NN )=1. visit rootMINDIST(q,M 1 ) < dist(q,o NN )M1m 1m 2RootM1M 2 M 3 M 2m m m m 3 4 5 6must visit node M 1m 1 m m 2 3f g ha b c d ei j k16


Branch-and-Bound NN Example (2)108642y a xiseM1fdbcgmm 2m 13ham0 2 4 6 8 10qksearchregionm 5M 24j m 6iM 3o NN = NULLdist(q, o NN )=2. visit M 1MINDIST(q, m 1 )


Branch-and-Bound NN Example (3)108642y a xiseM1fdbcgmm 2m 13ha0 2 4 6 8 10M1m 1qm 2km 5M 24j m 6imsearchregionM 3RootM1M 2 M 3 M 2m m m m 3 4 5 6o NN = NULLdist(q, o NN )=3. visit m 1check a,b,cfound new NN:o NN = a, dist(q, o NN ) = 5m 1 m m 2 3f g ha b c d ei j k18


Branch-and-Bound NN Example (4)108642y a xiseM1fdbcgmm 2m 13ha0 2 4 6 8 10M1m 1m 2RootM1M 2 M 3 M 2m m m m 3 4 5 6m 1 m m 2 3f g hqkm 5M 24j m 6imsearchregionM 3o NN = adist(q, o NN )= 5Upward pruning4. backtrack to M 1check m 3MINDIST(q, m 3 ) = 5 5:No need to visit node m 3check m 2MINDIST(q, m 2 ) = 3 5:No need to visit node m 2a b c d ei j k19


Branch-and-Bound NN Example (5)108642y a xiseM1fdbcgmm 2m 13ha0 2 4 6 8 10M1m 1qm 2km 5M 24j m 6imsearchregionM 3RootM1M 2 M 3 M 2m m m m 3 4 5 6o NN = adist(q, o NN )= 55. backtrack to rootcheck M 2MINDIST(q, M 2 ) = 2 < 5:must visit node M 2m 1 m m 2 3f g ha b c d ei j k20


Branch-and-Bound NN Example (6)108642y a xiseM1fdbcgmm 2m 13ha0 2 4 6 8 10M1m 1qm 2km 5M 24j m 6imsearchregionM 3RootM1M 2 M 3 M 2m m m m 3 4 5 6o NN = adist(q, o NN )= 56. visit M 2check m 4MINDIST(q, m 4 ) = 2 < 5:must visit node m 4m 1 m m 2 3f g ha b c d ei j k21


Branch-and-Bound NN Example (7)108642y a xiseM1fdbcgmm 2m 13ha0 2 4 6 8 10M1m 1qm 2km 5M 24j m 6imsearchregionM 3RootM1M 2 M 3 M 2m m m m 3 4 5 6o NN = adist(q, o NN )= 57. visit m 4check i, j, kfound new NN:o NN = k, dist(q, o NN ) = 2m 1 m m 2 3f g ha b c d ei j k22


Branch-and-Bound NN Example (8)108642y a xiseM1fdbcgmm 2m 13ha0 2 4 6 8 10M1m 1m 2RootM1M 2 M 3 M 2m m m m 3 4 5 6m 1 m m 2 3f g hqkm 5M 24j m 6imsearchregionM 3o NN = kdist(q, o NN )= 2Upward pruning8. backtrack to M 2check m 5MINDIST(q, m 5 ) 2:No need to visit node m 5check m 6MINDIST(q, m 6 ) 2:No need to visit node m 6a b c d ei j k23


Branch-and-Bound NN Example (9)y a xis108642eM1fdbcgmm 2m 13haqkm 5M 24j m 6imsearchregionM 3o NN = kdist(q,o NN )= 2Upward pruning9. backtrack to root0 2 4 6 8 10M1m 1m 2RootM1M 2 M 3 M 2m m m m 3 4 5 6m 1 m m 2 3f g hcheck M 3MINDIST(q, M 3 ) 2:No need to visit node M 310. backtrack from rootAlgorithm terminateso NN =k, dist(q,o NN )= 2a b c d ei j k24


k Nearest Neighbor Search• Generalized problem• Given a spatial relation R, a query object q, and a number k


Exercise• Apply the branch-and-bound NN search to the giventhe R-tree and query point q below.• Use ABL sorted on MINDIST• Don’t use ABLA P1BCqFP3A B CP1 P2 P3F GDEP2GD E26


• Nearest Neighbor Queries• Distance Metrics in R-treeAgenda• Branch-and-Bound NN Search• Best-First NN Search• Spatial Join• Summary27


Observation about DF NN search• In the branch-and-bound NN search• The closest entry to q in the current node is “visited” andcontrol is passed to the node pointed by it• However the entries in that node may not be the closestentries to q from those seen so far• In the previous example, point a is visited before thereal NN k• Can we do better?• E.g., avoid visiting node m128


• Idea of BF search:Best-First NN Search• Uses a priority queue to organize seen entries and prioritizethe next node to be visited• Always “visit” the closest one (from the priority queue)• Low cost: optimal in the number of R-tree nodes visited for agiven query q29


• Priority queue QPriority Queue Example• Organize seen entries and prioritize the next node to bevisited• Entry format: tree entry, and distance from q• E.g, Q = M 1 (1), M 2 ( 2), M 3 ( 8)• Supported operations• Top(Q): get the top entry of Q E.g., we get the entry M 1 (1)• Pop(Q): remove the top entry of Q E.g., after Pop(Q), we have Q = M 2 ( 2), M 3 ( 8)• Push(Q, e): insert an entry e into Q Suppose MINDIST(m 4 , q)= 5We use the termproirity queue andheap interchangebly After Push(Q, m 4 ), we have Q = M 2 ( 2), m 4 ( 5), M 3 ( 8)30


Best-First NN Search Example (1)108642y a xiseM1fdbcgmm 2m 13haqkm 5M 24j m 6imsearchregionM 3o NN = NULLdist(q, o NN )=Step 1: put all entries of root on heap QQ = M 1 (1), M 2 ( 2), M 3 ( 8)0 2 4 6 8 10M1m 1m 2RootM1M 2 M 3 M 2m m m m 3 4 5 6MINDIST from qm 1 m m 2 3f g ha b c d ei j k31


Best-First NN Search Example (2)108642y a xiseM1fdbcgmm 2m 13ham0 2 4 6 8 10qksearchregionm 5M 24j m 6iM 3o NN = NULLdist(q,o NN )=Step 2: get closest entry (top element of Q):M 1 (1). Visit node M 1 . Put all M 1 ’s entrieson heap QQ = M 2 ( 2), m 1 ( 5), m 3 ( 5), M 3 ( 8), m 2 (3)M1m 1m 2RootM1M 2 M 3 M 2m m m m 3 4 5 6m 1 m m 2 3f g ha b c d ei j k32


Best-First NN Search Example (3)108642y a xiseM1fdbcgmm 2m 13ha0 2 4 6 8 10M1m 1qm 2km 5M 24j m 6imsearchregionM 3RootM1M 2 M 3 M 2m m m m 3 4 5 6o NN = NULLdist(q,o NN )=Step 3: get closest entry (top element of Q):M 2 ( 2). Visit node M 2 . Put all M 2 ’s entrieson heap QQ =m 4 ( 2), m 1 ( 5), m 3 ( 5), M 3 ( 8), m 2 (3),m 5 ( 13), m 6 (17)m 1 m m 2 3f g ha b c d ei j k33


Best-First NN Search Example (4)108642y a xiseM1fdbcgmm 2m 13ha0 2 4 6 8 10M1m 1qm 2km 5M 24j m 6imsearchregionM 3RootM1M 2 M 3 M 2m m m m 3 4 5 6o NN = NULLdist(q,o NN )=Step 4: get closest entry (top element of Q):m 4 ( 2). Visit node m 4 . m 4 is a leaf node, soupdate NN if some object in m 4 is closer thanthe current NN:o NN = k, dist(q,o NN )= 2Q =m 1 ( 5), m 3 ( 5), M 3 ( 8), m 2 (3),m 5 ( 13), m 6 (17)m 1 m m 2 3f g ha b c d ei j k34


Best-First NN Search Example (5)108642y a xiseM1fdbcgmm 2m 13haqkm 5M 24j m 6imsearchregionM 3o NN = kdist(q,o NN )= 2Step 5: get closest entry (top element of Q):m 1 (5). Since 5 dist(q, o NN )=2, searchstops and returns o NN as the NN of q0 2 4 6 8 10M1m 1m 2RootM1M 2 M 3 M 2m m m m 3 4 5 6m 1 m m 2 3f g ha b c d ei j k35


Notes on Best-First NN Search• In the previous example, fewer nodes are visited whencompared to DF-NN search• Only visit nodes whose MBR intersects the disk centered at qwith radius the real NN distance• I.e., optimal number of node accesses• Adaptable for kNN search• Maintain the best k objects foundso far (like in DF-NN), or• Simply use the incremental search(in the next slide)• However, the worst-case space requirement of thealgorithm is high• The heap may grow large until the algorithm terminates36


Incremental NN search• The user may not know a “suitable” k in advance• After having found the NN, find the next NN without starting searchfrom the beginning• Application 1: find the nearest large city (>10,000 residents) tomy current position• incrementally find NN and check if the large city requirement is satisfied;if not get the next NN• Application 2: find the nearest hotel; see if you like it; if not getthe next one; see if you like it; …• Best-first NN search can be modified for incremental NN search• Once an object is popped from the priority queue, report it as the currentNN.• Do not prune, but continue processing (pop and push operations on thequeue) until k NNs have been reported or the user terminates theprocessing.37


Depth-First Search vs. Best-First SearchNumber of nodeaccessesMemoryrequirementDepth-first searchNumber of nodeaccesses notguaranteed to be theminimumAt most a single pathof tree nodesBest-first searchOptimal number ofnode accessesUnbounded memoryIncremental search Not applicableApplicable38


Exercise• Apply the best-first NN search to the given the R-treeand query point q below.• Report the first NN• Report the next 2 NNsA P1BCqFP3A B CP1 P2 P3F GDEP2GD E39


• Nearest Neighbor Queries• Spatial Join• Definition• Algorithm• SummaryAgenda40


• InputSpatial Join Definition• Two spatial relations R, S (e.g., R=cities, S=rivers)• Output:• {(r, s): rR, sS, r intersects s}• Example: find all pairs of cities and rivers that intersect• We focus on intersection join• They are other types of spatial join• E.g., the distance between r and s is smaller than a threshold• We focus on intersection join here41


Spatial Join Example• Given R=cities and S=rivers, find all pairs of cities andrivers that intersect• Result: {(r1, c1), (r2, c2), (r2, c5)}c 1c 2 c 3c 5c 4r 1 r 2c 1r 1 r 2c 2 c 3c 4c 542


Spatial Join Processing• Problem: Find all forest and river pairs that intersectwith each other.• Straightforward solution:• Nested loop join between the relations R and S• The cost is O(|R|*|S|); it is not scalable• Goal: suppose that both R and S are indexed by R-trees• How to process the join efficiently?• How do we apply the filter/refinement process?ForestsRiversa 1a 2a 3a 4a 5b 1b 2b 3b 443


R-tree (Intersection) Join• Applies on two R-trees of spatial relations R and S• Observation:• If a node n R R does not intersect n S S, then no object o R R under n R can intersect any object o S S under n S• Node MBRs at the high level of the trees can prune objectcombinations to be checked• Utilize this property to traverse synchronously bothtrees, following only entry pairs that intersectn Rn S44


• Nearest Neighbor Queries• Spatial Join• Definition• Algorithm• SummaryAgenda45


R-tree (Intersection) Join Algorithm• Initially, RJ is called with two tree roots as parameters• This pseudo-code version RJ assumes that the treeshave same height• It can be easily extendable to trees of different heights• Just push forward the other for-each loop if leaves are met46


R-tree (Intersection) Join Example• Run for root(R A ), root(R B )• For every intersecting pair there (e.g., A 1 , B 1 ), run recursivelyfor pointed children nodes• Intersecting pairs of leaf nodes may yield qualifying object pairsLevel 1 qualifying pairs:{(A 1 , B 1 ), (A 2 , B 2 )}R AR Bb 1b 2b 3b 4: Forests : RiversA 1A 2B 1B 2b 1b 2b 3b 4Level 0 qualifying pairs from (A 1 , B 1 ):{(a 1 , b 1 ), (a 2 , b 2 )}No qualifying pairs from (A 2 , B 2 ):a 1a 2a 3a 4a 5a 3a 4a 5a 3a 4a 5b 3a b 1 1a 2A 2b b24A 1B 1B 2a 1a 2A 2A 1B 1B 247


Filter-Refinement Steps for Spatial Join• A multi-step process is adopted for leaf pairs• MBR filter: find MBR pairs that intersect• Done by RJ algorithm• Geometric filter: compare some more detailedapproximations to make conclusions (next slide)• Refinement: if still join predicate inconclusive,perform expensive refinement stepDone by computational geometry algorithmsVery fast!Fast!Slow!non-qualifying pair thatpasses the filter step(false hit)qualifying pair48


• Detail approximationGeometric Filtering• Conservative approximationE.g., convex hullFalse hit detection• Progressive approximationE.g., maximum enclosed rectangleTrue hit detectionconvex hullobjectMERconservativeapproximationprogressiveapproximation49


Multi-Step Spatial Join ProcessingR-tree joinfalse hitsRelation 1R*-treecandidatepairsgeometricfiltercand.pairsExactgeometryprocessingRelation 2R*-treehitsresponse set50


References• Thomas Brinkhoff, Hans-Peter Kriegel, BernhardSeeger: Efficient Processing of Spatial Joins Using R-Trees. SIGMOD Conference 1993: 237-246• More details about• CPU time tuning• IO cost tuning• Spatial join of R-trees with different heights51


• Nearest Neighbor QuerySummary• Distance metrics of MBR in R-tree• Depth-first NN search• Best-first NN search• Spatial Join• R-tree intersection join algorithm• Multi-step filter-refinement process52

More magazines by this user
Similar magazines