Spatial index construction query method and system based on two-dimensional points

By constructing a query method based on two-dimensional points, a static fast index tree is built, which solves the performance bottlenecks and construction cost problems of existing technology in large-scale data processing, and realizes efficient query and rapid reuse, which is suitable for large-scale and real-time demand scenarios.

CN119166633APending Publication Date: 2024-12-20WESTERN CHINA SCI CITY INNOVATION CENT OF INTELLIGENT & CONNECTED VEHICLES (CHONGQING) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411159686.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-22
Publication Date
2024-12-20

AI Technical Summary

Technical Problem

The existing spatial indexing technology has high performance bottlenecks and construction and maintenance costs when processing large-scale data sets, especially in scenarios where data distribution is uneven and real-time requirements are high.

Method used

The spatial indexing based on two-dimensional points is adopted to build a static fast index tree, use small memory resources to provide high query efficiency, and formulate an index saving protocol to achieve rapid reuse.

Benefits of technology

It realizes high query efficiency on small memory resources, supports larger point data scale, reaches millions, and can quickly copy and reuse indexes to meet real-time and large-scale data processing needs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119166633A_ABST
    Figure CN119166633A_ABST
Patent Text Reader

Abstract

The invention discloses a spatial index construction query method and system based on two-dimensional points, and relates to the technical field of spatial indexes.The method comprises the steps that an index container is constructed; initializing a message header space, an index space and a coordinate space; sequentially inputting element information needing to be indexed and recording the element information in an index space; judging whether the number of elements in the index container is greater than a threshold value or not, if not, finishing sorting, and generating an index tree; if yes, selecting one coordinate axis as a division direction; selecting a reference number to divide the elements into two parts; judging whether the number of divided elements is greater than a threshold value or not, if not, completing division, and generating an index tree; if yes, the other coordinate axis is selected as the division direction, and the elements of the left part and the elements of the right part are divided respectively; and performing data query by using the index tree. According to the method, data query is realized by constructing a static rapid spatial index, and higher query efficiency can be provided on the basis of occupying smaller memory resources.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of spatial index technology, and in particular to a query method and system for constructing a spatial index based on two-dimensional points. Background Art

[0002] Spatial index is a data structure used to efficiently query spatial data, and is widely used in fields such as geographic information system (GIS), computer graphics, and computer-aided design (CAD). The problem that spatial index solves is how to quickly find points within a specified range among a large number of points.

[0003] Traditional spatial indexing technologies include quadtrees, R-trees, KD-trees, etc., each of which has its own advantages and limitations. Quadtree is a tree structure that divides a two-dimensional space into four quadrants. It is suitable for evenly distributed spatial data, but its performance degrades when the data is unevenly distributed. R-tree is a balanced tree structure that can dynamically adjust the depth of the tree and the splitting of nodes. It is suitable for indexing high-dimensional spatial data, but it may encounter performance bottlenecks when processing large-scale data sets. KD tree (K-Dimensional tree) is a tree structure that divides space into K dimensions. It is suitable for quickly retrieving points in K-dimensional space, but its construction and maintenance costs are high.

[0004] Currently, spatial indexes exist in two forms: database-based indexes and memory-based indexes. Database-based spatial indexes rely on the support of database capabilities, which is a double-edged sword. On the one hand, the database's capabilities and resource support can be used to provide convenience and feasibility for applications; on the other hand, they cannot run independently, and some lightweight, high-real-time scenarios are difficult to meet the requirements. Although memory-based spatial indexes have the ability to query quickly, they are insufficient in terms of data volume, memory and computing resource optimization, and index resource reuse. In view of the shortcomings of existing spatial indexing technologies, the present invention proposes a query method and system for constructing a spatial index based on two-dimensional points. Summary of the invention

[0005] The present invention provides a query method and system for constructing a spatial index based on two-dimensional points, so as to overcome at least one technical problem existing in the prior art.

[0006] In one aspect, the present invention provides a query method based on a spatial index of two-dimensional points, comprising:

[0007] Construct an index container and input the capacity of the index container;

[0008] Determine whether the capacity of the index container meets a first predetermined requirement, if not, the program ends; if the first predetermined requirement is met, initialize the message header space, index space and coordinate space according to the capacity of the index container;

[0009] Input the element information to be indexed in sequence, the element information including the coordinate ID, longitude and latitude; each time the element information is input, determine whether the current state meets the second predetermined requirement, if not, the program ends; if the second predetermined requirement is met, record the coordinate ID in the index space, and record the coordinate longitude and latitude in the coordinate space;

[0010] Determine whether the number of elements meets the third predetermined requirement. If not, the program ends. If it meets, determine whether the number of elements in the index container is greater than a threshold. If not, sorting is completed, an index tree is generated, and the state is changed. If it is greater, select a coordinate axis as a division direction.

[0011] Taking the kth smallest element on the current coordinate axis as a reference number, the element is divided into two parts based on the reference number, namely a left part and a right part;

[0012] Determine whether the number of elements after division is greater than the threshold. If not, the division is completed, an index tree is generated, and the state is changed. If it is greater, another coordinate axis is selected as the division direction, and for the elements on the left and the elements on the right, the steps with the kth smallest element on the current coordinate axis as the base number are returned respectively.

[0013] The index tree is used to perform data query.

[0014] Optionally, determining whether the capacity of the index container meets a first predetermined requirement is specifically:

