A method for spatial range query based on HQuadTree
By combining Hilbert curves and the HQuadTree index structure of Quadtree, and employing a depth-first approach combined with a limited breadth-first expansion strategy, the problem of excessively coarse query granularity is solved, improving the efficiency and accuracy of spatial range queries.
Patent Information
- Application Number
- CN202510026197.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-08
- Publication Date
- 2025-10-21
- Estimated Expiration
- 2045-01-08
AI Technical Summary
Existing spatial range query algorithms have too coarse a granularity, resulting in query results containing a large number of objects that are not within the query range, thus reducing query efficiency.
The HQuadTree index structure, which is a combination of Hilbert curve and Quadtree, is used to perform spatial range queries through a depth-first combined with limited breadth expansion strategy to reduce the number of invalid objects returned.
It effectively improves query efficiency, reduces the number of invalid objects returned, and enhances query accuracy and speed.
Smart Images

Figure CN119829690B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a spatial range query method based on HQuadTree, belonging to the field of spatial database and information retrieval. Related knowledge includes: computer technology, database technology, information retrieval technology, etc. Background Art
[0002] Given a spatial dataset D consisting of a series of objects O containing coordinate information, each object has a unique identifier O.ID, with object ID values ranging from 0, 1, ..., |D|-1. A spatial range query involves finding all objects O∈D∧O∈q in the dataset D that meet the query conditions, given a query area q represented by the lower left coordinates P1 = (x1, y1) and the upper right coordinates P2 = (x2, y2). For example, in a map service, users can specify an area to find points of interest (such as restaurants and gas stations) within that area.
[0003] Spatial range queries are a key operation in spatial databases and geographic information systems (GIS), widely used in fields such as geographic data processing, computer vision, and mobile computing. However, with the increasing volume of spatial data and the high precision required for queries, spatial range queries require efficient data structures and algorithms to improve query performance. Traditional index structures such as R-trees, R*-trees, and quadtrees, when used with large datasets or high query precision, often return a large number of objects that are not within the region. This significantly reduces query efficiency when validating these invalid objects.
[0004] Therefore, in big data processing and geographic information systems, coarse-grained spatial range queries are usually used. By dividing spatial data into larger areas, coarse-grained queries can reduce the details that need to be checked, thereby improving query efficiency. In addition, it can quickly exclude irrelevant areas, reduce computing and storage overhead, and improve system performance and response speed. In recent studies, SFC-Quad and ARM-SQ implement coarse-grained queries by returning the object with the smallest node containing the query area. However, the query granularity of the above algorithms is too coarse, resulting in the query results containing a large number of objects that are not within the query range, thereby reducing query efficiency. To solve the above problem, the present invention designs a novel index HQuadTree that combines Hilbert curve and Quadtree. It organizes nodes based on the Hilbert curve and establishes the consistency of the Hilbert curve. On this basis, a spatial coarse-grained range query algorithm (HQuadTree-SQ) based on HQuadTree is implemented. Summary of the Invention
[0005] The purpose of the present invention is to provide a spatial range query method based on HQuadTree, aiming to solve the technical problem that the query granularity of the existing algorithm is too coarse, resulting in the query results containing a large number of objects that are not within the query range, thereby reducing the query efficiency.
[0006] To achieve the above objectives, the technical solution of the present invention is: a spatial range query method based on HQuadTree. First, the Hilbert curve and Quadtree are combined to construct a new index structure HQuadTree. HQuadTree organizes nodes based on the Hilbert curve, thereby establishing consistency between HQuadTree and Hilbert curve. Based on HQuadTree, given a query q, a depth-first combined with limited breadth expansion strategy is used during the query to perform moderate drilling down on the spatial range query, which can effectively reduce the number of invalid object IDs returned, thereby improving query efficiency. The specific steps include:
[0007] Step 1: In the spatial index construction phase, given a spatial dataset D, construct an index structure HQuadTree that combines the Hilbert curve and QuadTree;
[0008] Step 2: In the spatial range query phase, given a query q, a coarse-grained spatial range query is implemented based on the created index structure HQuadTree. The ID ranges corresponding to all nodes intersecting with q are queried in the dataset D and stored in the result set RS.
[0009] The Step 1 is specifically as follows:
[0010] Step 1.1: Constructing the Hilbert curve state view: The Hilbert curve maps multidimensional data onto a one-dimensional integer domain. Its first-order states are divided into four states based on the direction of the curve opening: 0 (opening downward), 1 (opening to the left), 2 (opening upward), and 3 (opening to the right). Given a first-order state value, the corresponding coordinate values in the four states and the next-order state are as follows:
[0011] State 0: physical coordinates: (0,0), (0,1), (1,1), (1,0); next-order states: 1, 0, 0, 3;
[0012] State 1: physical coordinates: (0,0), (1,0), (1,1), (0,1); next-order states: 0, 1, 1, 2;
[0013] State 2: physical coordinates: (1,1), (1,0), (0,0), (0,1); next-order state: 3, 2, 2, 1;
[0014] State 3: physical coordinates: (1,1), (0,1), (0,0), (1,0); next-order states: 2, 3, 3, 0;
[0015] Step 1.2: Object ID reassignment: Renumber the objects in dataset D in the order of Hilbert code values, and assign IDs ranging from 0 to |D|-1;
[0016] Step 1.3: HQuadTree construction: Construct the spatial index structure HQuadTree that combines Hilbert curve and QuadTree;
[0017] Step 1.3.1: Node structure: Each node N of HQuadTree contains the following attributes: N.IDR: represents the object ID interval contained in the current node, N.IDR[0] and N.IDR[1] represent the lower and upper bounds of the corresponding ID interval respectively; N.Leaf indicates whether it is a leaf node; N.Region: is the region represented by the node N, which is a spatial region represented by the lower left corner coordinate P1 = (x1, y1) and the upper right corner coordinate P2 = (x2, y2); N.State: represents the Hilbert state of the current node N.
[0018] Step 1.3.2: The root node of the HQuadTree structure represents the entire data space. Each non-leaf node N contains four children, representing the four equal divisions of the spatial region corresponding to N. During the construction process, the order and state of the four child nodes are determined based on the node's N.State, so that the i-th child node N.Ni of node N corresponds to the i-th quadrant in Hilbert space, ensuring consistency between the HQuadTree and the Hilbert curve.
[0019] The Step 2 is specifically as follows:
[0020] Step 2.1: Query the smallest node containing q: Starting from the root node N of HQuadTree, determine whether q is contained in a child node N of N i If so, recursively determine whether q is included in N i In a child node of , otherwise N i That is, the smallest node containing q, record this node as MCN, and let the depth d of the node corresponding to MCN = 0.
[0021] Step 2.2: Because the object interval (IDR) of an MCN node may be large, a limited m-level drill-down is performed. Drilling down returns the IDR intervals of the child nodes of the MCN that intersect with q, which can effectively narrow the IDR range. Since there may be multiple IDR intervals after drilling down, these intervals are stored in I and adjacent IDRs are merged to reduce the number of intervals.
[0022] Step 2.3: When drilling down, based on the depth-first search, a limited breadth expansion is performed. First, a stack S is introduced. Initially, the MCN node N and its level d = 0 are pushed onto the stack (i.e., S.push(N,0)). Then, Steps 2.3.1 to 2.3.2 are executed.
[0023] Step 2.3.1: If the stack is not empty, pop the top node N and its level d. If N satisfies the following conditions: 1) d = m; 2) N is a leaf node; 3) N is contained in q, then there is no need to drill down further. Let maxID denote the maximum ID of the last IDR in I. If N.IDR[0] - maxID = 1, merge it into the last IDR of I and update maxID←N.IDR[1]. Otherwise, add N.IDR to I, i.e., I←I∪N.IDR, and update maxID←N.IDR[1].
[0024] Step 2.3.2: If the top node N does not meet the above conditions, use the following steps to detect N's child node N i Whether (i∈{1,2,3,4}) intersects with q, thus drilling down the query to level d=d+1. To reduce the number of intersection judgments during detection, the following two steps are performed according to the level of the current node N:
[0025] Step 2.3.2.1: When d=0, that is, when the current top node of the stack is MCN node N, the FSFO strategy is used for intersection judgment: First, the intersection judgment of q with N's child nodes N1 and N2 is performed, and f i When it represents node N i The flag indicating whether it intersects with q is 1 if it intersects, and 0 if it does not intersect. When f1 and f2 are not all 1, we can directly obtain f3 = f1, f4 = f2, otherwise f4 = f3 = O(N.N3,q).
[0026] Step 2.3.2.2: When d>1, that is, when the current top node N is a non-MCN node, that is, when d>0, FSFO is used. +The strategy for intersection judgment is: first, perform intersection judgment on q with N1 and N2. If f1f2=11, then continue to perform coverage judgment on N3; if f1f2=00, then continue to judge whether q and N3 intersect. If f3=1, then further judge N4; if f1f2=10 or f1f2=01, then it is necessary to add coverage judgment on N4 or N3.
[0027] Step 2.3.3: Set f i = 1 and its depth d are pressed into S;
[0028] Step 2.4: Region Verification: After the above steps, we obtain an object interval I consisting of multiple segments. Then, we traverse each segment in I and check whether the coordinates of each object O lie within the rectangular query box q. If so, we add it to the result set RS, i.e., RS←RS∪{O}.
[0029] The present invention provides an HQuadTree-based spatial range query method. During index construction, the Hilbert curve and QuadTree are combined to create an HQuadTree index. During query execution, given a query q, a depth-first approach combined with a limited breadth expansion strategy is employed to perform moderate drill-down on the spatial range query, effectively reducing the number of invalid objects returned. Furthermore, to avoid the number of intersection checks during the drill-down process, a fast intersection check strategy is proposed to reduce the number of checks, thereby improving query efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] Figure 1 is a flow chart of the steps of the present invention;
[0031] Figure 2 These are the four states of the first-order Hilbert curve of the present invention;
[0032] Figure 3 This is a spatial distribution diagram of example data of the present invention;
[0033] Figure 4 HQuadTree index created for the example data of this invention. DETAILED DESCRIPTION
[0034] In order to make the objectives, technical solutions and advantages of the present invention more clear, the embodiments of the present invention will be further described in detail below with reference to the accompanying drawings and examples.
[0035] Example 1: Figure 1 As shown in Figure 1, a spatial range query method based on HQuadTree is shown in Figure 1. The specific steps are as follows:
[0036] Given the example dataset shown in Table 1, the spatial distribution of the sample dataset is as follows Figure 3 As shown, given query q=<(3,2),(6,3)>, as Figure 3 As shown in the red rectangle.
[0037] Table 1 Sample data
[0038]
[0039] Spatial range query includes Step 1: constructing the index HQuadTree and Step 2: using the spatial range query method based on the HQuadTree. Specifically:
[0040] Step 1: Spatial index construction phase, which combines the Hilbert curve with the quadtree to construct a quadtree structure (HQuadTree) that is consistent with the order of the Hilbert curve;
[0041] Step 1.1: Hilbert curve state view construction: The Hilbert curve is a curve that maps multidimensional data to a one-dimensional integer domain. Its first-order state is divided into the following according to the opening direction of the curve: Figure 2 The four states shown are: 0 (opening downward), 1 (opening to the left), 2 (opening upward), and 3 (opening to the right). Given a 1st-order state value, the corresponding coordinate values in the 4 states and the next-order state are as follows:
[0042] State 0: physical coordinates: (0,0), (0,1), (1,1), (1,0); next-order states: 1, 0, 0, 3;
[0043] State 1: physical coordinates: (0,0), (1,0), (1,1), (0,1); next-order states: 0, 1, 1, 2;
[0044] State 2: physical coordinates: (1,1), (1,0), (0,0), (0,1); next-order state: 3, 2, 2, 1;
[0045] State 3: physical coordinates: (1,1), (0,1), (0,0), (1,0); next-order states: 2, 3, 3, 0;
[0046] Step 1.2: Object ID reassignment: Renumber the objects in dataset D in the order of Hilbert code values, and assign IDs ranging from 0 to |D|-1.
[0047] Step 1.3: HQuadTree construction: Construct the spatial index structure HQuadTree that combines Hilbert curve and QuadTree;
[0048] Step 1.3.1: Node structure: Each node N of HQuadTree contains the following attributes: N.IDR: represents the object ID interval contained in the current node, N.IDR[0] and N.IDR[1] represent the lower and upper bounds of the corresponding ID interval respectively; N.Leaf indicates whether it is a leaf node; N.Region: is the region represented by the node N, which is a spatial region represented by the lower left corner coordinate P1 = (x1, y1) and the upper right corner coordinate P2 = (x2, y2); N.State: represents the Hilbert state of the current node N.
[0049] Step 1.3.2: The root node of the HQuadTree structure represents the entire data space. Each non-leaf node N contains four children, representing the four equal divisions of the spatial region corresponding to N. During the construction process, the order and state of the four child nodes are determined based on the node's N.State, so that the i-th child node N.Ni of node N corresponds to the i-th quadrant in Hilbert space, ensuring consistency between the HQuadTree and the Hilbert curve.
[0050] Given the sample data set in Table 1, the constructed HQuadTree is as follows Figure 4 As shown, the root node's four children divide the entire Hilbert space into four equal parts, with each node representing a quadrant of the entire Hilbert space. Because the root node's state is 0, its four children are arranged in the order SW, NW, NE, and SE. The root node's first child (the blue circle) corresponds to the lower-left quadrant of the Hilbert region. Because its state is 1, its four children are arranged in the order SW, SE, NE, and NW.
[0051] Step 2: Given a query q, implement a coarse-grained spatial range query based on the created index HQuadTree. Query the ID ranges (IDR) corresponding to all nodes that intersect with q in the dataset D and store them in the result set RS.
[0052] Step 2.1: Query the smallest node containing q: Starting from the root node N of HQuadTree, determine whether q is contained in a child node N of N i If so, recursively determine whether q is included in N i In a child node of , otherwise N i That is, the smallest node containing q, record this node as MCN, and let the depth d of the node corresponding to MCN = 0.
[0053] like Figure 4 , starting from the root node, find the smallest node that contains the query area, which is the root node.
[0054] Step 2.2: Because the object interval (IDR) of an MCN node may be large, a limited m-level drill-down is performed. Drilling down returns the IDR intervals of the child nodes of the MCN that intersect with q, which can effectively narrow the IDR range. Since there may be multiple IDR intervals after drilling down, these intervals are stored in I and adjacent IDRs are merged to reduce the number of intervals.
[0055] Step 2.3: When drilling down, based on the depth-first search, a limited breadth expansion is performed. First, a stack S is introduced. Initially, the MCN node N and its level d = 0 are pushed onto the stack (i.e., S.push(N,0)). Then, Steps 2.3.1 to 2.3.2 are executed.
[0056] Step 2.3.1: If the stack is not empty, pop the top node N and its level d. If N satisfies the following conditions: 1) d = m; 2) N is a leaf node; 3) N is contained in q, then there is no need to drill down further. Let maxID denote the maximum ID of the last IDR in I. If N.IDR[0] - maxID = 1, merge it into the last IDR of I and update maxID←N.IDR[1]. Otherwise, add N.IDR to I, i.e., I←I∪N.IDR, and update maxID←N.IDR[1].
[0057] Step 2.3.2: If the top node N does not meet the above conditions, use the following steps to detect N's child node N i Whether (i∈{1,2,3,4}) intersects with q, thus drilling down the query to level d=d+1. To reduce the number of intersection judgments during detection, the following two steps are performed according to the level of the current node N:
[0058] Step 2.3.2.1: When d=0, that is, when the current top node of the stack is MCN node N, the FSFO strategy is used for intersection judgment: First, the intersection judgment of q with N's child nodes N1 and N2 is performed, and f i When it represents node N i The flag indicating whether it intersects with q, 1 means intersecting, 0 means not intersecting. When f1 and f2 are not all 1, we can directly obtain Otherwise f4=f3=O(N.N3,q).
[0059] Step 2.3.2.2: When d>1, that is, when the current top node N is a non-MCN node, that is, when d>0, FSFO is used. +The strategy for intersection judgment is: first, perform intersection judgment on q with N1 and N2. If f1f2=11, then continue to perform coverage judgment on N3; if f1f2=00, then continue to judge whether q and N3 intersect. If f3=1, then further judge N4; if f1f2=10 or f1f2=01, then it is necessary to add coverage judgment on N4 or N3.
[0060] Step 2.3.3: Set f i = 1 and its depth d are pressed into S;
[0061] like Figure 3 Given q = <(3,2), (6,3)>, we know that MCN is the root node, and the corresponding object interval IDR is [0,12]. When drilling down to layer l1, calling the FSFO algorithm to obtain N.N1 and N.N4 and q to cover the final I is {[0,3], [9,12]}. The returned ID range is smaller than the IDR [0,12] corresponding to directly using MCN. When drilling down further to layer l2, we get [1,2] (corresponding Figure 4 Left-center oblique line area), [9,9] (corresponding to Figure 4 Middle horizontal line area), [10,11] (corresponding Figure 4 Because the maximum ID of the second IDR and the minimum ID of the third IDR are adjacent, they can be merged, and the final return value is {[1,2],[9,11]}. When drilling down to level 13, the two IDRs [2,2] and [9,11] are returned.
[0062] Step 2.4: Region Verification: After the above steps, we obtain an object interval I consisting of multiple segments. Then, we traverse each segment in I and check whether the coordinates of each object O are within the rectangular query box q. If they are, we add them to the result set RS, i.e., RS←RS∪{O}.
[0063] For a given dataset and query region q, when m = 2, the candidate set C = {1, 2, 9, 10, 11} obtained from Step 2.3 is verified. It is found that the coordinates of the objects with IDs 1 and 9 are not in q, so the result set RS = {2, 10, 11} is finally returned.
[0064] The above describes the specific embodiments of the present invention in detail with reference to the figures and tables, but the present invention is not limited to the above embodiments. Various changes can be made within the knowledge of ordinary technicians in this field without departing from the purpose of the present invention.
Claims
1. A spatial range query method based on HQuadTree, characterized by: Step 1: In the spatial index construction phase, given a spatial dataset D, construct an index structure HQuadTree that combines the Hilbert curve and QuadTree; Step 2: In the spatial range query phase, given a query q, a coarse-grained spatial range query is implemented based on the created index structure HQuadTree. The ID ranges corresponding to all nodes intersecting with q are queried in the dataset D and stored in the result set RS. The Step 2 is specifically as follows: Step 2.1: Query the smallest node containing q, starting from the root node N of HQuadTree, determine whether q is contained in a child node N of N i If so, recursively determine whether q is included in N i In a child node of , otherwise N i That is, the smallest node containing q, record this node as MCN, and let the depth of the node corresponding to MCN be d=0; Step 2.2: Drill down to a limited m-level on the MCN node. Drill down to return the object interval IDR of the child nodes of the MCN that intersects with q, narrow the IDR range, use I to store the multiple IDR intervals after drilling down, and merge adjacent IDRs to reduce the number of intervals. Step 2.3: When drilling down, based on the depth-first search, perform limited breadth expansion. First, introduce a stack S. Initially, push the MCN node N and its level d = 0 onto the stack, and then execute Step 2.3.1 to Step 2.3.
2. Step 2.3.1: If the stack is not empty, pop the top node N and its level d if N satisfies the following conditions: 1) ; 2) N is a leaf node; 3) If N is included in q, there is no need to drill down further. Let maxID represent the maximum ID of the last IDR in I. If N.IDR[0]-maxID=1, merge it into the last IDR of I and update ; Otherwise, add N.IDR to I and update ; Step 2.3.2: If the top node N does not meet the above conditions, check N's child node N i Whether it intersects with q, i∈{1,2,3,4}, so as to drill down the query to the d=d+1 layer. According to the level of the current node N, the following two steps are performed to reduce the number of intersection judgments: Step 2.3.2.1: When d=0, the current top node of the stack is MCN node N, and the FSFO strategy is used for intersection judgment: First, the intersection judgment of q with N's child nodes N1 and N2 is performed, and f i Represents node N i The flag of whether it intersects with q, where 1 means intersecting and 0 means not intersecting. When f1 and f2 are not all 1, directly obtain , ,otherwise ; Step 2.3.2.2: When d>1, the current top node N is a non-MCN node and FSFO is used. + The strategy for intersection judgment: First, make an intersection judgment between q and N1 and N2. If , then continue to judge the coverage of N3; if , then continue to judge whether q and N3 intersect. If Then further judge ;like or When N4 or N3 coverage judgment is required, Step 2.3.3: Set f i = 1 and its depth d are pressed into S; Step 2.4: Get the object interval I consisting of multiple segments. Then, traverse each segment in I in turn and check whether the coordinates of each object O are within the rectangular query box q. If so, add it to the result set RS.
2. A spatial range query method based on HQuadTree according to claim 1, characterized in that: The Step 1 is specifically as follows: Step 1.1: Construct a Hilbert curve state view. The Hilbert curve maps multidimensional data to a one-dimensional integer domain. Its first-order state is divided into four states based on the direction of the curve opening: 0 opens downward, 1 opens to the left, 2 opens upward, and 3 opens to the right. Given a first-order state value, the coordinate values of the corresponding four states and the next-order state are as follows: State 0: physical coordinates are (0,0), (0,1), (1,1), (1,0); next-order states: 1, 0, 0, 3; State 1: physical coordinates are (0,0), (1,0), (1,1), (0,1); next-order states: 0, 1, 1, 2; State 2: physical coordinates are (1,1), (1,0), (0,0), (0,1); next-order states: 3, 2, 2, 1; State 3: physical coordinates are (1,1), (0,1), (0,0), (1,0); next-order states: 2, 3, 3, 0; Step 1.2: Reassign object IDs. Renumber the objects in dataset D in the order of Hilbert code values. The assigned IDs range from 0 to ; Step 1.3: Construct the spatial index structure HQuadTree that combines the Hilbert curve and QuadTree.
3. A spatial range query method based on HQuadTree according to claim 2, characterized in that: The specific steps of Step 1.3 are as follows: Step 1.3.1: Each node N of HQuadTree contains the following attributes: N.IDR: indicates the object ID interval contained in the current node. N.IDR[0] and N.IDR[1] respectively indicate the lower and upper bounds of the corresponding ID interval. N.Leaf indicates whether it is a leaf node. N.Region: The region represented by node N, which is a region with the lower left corner coordinates and the upper right corner coordinates The spatial region represented; N.State: represents the Hilbert state of the current node N; Step 1.3.2: The root node of the HQuadTree structure represents the entire data space. Each non-leaf node N contains four children, representing the four equal divisions of the spatial region corresponding to N. During the construction process, the order and state of the four child nodes are determined according to the node's N.State, so that the i-th child node N.Ni of node N corresponds to the i-th Quadrant in the Hilbert space.
Citation Information
Patent Citations
Spatio-temporal data indexing method in non-relational database
CN107423368A
Efficient space keyword query method based on association rule mining
CN116501775A