Grid and quad-tree indexes

Source: Internet
Author: User

Grid index-point elements (elements), line and surface elements, with Redundancy

Quadtree indexes-line and surface elements with Redundancy

Improved quad-tree indexes-line and plane Elements

R tree -- space overlap

I,Grid index and quad-Tree Index

Before introducing spatial indexes, let's talk about what is "Index". Index a dataset to improve the efficiency of searching the dataset. The "directory" of the book is the "Index" of the book content. When we get a new book and want to view the content we are interested in, we will first check the directory, determine the pages on which the content you are interested in will be directly directed to those pages, and it will be OK, instead of starting from chapter 1, looking for the content you are interested in with one word at a time, until it is found, the efficiency of such retrieval content is too low. If a book has no directory, you can imagine how inconvenient it is... It can be seen how important a book's directory is, and how important an index is!

Now everyone has a perceptual knowledge of indexes. What is "spatial index ?" The spatial index is also an index, which is a directory for the spatial graph set, improving the efficiency of searching for a certain graphic object in this graph set. For example, we select a rectangle on a map layer to determine which elements on the layer are completely contained by the rectangle. Without a "spatial index, we will take all the elements on this layer one by one and use it to carry out geometric inclusion judgment with this rectangle to determine which elements are completely included in this rectangle. Do you think this is reasonable? Otherwise, let's look at a grid index example:

 

 

We have made a mesh index on this vertex layer to determine which points are in this rectangular selection box. We do not need to include all the points in this layer with the rectangle, only the seven vertices A, B, C, D, E, F, and g are computed. It can be inferred that if a point layer has 100,000 points and no spatial index is set up, any map operation will traverse all the elements of the entire layer, that is to say, we need to create a for loop for 0.1 million times. Creating an index will reduce the number of for loops a lot, and the efficiency will naturally increase!

Haha... I think everyone knows the advantages of spatial indexes, and I have introduced the grid indexes of point layers. What other common spatial indexes are there? How can we implement these spatial indexes? With this problem, the following describes several common spatial indexes.

Grid index
A grid index is a map layer that uses a uniform grid based on the width of each small grid △w and the height △h to calculate the grid occupied by each element or the set of grid units passing through,

In these grid units, the address or reference of the meta object is recorded. For example, declaring an object's two-dimensional array list grid [m] [N]; M indicates the number of rows in the grid, N indicates the number of columns in the grid. Each array element is a "set object", which is used to store the addresses or references of all elements associated with the grid unit. In this way, the grid index is established. Next, how should we use this grid index? All graphic display and operations can be improved with the help of "spatial index. Here are a few examples to illustrate the use of "spatial index:

1. Enlarge the window display. As described in the previous section, when we draw a rectangle on the map to enlarge the map, first, determine which elements need to be displayed on the enlarged map on the screen? Therefore, we need to determine which elements in the map are in the rectangle in whole or in part. Judgment steps:

1. Determine the grid array elements in the upper left corner and lower right corner of the rectangle to obtain all the grid sets associated with the rectangle;

2. traverse the elements in the grid set and obtain the elements recorded in each grid element list;

3. Just draw these elements. (Of course, the whole process involves two points: 1. The screen coordinates and map coordinates are transformed each other; 2. The window is cut or not)

 

2. include judgment: a vertex point and a polygon are given to determine whether the vertex is in the surface. First, judge whether the vertex is in the grid and associated with the polygon. If not, it indicates that the point is not within the plane. If yes, you can accurately parse the geometric judgment in the next step or determine that the polygon contains the point if the precision permits.

In addition, Google map should also adopt the geographic grid method to index map images. As a result, it can be seen that grid indexes are widely used in graphic display, selection, and Topology judgment. However, there are also serious defects: When the element object to be indexed is a line or a polygon, there is an index redundancy, that is, the reference of a line or polygon is recorded in multiple grids. As the number of redundancy increases, the efficiency decreases significantly. Therefore, many students have proposed various methods to improve the mesh index, which will be described in the following chapter. Point elements are very suitable for grid indexing, and there is no redundancy problem.

Quadtree Indexes)

Similar to the grid index described above, it also divides the geographical space into a grid, and uses four points for the geographical space recursion to build a quad-tree. This article will base on the general quad-tree, this article introduces an improved quad-tree index structure. First, we will introduce a GIS (Geographic Information System) or a very important concept in computer graphics-MBr-Minimum bounding rectangle ):