[0015] Determine whether the capacity of the index container is an integer. If not, it indicates that the capacity of the index container does not meet the first predetermined requirement. If it is an integer, determine whether the capacity of the index container is greater than 0. If not, it indicates that the capacity of the index container does not meet the first predetermined requirement. If greater than 0, it indicates that the capacity of the index container meets the first predetermined requirement.

[0016] Optionally, judging whether the current state meets the second predetermined requirement is as follows:

[0017] Determine whether the current number of elements in the index container exceeds the capacity of the index container. If so, it indicates that the second predetermined requirement is not met. If not, determine whether the index space contains the ID of the current input coordinates. If so, it indicates that the second predetermined requirement is not met. If not, it indicates that the second predetermined requirement is met.

[0018] Optionally, the message header space includes a start bit and the number of leaf nodes, and the number of leaf nodes is used as the threshold.

[0019] Optionally, the elements are divided into two parts based on the reference number, namely a left part and a right part, specifically:

[0020] Based on the current coordinates, elements smaller than the reference number are located on the left side of the reference number as the left part; elements larger than the reference number are located on the right side of the reference number as the right part.

[0021] Optionally, a rectangular query method is used to query data, specifically:

[0022] Enter the coordinates of the rectangular box;

[0023] Determine whether the coordinates of the rectangular frame conform to the rectangular rule. If not, the program ends; if not, determine whether the index tree is generated according to the changed state;

[0024] If the index tree is not generated, the program ends; if the index tree is generated, the index tree is traversed downward from the root node to determine whether the rectangular area corresponding to the current node has a containment relationship with the rectangular frame;

[0025] If there is no containment relationship, the program ends; if there is a containment relationship, recursively query whether the rectangular area corresponding to the left and right subtrees of the current node and the rectangular box have a containment relationship;

[0026] After reaching the leaf node, if the current leaf node is within the rectangular frame, the current leaf node is added to the selection set;

[0027] The selection set formed after finding all the points falling within the rectangular box is the query result data.

[0028] Optionally, a peripheral query method is used to query data, specifically:

[0029] Enter the query point and query range;

[0030] Determine whether the query point and query range entered are legal. If not, the program ends. If legal, determine whether the index tree is generated based on the changed state.

[0031] If the index tree is not generated, the program ends; if the index tree is generated, a circle is generated according to the query point and the query range;

[0032] Traverse the index tree downward from the root node to determine whether the rectangular area corresponding to the current node has a containment relationship with the circle;

[0033] If there is no containment relationship, the program ends; if there is a containment relationship, recursively query whether the rectangular area corresponding to the left and right subtrees of the current node has a containment relationship with the circle;

[0034] After reaching the leaf node, if the current leaf node is within the circle, the current leaf node is added to the selection set;

[0035] The selection set formed after finding all the points falling within the circle is the query result data.

[0036] Optionally, after the index tree is generated, the method further includes: generating an index file using the index tree.

[0037] Optionally, a method of exporting an index file is used to perform data query.

[0038] On the other hand, the present invention also provides a query system based on a spatial index of two-dimensional points, comprising:

[0039] A construction module, used for constructing an index container and inputting the capacity of the index container;

[0040] A first judgment module, used to judge whether the capacity of the index container meets a first predetermined requirement, and if not, the program ends; if the first predetermined requirement is met, the message header space, the index space and the coordinate space are initialized according to the capacity of the index container;

[0041] The input module is used to sequentially input the element information to be indexed, wherein the element information includes the ID, longitude and latitude of the coordinates; after each input of the element information, it is determined whether the current state meets the second predetermined requirement, and if the second predetermined requirement is not met, the program ends; if the second predetermined requirement is met, the ID of the coordinates is recorded in the index space, and the longitude and latitude of the coordinates are recorded in the coordinate space;

[0042] The second judgment module is used to judge whether the number of elements meets the third predetermined requirement. If not, the program ends; if it meets, it is judged whether the number of elements in the index container is greater than the threshold. If not, the sorting is completed, the index tree is generated, and the state is changed; if it is greater, a coordinate is selected as the division direction;

[0043] A division module, used for taking the kth smallest element on the current coordinate axis as a reference number, and dividing the element into two parts based on the reference number, namely a left part and a right part;

[0044] The third judgment module is used to judge whether the number of elements after division is greater than the threshold value. If not, the division is completed, an index tree is generated, and the state is changed; if greater, another coordinate axis is selected as the division direction, and for the elements in the left part and the elements in the right part, the step of taking the kth smallest element on the current coordinate axis as the base number is returned respectively;

[0045] The query module is used to perform data query using the index tree.

[0046] The innovative features of the embodiments of the present invention include:

[0047] 1. In this embodiment, a static fast spatial index is constructed to realize data query, which can provide higher query efficiency while occupying less memory resources and support a larger point data scale, reaching millions or tens of millions, which is one of the innovations of the embodiment of the present invention.

[0048] 2. In this embodiment, a replicable index storage protocol is formulated to enable rapid replication of indexes, thereby achieving rapid reuse, which is one of the innovative features of the embodiment of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0050] Figure 1 A flow chart of a spatial index construction query method provided by an embodiment of the present invention;

[0051] Figure 2 A schematic diagram of an assembly method of an index space provided in an embodiment of the present invention;

[0052] Figure 3 A flow chart for determining whether a first predetermined requirement is met provided in an embodiment of the present invention;

