Data Structure Notes: PR Quadtree

1 Basic introduction

In the PR quadtree, each node represents a rectangular area, and each node either has no child nodes or has four child nodes, representing the four quadrants of the rectangular area.

2 Data structure

Each node of a PR quadtree usually contains the following elements:

  • Area (rectangle): the two-dimensional space range represented by the node.
  • Point: The point stored within the area (usually only one point is allowed to be stored, but there are variations).
  • Four sub-nodes: represent the upper left, upper right, lower left, and lower right quadrants respectively.

3 insert

  1. Start from the root node.
  2. Determine whether the point to be inserted is within the area of ​​the current node.
  3. If so, check whether the current node has stored points.
    • If not, store this point.
    • If so, divide the current area into four quadrants, and then put the current point and the new point into the corresponding quadrants.
  4. Do this process recursively.

3.1.1 Examples

Suppose we have the following points: (1, 1), (2, 2), (3, 3), and we want to use a PR quadtree to store them in a 4x4 area

  • Initial state:
  • insert(1,1)
    • Store directly in the root node
  • insert(2, 2)
    • Split the root node into four 2x2 regions. Put (1, 1) into the lower left area and (2, 2) into the upper right area
  • insert(3,3)
    • Also placed on the upper right, but since the upper right already has a point (2, 2), it is divided again

Reference content: GIS spatial database (21) PR quadtree index | Mala GIS (malagis.com)

Guess you like

Origin blog.csdn.net/qq_40206371/article/details/132700235