46
Geoinformation 3 1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 11 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

Embed Size (px)

Citation preview

Page 1: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

Geoinformation31 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 2011

Geoinformation III

Punkt-in-Polygon-Verfahren III

(R/R+-Baum)

Vorlesung 4

Page 2: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

• Punkt-in-Polygon-Suche II• MBR – minimum bounding

rectangle• Idee• Neues laufendes Beispiel• Rechtecke• Rechtecke mit R-Baum• R-Baum• R-Baum als B-Baum• Der R-Baum als solcher• Einfügen in einen R-Baum• Strategien zum Spalten

eines Knotens• Suchen eines Knotens

1

Übersicht

• Nachteil des R-Baums• Alternative: Der R+-Baum• R+-Baum• Suche im R+-Baum

Page 3: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

R-Baum

• Bisher:– Zerlegung der Maschen in Streifen– Konstruktion einer Suchstruktur

• Alternatives Vorgehen:• Approximation der Maschen durch umschließende

achsenparallele Rechtecke – Minimal Bounding Rectangle (MBR)– Verwaltung der Rechtecke

• R-Baum• R+-Baum

2

Page 4: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

MBR – minimum bounding rectangle

A 4x

yAußen

x

3

Page 5: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

Idee

• In welcher Masche M liegt der Punkt P?• Nutze die Bounding Boxes als Filter

• Verwende effizientes Verfahren, um alle Rechtecke R1, ... Rn zu finden, die P enthalten

– Jedem Rechteck Ri entspricht eine Masche Mi

• Prüfe, ob P in einer der Maschen M1, ... Mn vorkommt

• Verwende dazu das Standardverfahren• Problem: Zugriffsstruktur für Rechtecke• Rechtecke sind einfacher zu handhaben als Maschen im

allgemeinen

4

A 1x

Page 6: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

Neues laufendes Beispiel

• Nur die Rechtecke interessieren uns hier, nicht die zugrundeliegenden Maschen

A 1x

4

Page 7: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

A 4x

Rechtecke mit R-Baum

B

D

G

J F

CI

E H

A

3 4

1 2

A I E H

5

B C D

6

J F G

6

4

21

35

5

Page 8: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

Rechtecke mit R-Baum

A 4x

A

I

3

A I

3

5

Page 9: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

Rechtecke mit R-Baum

A 4x

A

I

3

A I

3

E H

4

4

E H

5

Page 10: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

Rechtecke mit R-Baum

A 4x

A

I

3

A I

3

E H

4

4

E H

B

D

G

J F

CI 1 2

B C D J F G

6

2

5

5 6

5

Page 11: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

A 21x

R-Baum

A

1 2

B

D

G

J F

CI

12

E H

A

6

Page 12: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

A 21x

R-Baum

A

1 2

B

D

G

J F

CI

12

E H

A

3

A I

3

6

Page 13: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

A 21x

R-Baum

A

1 2

B

D

G

J F

CI

12

E H

A

3

A I

3 4

4

E H

6

Page 14: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

A 21x

R-Baum

A

1 2

B

D

G

J F

CI

12

E H

A

3

A I

3 4

4

E H

5

B C D

5

6

Page 15: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

A 21x

R-Baum

A

1 2

B

D

G

J F

CI

12

E H

A

3

A I

3 4

4

E H

5

B C D

56

6

J F G

6

Page 16: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

A 21x

R-Baum

A

1 2

B

D

G

J F

CI

12

E H

A

3

A I

3 4

4

E H

5

B C D

56

6

J F G

6

Page 17: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

R-Baum als B-Baum

• Ein R-Baum ist ein B-Baum mit zusätzlichen Eigenschaften• B-Baum

– Ein B-Baum ist (wie der AVL-Baum) ausgeglichen– Besonders gut für Hintergrundspeicher (Festplatte), innere Knoten

entsprechen „Kacheln“ des Sekundärspeichers– Alle Informationen stehen in den Blättern– Alle Blätter haben das gleiche Niveau– Alle inneren Knoten außer der Wurzel sind mindestens zur Hälfte

gefüllt– Teilung beim Überlauf eines inneren Knoten – Verteilung auf Nachbarn beim Unterlauf

7

Page 18: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

B-Baum

Ein kleiner Exkurs:

Der B-Baum wurde nach seinem Entwickler R. Bayer benannt.

Die Suche eines Elementes in einem B-Baum unterscheidetsich nur wenig von der Suche in anderen Such-Bäumen.

Das Einfügen und Entfernen von Elementen ist jedoch anvielen Stellen anders als in Binär-Such-Bäumen.

8

Page 19: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

B-Baum

• Eigenschaften eines B-Baumes der Ordnung n:– Ein B-Baum ist nicht binär– Ein B-Baum ist ausgeglichen– Alle Blätter haben das gleiche Niveau– Jeder Knoten enthält höchstens 2n Elemente– Jeder innere Knoten außer der Wurzel enthält mindestens n Elemente– Jeder innere Knoten hat m+1 Nachfolgeknoten, wobei m die Anzahl der

Schlüssel des inneren Knotens ist– Die m Schlüssel eines inneren Knotens werden in aufsteigender

Reihenfolge gespeichert: x1 < x2 < ... < x3

– Für jeden i-ten Teilbaum Si eines Knotens gilt:Die Schlüssel seiner Knoten sind grösser als xi und kleiner als xi+1 (ganz links und ganz rechts analog)

– Bei einigen Varianten des B-Baums stehen alle Informationen in den Blättern

9

Page 20: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

2 9 12

13 15 171 233

29 48

19

10 37 567

B-Baum

! Alle Knoten bestehen aus 4 Blättern, auch wenn sie im Folgenden nicht dargestellt sind ! 56

=

10

A 1x

Page 21: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

Einfügen

• Einfügen eines Elements mit dem Wert 18 (Idealfall)

A 26x

2 9 12

13 15 171 3

19

107 23

29 48

37 56

18 < 19 linker Ast18 > 12 rechter Ast18 > 17 Einfügen

18

2 9 12

13 15 171 3

19

107 23

29 48

37 56

11

Page 22: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

18

Einfügen

• Einfügen eines Elements mit dem Wert 14 (Problemfall)

A 26x

2 9 12

13 15 171 3

19

107 23

29 48

37 56

14 < 19 linker Ast14 > 12 rechter Ast

2 9 12

13 15 171 3

19

107 23

29 48

37 5618

Problem: Speicher voll

Lösung: Knoten sprengen

11

Page 23: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

Setze das mittlere Element um einePosition nach oben

Bilde zwei neue Zweige

Einfügen

A 26x

• Einfügen eines Elements mit dem Wert 14

2 9 12

13 14 15 171 3 107

19

23

29 48

37 5618

15

151514 151817 1518

11

Page 24: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

Das Löschen in einem B-Baum gestaltet sich sehr einfach. Wir unterscheiden hier folgende Fälle:

1. Löschen in einem Blatt: Einfaches Löschen 2. Löschen in einem inneren Knoten:

Beachte: die Anzahl der Schlüssel der inneren Knoten muss mindestens n sein Wie bei AVL-Bäumen den Eintrag ersetzen durch den Rechtesten Eintrag im linken Unterbaum oder den Linkesten im Rechten.

Entfernen

12

A 5x

Page 25: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

Entfernen

• Entfernen des Elements mit dem Wert 48

A 5x

2 9 12

13 15 171 3

19

107 23

29 48

27 31 37 49 60

Keine n Elemente im

Knoten Ersetzen durch den rechtesten Eintrag im linken Unterbaum

37

12

Page 26: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

Der R-Baum als solcher

• Ein Blattknoten ist ein Paar (R,O), R ist das kleinste Rechteck, welches das Objekt O umschließt

• Jeder innere Knoten hat n Paare (R,P)– P zeigt auf einen Teilbaum– R ist das kleinste umschließende Rechteck dieses Teilbaums

Beachte• Rechtecke können sich überlappen• Struktur des R-Baums hängt von Reihenfolge des Einfügens ab• Jedes Paar (R,O) kommt genau einmal vor• R kann mehrere umschließenden Rechtecke schneiden

13

Page 27: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

Einfügen in einen R-Baum

• Ausgangspunkt: Einfügen eines neuen Knotens in einen R-Baum• Problem hier: an welche Stelle wird (R,O) eingefügt?

– Durchlaufe den R-Baum mit der Wurzel als Ausgangspunkt– Wähle an jedem inneren Knoten den Teilbaum, der durch