[0053] Figure 4 A flow chart for determining whether a second predetermined requirement is met provided by an embodiment of the present invention;

[0054] Figure 5 A flow chart of data query provided by an embodiment of the present invention;

[0055] Figure 6 Another flow chart of data query provided by an embodiment of the present invention;

[0056] Figure 7 Another flow chart of a spatial index construction query method provided by an embodiment of the present invention;

[0057] Figure 8 A schematic diagram of the structure of a spatial index construction query system provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0058] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0059] It should be noted that the terms "including" and "having" and any variations thereof in the embodiments of the present invention and the accompanying drawings are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device including a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products or devices.

[0060] The embodiment of the present invention discloses a query method and system based on a spatial index of two-dimensional points, which are described in detail below.

[0061] Figure 1 For a flowchart of a spatial index construction query method provided by an embodiment of the present invention, please refer to Figure 1 The spatial index construction query method based on two-dimensional points provided by the embodiment of the present invention includes:

[0062] Step 1: Build an index container and enter the capacity of the index container;

[0063] Step 2: Determine whether the capacity of the index container meets the first predetermined requirement. If not, the program ends. If the first predetermined requirement is met, initialize the message header space, index space, and coordinate space according to the capacity of the index container.

[0064] Step 3: Input the element information to be indexed in sequence, the element information includes the coordinate ID, longitude and latitude; each time the element information is input, determine whether the current state meets the second predetermined requirement, if not, the program ends; if the second predetermined requirement is met, record the coordinate ID in the index space, and record the coordinate longitude and latitude in the coordinate space;

[0065] Step 4: Determine whether the number of elements meets the third predetermined requirement. If not, the program ends. If it meets, determine whether the number of elements in the index container is greater than the threshold. If not, sorting is completed, an index tree is generated, and the state is changed. If it is greater, select a coordinate axis as the division direction.

[0066] Step 5: Take the kth smallest element on the current coordinate axis as the reference number, and divide the element into two parts based on the reference number, namely the left part and the right part;

[0067] Step 6: Determine whether the number of elements after division is greater than the threshold. If not, the division is completed, an index tree is generated, and the state is changed. If it is greater, another coordinate axis is selected as the division direction, and for the elements in the left part and the elements in the right part, the kth smallest element on the current coordinate axis is returned as the base number step;

[0068] Step 7: Use the index tree to query data.

[0069] Specifically, please refer to Figure 1 The spatial index construction query method based on two-dimensional points provided by the embodiment of the present invention first creates a data pool as an index container through step 1, and the data pool can be used to store data that needs to be spatially indexed. When constructing the index container, it is necessary to input the capacity of the index container at the same time. The capacity of the index container refers to the number of data points that can be stored. For example, its capacity is set to be able to store 1 million data points.

[0070] After the index container is constructed, it needs to be initialized. In step 2, first determine whether the capacity of the index container meets the first predetermined requirement, where the first predetermined requirement can be specifically set according to actual needs, such as determining whether the input index container capacity is an integer, whether the input index container capacity is greater than 0, etc.

[0071] When the capacity of the index container does not meet the first predetermined requirement, the initialization cannot be performed and the program ends. When the capacity of the index container meets the first predetermined requirement, the index container is initialized. During initialization, the message header space, index space, and coordinate space need to be initialized separately. Specifically, the capacity of the index container is allocated to the message header space, index space, and coordinate space respectively, such as Figure 2 A schematic diagram of an assembly method of the index space provided in an embodiment of the present invention, in addition to the message header space, index space and coordinate space, an end byte is also provided. The CRC in the end character is verified according to the 32-bit result, which is usually used in network communication and file verification. Figure 2 The bytecode assembly shown generates an xx.index file and saves it, which enables the index to be quickly copied, thereby achieving rapid reuse of the index.

[0072] After the index space is built and initialized, data can be written into the index space in step 3. The data here refers to all the information contained in the elements to be indexed. The element information is also the coordinate information, including the coordinate ID, longitude and latitude. For example, the longitude and latitude of the coordinate are 106.2323, 29.2323 respectively, and the coordinate ID is Chongqing.

[0073] Since there may be multiple elements that need to be indexed, each time the element information is input, it is necessary to determine whether the current state meets the second predetermined requirement. The second predetermined requirement can be, for example, to determine whether the number of elements currently in the index container exceeds the capacity of the index container. If the second predetermined requirement is not met, it means that the number of elements currently in the index container exceeds the capacity of the index container. At this time, data cannot be written further, so the element information is not input and the program ends. If the second predetermined requirement is met, the element information is written into the index container. When writing, the coordinate ID is written into the index space, and the longitude and latitude of the coordinate are written into the coordinate space.

[0074] After all elements are written into the index container, the index tree is constructed. First, step 4 is used to determine whether the number of elements meets the third predetermined requirement. The third predetermined requirement can be, for example, whether the number of elements in the index container exceeds the capacity of the index container. If the third predetermined requirement is not met, it indicates that the number of elements in the index container exceeds the capacity of the index container, and the program ends.

[0075] If the third predetermined requirement is met, the index tree is constructed using the elements in the index container. When constructing the index tree, first determine whether the number of elements in the index container is greater than a threshold. In this embodiment, the value of the threshold can be the value of a leaf node, or a default value of 64. When initializing the index container, the initialization of the message header space includes the initialization of the start bit and the number of leaf nodes. When the number of leaf nodes is used as the threshold, the value of the number of leaf nodes can be obtained based on the initialization value of the index container.