The minimum outsourcing rectangle MBR is the smallest external rectangle that is enclosed in elements and parallel to X and Y axes. What is the use of MBR? Why should this concept be introduced? This is because the shape of the elements is irregular, while MBR is a regular image parallel to X and Y axes. Imagine if all the elements are rectangles parallel to X and Y axes, is it much simpler to make any geometric judgment on such a rectangle? Regardless of whether we write formula algorithms or program programs by ourselves, isn't it much simpler than the original complex graphic geometric operations? The answer is clear.

Next, let's take a look at the GIS spatial operation steps (I forgot to explain this step before, and I will add it here)

It can be seen that in the filtering phase, some elements that obviously do not meet the conditions can be excluded through spatial indexes, and the post-selected collection can be obtained. Then, the post-selected element set can be accurately computed to obtain the final result. You may have such questions. Is this necessary? Does it complicate the problem? A suitable spatial index can only improve the efficiency of computers without spatial indexes. Therefore, we need to perform precise geometric operations on each element in the Set, which is complex, it is very CPU-consuming, so it requires a space index, taking a small amount of memory and simple cup operations, to minimize the number of precise high-consumption operations, this is completely worthwhile. The following section describes how to perform precise geometric operations on the complexity of precise geometric operations. Here we will introduce the spatial indexes in the filtering phase.

Now, let's take a look at the "quad-Tree Index ".

 

The quad-tree index recursively divides the geographic space into four points until it is set to terminate (for example, if the number of elements associated with each node is no more than three, and the number of elements is more than three, the next four points will be added ), finally, a layered quad-tree is formed. In the figure, the rectangle with numerical IDS is the MBR of each element. Each leaf node stores the list of elements associated with the region and the geographical range of the region, non-leaf nodes only store the geographical range of the region. You can find that there is also a metadata identifier associated with multiple regions and stored on multiple leaf nodes, such as the elements represented by "6, they are stored on four branches. In this way, indexes are redundant, which has the same drawbacks as grid indexes. Next we will introduce an improved quad-tree index, or a layered grid index.

The improved quad-tree index is used to avoid the redundancy of spatial indexes. The basic idea of improvement is to make the MBR of each element a minimum area.Full inclusion.

 

It can be seen that 3 and 13 Both span two regions. To be completely included by a minimum region, they can only be the region represented by the root node, and 2 and 5 span the two regions, 6 spans four regions. To be fully contained by a minimum region, only the NW region is required. How can we determine which smallest area of an element is fully contained? Intuitively, the geographic space is recursively divided into four points. If the element and the division line of a region are intersection, the element will belong to this area, or it will not be divided until it is no longer divided, that is the region that is no longer divided. Haha... It may be a bit difficult. Look at the picture and combine the two words "minimum" and "Full inclusion", you will understand. In this quad-tree, metadata identifiers are not only stored on leaf nodes, but can be stored on each node, thus avoiding index redundancy. Each node also stores the geographic range of the current node.

With the quad-tree index, how can we use this tree to help search? Select a rectangle as an example! (Why do I always use this example? This example is simple, easy to understand, and representative !) We draw a rectangle on the map to determine which elements on the map fall into the rectangle or intersect the rectangle. There are many methods. Here is a simple retrieval procedure, as shown below:

1. First, add the elements associated with the root node to a list from the root node of the quad-tree;

2. Compare whether the rectangle range has an intersection (intersection or inclusion) with the four subnodes (or sub-areas) of the root node. If yes, then, the metadata associated with the corresponding region is added to the list set. If no, the following subtree is not considered.

3. recursion of the above process until the leaf node of the tree ends, the list is returned.

4. Retrieve the elements from the list set according to the identifiers one by one. First, judge whether the MBR and the rectangle have an intersection. If so, perform the following precise geometric judgment. If not, this element is not considered. (Of course, there is only one basic idea here, but there are some other different methods, for example, there will be some adjustments to the physical storage combined with spatial data disks)

Conclusion: The improved quad-tree index solves the problem of line and area object index redundancy and has good performance. It is used by large spatial database engines, such as ArcSDE and Oracle spatial, at the same time, this structure is also suitable for disk indexes of spatial data. In combination with spatial sorting clustering, the data organization based on the Hilbert Algorithm Based on fragment will play a major role in the definition of spatial data formats.

Grid and quad-tree indexes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.