Einfügen von R minimal vergrößert würde– Füge (R,O) schließlich als Blatt ein– Beim Überlauf verfahre wie beim B-Baum

• Besonderheit gegenüber B-Baum:– Es gibt keine lineare Ordnung zwischen den Einträgen der Knoten– Verschiedene Strategien zum Spalten eines Knotens

14

Page 28: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

Strategien zum Spalten eines Knotens

A 5x

Minimierung des DurchschnittsMinimierung der Gesamtfläche

15

Page 29: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

Suchen eines Knotens

A 13x

E H

A

B

D

G

J F

CI

3 4

1 2

A I E H

5

B C D

6

J F G

6

4

21

35

In welchem

R liegt Q?

16

Page 30: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

Suchen eines Knotens

A 13x

E H

A

B

D

G

J F

CI

3 4

1 2

A I E H

5

B C D

6

J F G

6

4

21

35

16

Page 31: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

Suchen eines Knotens

A 13x

E H

A

B

D

G

J F

CI

3 4

1 2

A I E H

5

B C D

6

J F G

6

4

21

35

16

Page 32: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

Suchen eines Knotens

A 13x

E H

A

B

D

G

J F

CI

3 4

1 2

A I E H

5

B C D

6

J F G

6

4

21

35

16

Page 33: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

Suchen eines Knotens

A 13x

E H

A

B

D

G

J F

CI

3 4

1 2

A I E H

5

B C D

6

J F G

6

4

21

35

16

Page 34: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

Suchen eines Knotens

A 13x

E H

A

B

D

G

J F

CI

3 4

1 2

A I E H

5

B C D

6

J F G

6

4

21

35

16

Page 35: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11 17

Nachteil des R-Baums

• Um das richtige Blatt zu finden, sind meist mehrere Durchläufe erforderlich

• Dies gilt insbesondere dann, wenn die Suche erfolglos ist• Abhilfe: R+-Baum

Page 36: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11 18

Alternative: Der R+-Baum

• Alle inneren Rechtecke sind disjunkt• Ein Objekt / umschließendes Rechteck kann in mehreren

Blättern vorkommen• Jedes Blatt repräsentiert den Teil von (R,O), der von dem

Vaterknoten umschlossen wird

Page 37: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11 19

R+-Baum

E H

A

B

D

G

J F

CI

12

3

4

5

6

7

8

9

2 31

4 5

A E D E H

6 7

B D I B C D

8 9

E G F J

A 34x

Page 38: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

R+-Baum

A 34x

1 2

E H

A

B

D

G

J F

CI

12

19

Page 39: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

R+-Baum

A 34x

1 2

E H

A

B

D

G

J F

CI

12

33

4

A E

4

19

33

Page 40: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

R+-Baum

A 34x

1 2

E H

A

B

D

G

J F

CI

12

33

4

A E

4

5

D E H

5

19

Page 41: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

R+-Baum

A 34x

1 2

E H

A

B

D

G

J F

CI

12

33

4

A E

4

5

D E H

5

6

6

B D I

19

Page 42: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

R+-Baum

A 34x

1 2

E H

A

B

D

G

J F

CI

12

33

4

A E

4

5

D E H

5

6

6

B D I

7

7

B C D

19

Page 43: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

R+-Baum

A 34x

1 2

E H

A

B

D

G

J F

CI

12

33

4

A E

4

5

D E H

5

6

6

B D I

7

7

B C D

88

E G

19

Page 44: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

R+-Baum

A 34x

1 2

E H

A

B

D

G

J F

CI

12

33

4

A E

4

5

D E H

5

6

6

B D I

7

7

B C D

88

E G

9

9

F J

19

Page 45: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

R+-Baum

A 34x

1 2

E H

A

B

D

G

J F

CI

12

33

4

A E

4

5

D E H

5

6

6

B D I

7

7

B C D

88

E G

9

9

F J

19

Page 46: Geoinformation3 1234567891012131415161718192011 Geoinformation III Punkt-in-Polygon-Verfahren III (R/R + -Baum) Vorlesung 4

1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20Geoinformation3

11

Suche im R+-Baum

A 6x

E H

A

B

D

G

J F

CI

12

3

4

5

6

7

8

9

2 31

4 5

A E D E H

6 7

B D I B C D

8 9

E G F J

20