[0076] If the number of elements in the index container is not greater than the threshold, it means that the current number of elements meets the number of leaf nodes or the default value set by the initialization. At this time, there is no need to divide and sort the elements, and the index tree can be directly generated. If the number of elements in the index container is greater than the threshold, the elements need to be divided, and a coordinate axis is selected as the division direction. Here, it is assumed that the coordinate axis x is selected as the division direction.

[0077] After selecting the division direction, select the division value through step 5. When selecting the division value, the kth smallest element on the current coordinate axis is used as the reference number. The kth smallest element can be, for example, the median of the element. After selecting the reference number, the element is divided into two parts based on the size relationship between the reference number and the element. For example, the element smaller than the reference number is located to the left of the reference number as the left part, and the element larger than the reference number is located to the right of the reference number as the right part. Here, the reference number is the root node, and the left part and the right part are the left subtree and the right subtree respectively.

[0078] After obtaining the left subtree and the right subtree, the left subtree and the right subtree need to be recursively divided respectively. Similarly, before dividing, it is still necessary to determine whether the current subtree needs to be divided. Through step 6, determine whether the number of elements in the left subtree and the right subtree is greater than the threshold. If the number of elements in the left subtree and the right subtree is not greater than the threshold, it means that the current number of elements meets the number of leaf nodes or the default value set by the initialization. At this time, there is no need to divide and sort the elements, and the index tree can be directly generated. If the number of elements in the left subtree and the right subtree is greater than the threshold, the elements need to be divided.

[0079] When dividing, select another coordinate axis as the division direction. For example, if the x coordinate axis was selected as the division direction last time, select the y coordinate axis as the division direction this time. After selecting the division direction, you need to divide the left subtree and the right subtree separately. The division method is the same as the division method for the root node. Through step 5, select the division value for the left subtree and the right subtree respectively.

[0080] It should be noted that in order to display the status of the index container in real time, the current status of the index container needs to be displayed after each operation on the index container is completed. For example, after initialization is completed, the status of the index container is changed to "initialization completed", and after data writing is completed, its status is changed to "data writing completed", etc. Similarly, after the index tree is built, the status needs to be updated and its status needs to be changed to "index building completed".

[0081] After obtaining the index tree, in step 7, the index tree can be used to perform data query. The method of data query can be a rectangular query, that is, you can enter a rectangular box to query the data in this box. Or it can be a peripheral query, that is, enter a point location and the surrounding distance to query the corresponding data, such as querying supermarkets within 2000 meters of the *** attachment. You can also query by exporting an index file, that is, exporting an index file, which contains index information and can be copied and transferred to achieve index reuse. Which specific query method to use can be specifically selected according to actual needs, and the present invention does not make specific limitations on this.

[0082] The spatial index construction query method based on two-dimensional points provided by the present invention realizes data query by constructing a static and fast spatial index, which can provide higher query efficiency on the basis of occupying less memory resources, and can support larger point data scales, reaching millions and tens of millions. By formulating a replicable index storage protocol, the index can be quickly replicated, thereby realizing rapid reuse.

[0083] Optionally, Figure 3 For a flowchart of determining whether the first predetermined requirement is met provided by an embodiment of the present invention, please refer to Figure 1 and Figure 3In step 2, it is determined whether the capacity of the index container meets the first predetermined requirement, specifically: whether the capacity of the index container is an integer is determined. If it is not an integer, it indicates that the capacity of the index container does not meet the first predetermined requirement; if it is an integer, it is determined whether the capacity of the index container is greater than 0. If it is not greater than 0, it indicates that the capacity of the index container does not meet the first predetermined requirement. If it is greater than 0, it indicates that the capacity of the index container meets the first predetermined requirement.

[0084] Specifically, please refer to Figure 1 and Figure 3 In this embodiment, the first predetermined requirement is whether the capacity of the input index container is an integer and whether the capacity of the input index container is greater than 0. When determining whether the capacity of the index container meets the first predetermined requirement, it is necessary to determine whether the capacity of the index container meets both conditions. As long as any one of the conditions is not met, it means that the capacity of the index container does not meet the first predetermined requirement.

[0085] First, determine whether the capacity of the index container is an integer. If it is not an integer, it means that the capacity of the index container does not meet the first predetermined requirement and cannot be initialized. If it is an integer, continue to determine whether the capacity of the index container is greater than 0. If it is not greater than 0, it means that the capacity of the index container does not meet the first predetermined requirement and cannot be initialized. If it is greater than 0, it means that the capacity of the index container meets the first predetermined requirement and can be initialized.

[0086] Optionally, Figure 4 For a flowchart of determining whether the second predetermined requirement is met provided by an embodiment of the present invention, please refer to Figure 1 and Figure 4 In step 3, it is determined whether the current state meets the second predetermined requirement, specifically: whether the current number of elements in the index container exceeds the capacity of the index container, if so, it indicates that the second predetermined requirement is not met; if not, it is determined whether the index space contains the ID of the current input coordinates, if so, it indicates that the second predetermined requirement is not met, if not, it indicates that the second predetermined requirement is met.

