Reference: http://blog.csdn.net/zhouxuguang236/article/details/12312099
The original blog address and C + + source ...
The basic idea of Quadtree index is to divide the geographical space recursively into different levels of tree structure. It divides the space of the known range into four equal subspace, so recursively, until the level of the tree reaches a certain depth or satisfies a certain requirement and stops splitting. The structure of Quadtree is relatively simple, and when spatial data objects are distributed more evenly, it has high efficiency of spatial data inserting and querying, so Quadtree is one of the commonly used spatial indexes in GIS. The structure of the regular Quadtree, geospatial objects are stored on the leaf node, and the middle node and the root node do not store geospatial objects.
Four-fork Tree
Quadtree is more efficient for regional queries. However, if the spatial objects are unevenly distributed, with the continuous insertion of geospatial objects, the level of quadtree will continue to deepen, will form a serious imbalance of the four-fork tree, then the depth of each query will be greatly increased, resulting in a sharp decline in query efficiency.
This section describes an improved four-fork tree index structure. Quadtree structure is a tree-like hierarchy that is gradually divided from top to bottom. The traditional four-fork Tree index has several drawbacks:
(1) The space entity can only be stored in the leaf node, the middle node and the root node can not store the spatial entity information, with the continuous insertion of the space object, will eventually lead to a four-fork tree tree hierarchy is deep, in the Spatial Data window query efficiency will be relatively low.
(2) It is very likely that the same geographic entity will be stored in multiple nodes during the division of Quadtree, resulting in a waste of index storage space.
(3) Because geospatial objects may be unevenly distributed, this can result in the regular quadtree generating an extremely unbalanced tree, which can also result in the imbalance of tree structure and waste of storage space.
The corresponding improved method is to store geographic entity information in the smallest rectangular node that completely contains it, not in its parent node, where each geographic entity is stored only once in the tree, avoiding wasted storage space. The first generation of a four-fork tree avoids the need to reallocate memory when a geographic entity is inserted, speeds up the insertion, and finally frees up the empty node's memory space. The improved four-fork tree structure is shown. The depth of the quadtree is generally the best between the XP values of 4-7.
Figure improved four-fork tree structure
In order to maintain spatial indexes and the consistency of spatial data stored in a file or database, the author designs The following data structure to support quadtree operations.
(1) Four sub-regional identification
The four sub-region index numbers of a planar area are defined, the first quadrant is 0, the upper left is the second Quadrant 1, the lower left is the third Quadrant 2, and the lower right is the fourth Quadrant 3.
typedef enum
{
ur = 0,//ur first quadrant
UL = 1,//ul for second quadrant
LL = 2,//ll for the third quadrant
LR = 3//LR for fourth quadrant
}quadrantenum;
(2) Spatial object data structure
The spatial object data structure is approximate to the geospatial object, and in the spatial index, a considerable part of it is using MBR as approximation.
/* Spatial object MBR information */
typedef struct SHPMBRINFO
{
int NID; Spatial Object ID Number
Maprect Box; Spatial object MBR range coordinates
}shpmbrinfo;
Nid is the identification number of the spatial object, and box is the smallest outsourced rectangle (MBR) of the spatial object.
(3) Four fork tree node data structure
Quadtree node is the main component of quadtree structure, which is mainly used to store space object's identification number and MBR, and is also the main part of Quadtree algorithm operation.
/* Four fork tree node type structure */
typedef struct QUADNODE
{
Maprect Box; The rectangular area represented by the node
int nshpcount; The number of all spatial objects that the node contains
shpmbrinfo* Pshapeobj; Array of spatial object pointers
int nchildcount; Number of child nodes
Quadnode *children[4]; Four children pointing to a node
}quadnode;
box is the smallest bounding rectangle representing the corresponding area of the quadtree, and the minimum bounding rectangle of the upper node contains the next layer of the smallest bounding rectangle; Nshpcount represents the number of spatial objects that this node contains; Pshapeobj represents the first address that points to the storage address of a space object. The spatial objects of the same node are stored continuously in memory; Nchildcount represents the number of child nodes owned by the node; Children is an array of pointers to child nodes.
Note: The original blog address also has C + + source ...
[Map Development] [Algorithm and data structure] principle of four-fork tree