[0087] Specifically, please refer to Figure 1 and Figure 4 In this embodiment, the second predetermined requirement is whether the number of elements in the index container currently exceeds the capacity of the index container, and whether the index space contains the ID of the current input coordinates. When judging whether the current state meets the second predetermined requirement, it is necessary to judge whether the current state meets these two conditions at the same time. As long as any one of the conditions is not met, it means that the current state does not meet the second predetermined requirement.

[0088] First, determine whether the number of elements currently in the index container exceeds the capacity of the index container. If so, it means that the second predetermined requirement is not met and data cannot be written further, so the element information is not input. If not, continue to determine whether the index space already contains the ID of the currently input coordinates. If so, it means that the current element already exists in the index space and no further input is required. If not, it means that the second predetermined requirement is met and the element information is written into the index container. When writing, the coordinate ID is written into the index space, and the longitude and latitude of the coordinate are written into the coordinate space. .

[0089] Optionally, Figure 5 For a flow chart of data query provided by an embodiment of the present invention, please refer to Figure 1 and Figure 5 When using the index tree to query data in step 7, a rectangular query method is used to query data, specifically: step 71, input the coordinates of the rectangular box; step 72, determine whether the coordinates of the rectangular box conform to the rectangular rule, if not, the program ends; if yes, step 73, determine whether the index tree is generated according to the changed state; if the index tree is not generated, the program ends; if the index tree is generated, step 74, traverse the index tree downward from the root node to determine whether there is an inclusion relationship between the rectangular area corresponding to the current node and the rectangular box; if there is no inclusion relationship, the program ends; if there is an inclusion relationship, step 75, recursively query whether the rectangular area corresponding to the left and right subtrees of the current node and the rectangular box have an inclusion relationship; step 76, after reaching the leaf node, if the current leaf node is in the rectangular box, the current leaf node is added to the selection set; step 77, the selection set formed after finding all the points falling in the rectangular box is the query result data.

[0090] Specifically, please refer to Figure 1 and Figure 5 In this embodiment, a rectangular query method is used to query data. First, the coordinates of the rectangular frame are input through step 71. In order to ensure that the input coordinates can form a rectangular frame, the input rectangular frame coordinates are judged through step 72 to determine whether the rectangular frame coordinates meet the rectangular rule. If they do not meet the rule, the query range cannot be formed and the program ends. If they meet the rule, in step 73, it is determined whether the index tree is successfully generated according to the state of the index container.

[0091] If the index tree is not generated, data query cannot be performed and the program ends. If the index tree is generated, in step 74, the index tree is traversed downward from the root node, and for each node, it is determined whether the rectangular area corresponding to the current node has a containment relationship with the rectangular box. The containment relationship here can be that one box is completely located in another box, or the two rectangular boxes intersect.

[0092] If there is no containment relationship, the program ends. If there is a containment relationship, in step 75, it is recursively queried whether the rectangular area corresponding to the left and right subtrees of the current node and the rectangular frame have a containment relationship. The left and right subtrees are recursively queried, specifically, the parent nodes of the left subtree and the right subtree are respectively used as the current node, and the left subtree and the right subtree are continued to be judged according to the judgment method of step 74.

[0093] In the process of traversing nodes, if the current node is a leaf node, then step 76 is used to determine whether the leaf node is located in the rectangular frame. If the current leaf node is located in the rectangular frame, the current leaf node is added to the selection set, otherwise, it is not added. By traversing all nodes, all points that fall within the rectangular frame can be obtained. Step 77 is used to form a selection set for all points that fall within the rectangular frame, and the selection set is used as the query result data.

[0094] Optionally, Figure 6 For another flow chart of data query provided by the embodiment of the present invention, please refer to Figure 1 and Figure 6 When using the index tree to query data in step 7, the surrounding query method is used to query data, specifically: step 701, input the query point and query range; step 702, determine whether the input query point and query range are legal, if not, the program ends; if legal, step 703, determine whether the index tree is generated according to the changed state; if the index tree is not generated, the program ends; if the index tree is generated, step 704, generate a circle according to the query point and query range; step 705, traverse the index tree downward from the root node to determine whether the rectangular area corresponding to the current node has an inclusion relationship with the circle; if there is no inclusion relationship, the program ends; if there is an inclusion relationship, step 706, recursively query whether the rectangular area corresponding to the left and right subtrees of the current node has an inclusion relationship with the circle; step 707, after reaching the leaf node, if the current leaf node is located in the circle, the current leaf node is added to the selection set; step 708, the selection set formed after finding all the points falling in the circle is the query result data.

[0095] Specifically, please refer to Figure 6 In this embodiment, the surrounding query method is used to query data. First, the query point and query range are input through step 701. In order to ensure that the input point and range can form a query range that meets the conditions, the input query point and query range are judged through step 702 to determine whether the query point and query range are legal. If not, the query range cannot be formed and the program ends. If it meets the conditions, in step 703, it is determined whether the index tree is successfully generated according to the state of the index container.

[0096] If the index tree is not generated, data query cannot be performed and the program ends. If the index tree is generated, a circle is generated according to the query point and the query range in step 704, and the circle is used as the data query range. Here, it should be noted that the circle consists of 360 points, and the calculation rule for each point is x = longitude + distance * sin angle, Y = latitude + distance * cos angle.

[0097] After obtaining the data query range, in step 705, the index tree is traversed downward from the root node, and for each node, it is determined whether there is an inclusion relationship between the rectangular area corresponding to the current node and the circle. The inclusion relationship here can be that one area is completely located in another area, or the two areas intersect.

[0098] If there is no inclusion relationship, the program ends. If there is an inclusion relationship, in step 706, recursively query whether the rectangular area corresponding to the left and right subtrees of the current node has an inclusion relationship with the circle. Recursively query the left and right subtrees, specifically, respectively take the parent nodes of the left subtree and the right subtree as the current node, and continue to judge the left subtree and the right subtree according to the judgment method of step 705.

[0099] In the process of traversing nodes, if the current node is a leaf node, then step 707 is used to determine whether the leaf node is located in the circle. If the current leaf node is located in the circle, the current leaf node is added to the selection set, otherwise, it is not added. By traversing all nodes, all points that fall within the circle can be obtained. Step 708 is used to form a selection set for all points that fall within the rectangular box, and the selection set is used as the query result data.

[0100] Optionally, Figure 7 For another flowchart of the spatial index construction query method provided in the embodiment of the present invention, please refer to Figure 7 After the index tree is generated, the method further includes: Step 07, generating an index file using the index tree. Preferably, the method of exporting the index file is used to perform data query.

[0101] Specifically, in this embodiment, through step 07, the generated index tree is Figure 2 The index space assembly method shown generates an index file, so that the index tree can be saved in the form of an index file, so that the index can be quickly copied, thereby realizing rapid reuse of the index. When the index tree is saved in the form of an index file, since it can be quickly copied, when data needs to be queried, the index file can be directly exported and queried using the index file.

[0102] Based on the same inventive concept, the present invention also provides a query system 100 based on a spatial index of two-dimensional points. Figure 8A schematic diagram of a spatial index construction query system provided by an embodiment of the present invention is shown in FIG. Figure 8 The spatial index construction query system 100 based on two-dimensional points provided by the present invention includes:

[0103] A construction module 10 is used to construct an index container and input the capacity of the index container;

[0104] A first judging module 20 is used to judge whether the capacity of the index container meets a first predetermined requirement. If not, the program ends; if the first predetermined requirement is met, the message header space, the index space and the coordinate space are initialized according to the capacity of the index container;

[0105] The input module 30 is used to sequentially input the element information to be indexed, the element information including the ID, longitude and latitude of the coordinates; after each input of the element information, it is determined whether the current state meets the second predetermined requirement, if not, the program ends; if the second predetermined requirement is met, the ID of the coordinates is recorded in the index space, and the longitude and latitude of the coordinates are recorded in the coordinate space;

[0106] The second judgment module 40 is used to judge whether the number of elements meets the third predetermined requirement. If not, the program ends; if it meets, it is judged whether the number of elements in the index container is greater than the threshold. If not, the sorting is completed, the index tree is generated, and the state is changed; if it is greater, a coordinate is selected as the division direction;

[0107] A division module 50, used to use the kth smallest element on the current coordinate axis as a reference number, and divide the element into two parts based on the reference number, namely a left part and a right part;

[0108] The third judgment module 60 is used to judge whether the number of elements after division is greater than a threshold value. If not, the division is completed, an index tree is generated, and the state is changed; if greater, another coordinate axis is selected as the division direction, and for the elements in the left part and the elements in the right part, the step of taking the kth smallest element on the current coordinate axis as the reference number is returned respectively;

[0109] The query module 70 is used to perform data query using the index tree.

[0110] Specifically, please refer to Figure 8 The spatial index construction query system based on two-dimensional points provided by the embodiment of the present invention first creates a data pool as an index container through the construction module 10, and the data pool can be used to store data that needs to be spatially indexed. When constructing the index container, it is necessary to input the capacity of the index container at the same time. The capacity of the index container refers to the number of data points that can be stored. For example, its capacity is set to be able to store 1 million data points.

[0111] After the index container is constructed, it needs to be initialized. During initialization, the first judgment module 20 first determines whether the capacity of the index container meets the first predetermined requirement. The first predetermined requirement here can be specifically set according to actual needs, such as determining whether the capacity of the input index container is an integer, whether the capacity of the input index container is greater than 0, etc.

[0112] When the capacity of the index container does not meet the first predetermined requirement, the initialization cannot be performed and the program ends. When the capacity of the index container meets the first predetermined requirement, the index container is initialized. During initialization, the message header space, index space, and coordinate space need to be initialized separately. Specifically, the capacity of the index container is allocated to the message header space, index space, and coordinate space respectively, such as Figure 2 An assembly method of the index space provided in the embodiment of the present invention is to combine the indexes according to Figure 2 The assembly method shown can be saved to allow the index to be quickly copied, thereby achieving rapid reuse of the index.

[0113] After the index space is constructed and initialized, data can be written into the index space using the input module 30. The data here refers to all the information contained in the elements to be indexed, and the element information is also the coordinate information, specifically including the coordinate ID, longitude and latitude. For example, the longitude and latitude of the coordinate are 106.2323, 29.2323 respectively, and the coordinate ID is Chongqing.

[0114] Since there may be multiple elements that need to be indexed, each time the element information is input, it is necessary to determine whether the current state meets the second predetermined requirement. The second predetermined requirement can be, for example, to determine whether the number of elements currently in the index container exceeds the capacity of the index container. If the second predetermined requirement is not met, it means that the number of elements currently in the index container exceeds the capacity of the index container. At this time, data cannot be written further, so the element information is not input and the program ends. If the second predetermined requirement is met, the element information is written into the index container. When writing, the coordinate ID is written into the index space, and the longitude and latitude of the coordinate are written into the coordinate space.

[0115] After all elements are written into the index container, the index tree is constructed. First, the second judgment module 40 judges whether the number of elements meets the third predetermined requirement. The third predetermined requirement can be, for example, whether the number of elements in the index container exceeds the capacity of the index container. If the third predetermined requirement is not met, it indicates that the number of elements in the index container exceeds the capacity of the index container, and the program ends.

[0116] If the third predetermined requirement is met, the index tree is constructed using the elements in the index container. When constructing the index tree, first determine whether the number of elements in the index container is greater than a threshold. In this embodiment, the value of the threshold can be the value of a leaf node, or a default value of 64. When initializing the index container, the initialization of the message header space includes the initialization of the start bit and the number of leaf nodes. When the number of leaf nodes is used as the threshold, the value of the number of leaf nodes can be obtained based on the initialization value of the index container.

[0117] If the number of elements in the index container is not greater than the threshold, it means that the current number of elements meets the number of leaf nodes or the default value set by the initialization. At this time, there is no need to divide and sort the elements, and the index tree can be directly generated. If the number of elements in the index container is greater than the threshold, the elements need to be divided, and a coordinate axis is selected as the division direction. Here, it is assumed that the coordinate axis x is selected as the division direction.

[0118] After the division direction is selected, the division value is selected by the division module 50. When selecting the division value, the kth smallest element on the current coordinate axis is used as the reference number. The kth smallest element can be, for example, the median of the element. After the reference number is selected, the element is divided into two parts using the size relationship between the reference number and the element. For example, the element smaller than the reference number is located to the left of the reference number as the left part, and the element larger than the reference number is located to the right of the reference number as the right part. Here, the reference number is the root node, and the left part and the right part are the left subtree and the right subtree, respectively.

[0119] After obtaining the left subtree and the right subtree, the left subtree and the right subtree need to be recursively divided respectively. Similarly, before dividing, it is still necessary to judge whether the current subtree needs to be divided. Through the third judgment module 60, it is judged whether the number of elements in the left subtree and the right subtree is greater than the threshold value. If the number of elements in the left subtree and the right subtree is not greater than the threshold value, it means that the current number of elements meets the number of leaf nodes or the default value set by the initialization. At this time, there is no need to divide and sort the elements, and the index tree can be directly generated. If the number of elements in the left subtree and the right subtree is greater than the threshold value, the elements need to be divided.

[0120] When dividing, select another coordinate axis as the division direction. For example, if the x coordinate axis was selected as the division direction last time, select the y coordinate axis as the division direction this time. After selecting the division direction, you need to divide the left subtree and the right subtree separately. The division method is the same as the division method for the root node, and select the division value for the left subtree and the right subtree respectively.

[0121] It should be noted that in order to display the status of the index container in real time, the current status of the index container needs to be displayed after each operation on the index container is completed. For example, after initialization is completed, the status of the index container is changed to "initialization completed", and after data writing is completed, its status is changed to "data writing completed", etc. Similarly, after the index tree is built, the status needs to be updated and its status needs to be changed to "index building completed".

[0122] After obtaining the index tree, the query module 70 can use the index tree to perform data query. The data query method can be a rectangular query, that is, you can enter a rectangular box to query the data in this box. Or it can be a peripheral query, that is, enter a point location and the surrounding distance to query the corresponding data, such as querying supermarkets within 2000 meters of the *** attachment. You can also query by exporting an index file, that is, exporting an index file, which contains index information and can be copied and transferred to achieve index reuse. Which query method to use can be specifically selected according to actual needs, and the present invention does not make specific limitations on this.

[0123] The spatial index construction query system based on two-dimensional points provided by the present invention realizes data query by constructing a static and fast spatial index, which can provide higher query efficiency on the basis of occupying less memory resources, and can support larger point data scales, reaching millions and tens of millions. By formulating a replicable index storage protocol, the index can be quickly replicated, thereby realizing rapid reuse.

[0124] Those skilled in the art can understand that the accompanying drawings are only schematic diagrams of an embodiment, and the modules or processes in the accompanying drawings are not necessarily required to implement the present invention.

[0125] Those skilled in the art can understand that the modules in the device in the embodiment can be distributed in the device in the embodiment according to the description of the embodiment, or can be changed accordingly and located in one or more devices different from the embodiment. The modules in the above embodiment can be combined into one module, or can be further divided into multiple sub-modules.

[0126] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A query method based on a spatial index of two-dimensional points, characterized in that: include: Construct an index container and input the capacity of the index container; Determine whether the capacity of the index container meets a first predetermined requirement, if not, the program ends; if the first predetermined requirement is met, initialize the message header space, index space and coordinate space according to the capacity of the index container; Input the element information to be indexed in sequence, the element information including the coordinate ID, longitude and latitude; each time the element information is input, determine whether the current state meets the second predetermined requirement, if not, the program ends; if the second predetermined requirement is met, record the coordinate ID in the index space, and record the coordinate longitude and latitude in the coordinate space; Determine whether the number of elements meets the third predetermined requirement, if not, the procedure ends; If it meets the requirement, determine whether the number of elements in the index container is greater than a threshold value, if not, sorting is completed, an index tree is generated, and the state is changed; If it is greater than, select a coordinate axis as the division direction; Taking the kth smallest element on the current coordinate axis as a reference number, the element is divided into two parts based on the reference number, namely a left part and a right part; Determine whether the number of elements after division is greater than the threshold. If not, the division is completed, an index tree is generated, and the state is changed. If it is greater, another coordinate axis is selected as the division direction, and for the elements on the left and the elements on the right, the steps with the kth smallest element on the current coordinate axis as the base number are returned respectively. The index tree is used to perform data query.

2. The query method based on spatial index construction of two-dimensional points according to claim 1, characterized in that: Determining whether the capacity of the index container meets the first predetermined requirement is specifically as follows: Determine whether the capacity of the index container is an integer. If not, it indicates that the capacity of the index container does not meet the first predetermined requirement. If it is an integer, determine whether the capacity of the index container is greater than 0. If not, it indicates that the capacity of the index container does not meet the first predetermined requirement. If greater than 0, it indicates that the capacity of the index container meets the first predetermined requirement.

3. The query method based on spatial index construction of two-dimensional points according to claim 1, characterized in that: Determine whether the current state meets the second predetermined requirement, specifically: Determine whether the current number of elements in the index container exceeds the capacity of the index container. If so, it indicates that the second predetermined requirement is not met. If not, determine whether the index space contains the ID of the current input coordinates. If so, it indicates that the second predetermined requirement is not met. If not, it indicates that the second predetermined requirement is met.

4. The query method based on spatial index construction of two-dimensional points according to claim 1, characterized in that: The message header space includes a start bit and the number of leaf nodes, and the number of leaf nodes is used as the threshold.

5. The query method based on spatial index construction of two-dimensional points according to claim 1, characterized in that: Based on the reference number, the elements are divided into two parts, namely the left part and the right part, specifically: Based on the current coordinates, elements smaller than the reference number are located on the left side of the reference number as the left part; elements larger than the reference number are located on the right side of the reference number as the right part.

6. The query method based on spatial index construction of two-dimensional points according to claim 1, characterized in that: The rectangular query method is used for data query, specifically: Enter the coordinates of the rectangular box; Determine whether the coordinates of the rectangular frame conform to the rectangular rule. If not, the program ends; if not, determine whether the index tree is generated according to the changed state; If the index tree is not generated, the program ends; if the index tree is generated, the index tree is traversed downward from the root node to determine whether the rectangular area corresponding to the current node has a containment relationship with the rectangular frame; If there is no containment relationship, the program ends; if there is a containment relationship, recursively query whether the rectangular area corresponding to the left and right subtrees of the current node and the rectangular box have a containment relationship; After reaching the leaf node, if the current leaf node is within the rectangular frame, the current leaf node is added to the selection set; The selection set formed after finding all the points falling within the rectangular box is the query result data.

7. The query method based on spatial index construction of two-dimensional points according to claim 1, characterized in that: Use the surrounding query method to query data, specifically: Enter the query point and query range; Determine whether the query point and query range entered are legal, if not, the program ends; If it is legal, determine whether the index tree is generated based on the changed status; If the index tree is not generated, the program ends; If the index tree is generated, a circle is generated according to the query point and the query range; Traverse the index tree downward from the root node to determine whether the rectangular area corresponding to the current node has a containment relationship with the circle; If there is no containment relationship, the program ends; if there is a containment relationship, recursively query whether the rectangular area corresponding to the left and right subtrees of the current node has a containment relationship with the circle; After reaching the leaf node, if the current leaf node is within the circle, the current leaf node is added to the selection set; The selection set formed after finding all the points falling within the circle is the query result data.

8. The query method based on spatial index construction of two-dimensional points according to claim 1, characterized in that: After the index tree is generated, the method further includes: generating an index file using the index tree.

9. The query method based on spatial index construction of two-dimensional points according to claim 8, characterized in that: Use the method of exporting index files to query data.

10. A query system based on a spatial index of two-dimensional points, characterized in that: include: A construction module, used for constructing an index container and inputting the capacity of the index container; A first judgment module, used to judge whether the capacity of the index container meets a first predetermined requirement, and if not, the program ends; if the first predetermined requirement is met, the message header space, the index space and the coordinate space are initialized according to the capacity of the index container; The input module is used to sequentially input the element information to be indexed, wherein the element information includes the ID, longitude and latitude of the coordinates; after each input of the element information, it is determined whether the current state meets the second predetermined requirement, and if the second predetermined requirement is not met, the program ends; if the second predetermined requirement is met, the ID of the coordinates is recorded in the index space, and the longitude and latitude of the coordinates are recorded in the coordinate space; The second judgment module is used to judge whether the number of elements meets the third predetermined requirement. If not, the program ends; If it meets the requirement, determine whether the number of elements in the index container is greater than a threshold value, if not, sorting is completed, an index tree is generated, and the state is changed; If it is greater, select a coordinate as the division direction; A division module, used for taking the kth smallest element on the current coordinate axis as a reference number, and dividing the element into two parts based on the reference number, namely a left part and a right part; The third judgment module is used to judge whether the number of elements after division is greater than the threshold value. If not, the division is completed, an index tree is generated, and the state is changed; if greater, another coordinate axis is selected as the division direction, and for the elements in the left part and the elements in the right part, the step of taking the kth smallest element on the current coordinate axis as the base number is returned respectively; The query module is used to perform data query using the index tree.