A fast query method for neighboring points based on key-value database

By using the Geohash algorithm in the key-value database to convert geographical coordinates into one-dimensional codes and establishing an index table, the problem of low efficiency of traditional databases when processing massive geospatial data is solved, and the method of quickly querying point data is realized, which significantly improves the Query speed and storage efficiency.

CN114116702BInactive Publication Date: 2024-11-01WUHAN UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111292647.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-03
Publication Date
2024-11-01
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Traditional relational databases are less efficient when processing massive geospatial data, and cannot quickly and effectively query target point data.

Method used

Using a key-value database-based method, the two-dimensional geographic coordinates are converted into one-dimensional Geohash code through the Geohash algorithm, an index table is established to improve query efficiency, and the main table is combined to achieve rapid query point data.

Benefits of technology

It significantly improves the query speed and storage efficiency of point data, solves the problem of low efficiency in traditional databases when processing geospatial data, and realizes the rapid search of target data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114116702B_ABST
    Figure CN114116702B_ABST
Patent Text Reader

Abstract

The present invention relates to a method for quickly querying neighboring points based on a key-value database. The two-dimensional geographic coordinates in the point data are converted into a one-dimensional Geohash code using a Geohash algorithm, and the unique Geohash code is used as a Key value, and other attributes of the point data are used as Value values ​​and stored in a key-value database. Then, the characteristic that the similarity of the Geohash encoding prefix is ​​proportional to the spatial distance is used to establish an index table for the stored point data. Finally, the main table and the index table are combined to realize the function of quickly querying the point data around the target. The present invention stores point data in a key-value database and establishes an effective index table, which greatly improves the efficiency of querying point data and solves the problem of low efficiency of traditional relational databases in processing geographic spatial data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field related to geographic space point data storage and retrieval, and in particular to a method for quickly querying neighboring points based on a key-value database. Background Art

[0002] With the progress of society and the advancement of smart city construction, the amount of geospatial data has grown rapidly. In the case of a huge amount of data, how to quickly and effectively store, process and query geospatial data has become an urgent problem to be solved. Point data, as a geographic data application entity, has been widely used in e-commerce, social networking, electronic map services, Internet finance and other fields. Traditional relational databases cannot support the rapid and effective query of target point data through two-dimensional coordinate information in massive point data. Because the complex table structure of relational databases will reduce the efficiency of data processing, especially the processing of large-scale data writing, updating and simple and fast query. The key-value database has good scalability, high flexibility, high performance in large-scale write operations, and can quickly find target data. Therefore, using a key-value database to store point data will greatly improve storage and query efficiency. Summary of the invention

[0003] In view of the deficiencies in the prior art, the present invention provides a method for quickly querying neighboring points based on a key-value database. By storing point data in a key-value database and establishing an effective index table, the efficiency of querying point data is greatly improved, and the problem of low efficiency of traditional relational databases in processing geographic spatial data is solved.

[0004] In order to achieve the above object, the technical solution provided by the present invention is a method for quickly querying neighboring points based on a key-value database, comprising the following steps:

[0005] Step 1: Create a spatial index for the point data and store it in the main table;

[0006] Step 2, create an index table for the main table;

[0007] Step 3: When a query request is received, the index table and the main table are searched according to the spatial position of the request point, and the query result is returned;

[0008] Step 3.1, when a query request is received, the corresponding Geohash code is generated using the Geohash algorithm according to the latitude and longitude coordinates of the request point, and the first M bits of the code are queried in the index table to obtain the code values ​​of all Geohash in the main table that have the same first M bits;

[0009] Step 3.2: If the first M-digit Geohash code that is the same as the requested point is not found in the index table, it is returned that there is no data around the requested point; if n first M-digit Geohash codes that are the same as the requested point are found in the index table, all the code values ​​obtained in step 3.1 are decoded to obtain n sets of longitude and latitude values, and the first m points with the closest Euclidean distance to the requested point are calculated using the longitude and latitude;

[0010] Step 3.3, query the attributes of the m point data obtained in step 3.2 in the main table, and return the query result, which is the latitude and longitude coordinates and attribute information of the point.

[0011] Moreover, in step 1, the spatial coordinates of the point data are firstly reduced in dimension, and the longitude and latitude coordinates are converted into one-dimensional Geohash codes using the Geohash algorithm. Then, the N-bit Geahash code is selected as the Key value, and other attribute values ​​of the point data are used as the Value value, which are stored in the main table of the key-value database.

[0012] Moreover, in step 2, all the Key values ​​stored in the main table of the database, that is, the N-bit Geohash codes generated by each point data, are processed; according to the actual stored point distribution and density, all Geohash codes with the same first M bits of the Geohash code are combined and stored in the index table, that is, the Key value of the index table is the same first M bits of the Geohash code, and the Value value is a spliced ​​combination of the last NM bits of the Geohash code.

[0013] Compared with the prior art, the present invention has the following advantages:

[0014] 1) Using a key-value database to store point information improves retrieval speed and has good scalability.

[0015] 2) Use the Geohash algorithm to convert the two-dimensional geographic coordinates in the point data into a one-dimensional Geohash code. Since each point corresponds to a unique Geohash code and the similarities of the corresponding Geohash codes of spatially similar points are also relatively high, the point data around the target point can be queried effectively and quickly. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] Figure 1 The figure is a flowchart of an embodiment of the present invention.

[0017] Figure 2 Schematic diagram of a Geohash curve according to an embodiment of the present invention.

[0018] Figure 3 The figure is a schematic diagram of a data query process according to an embodiment of the present invention. DETAILED DESCRIPTION

[0019] The present invention provides a method for quickly querying neighboring points based on a key-value database. First, the Geohash algorithm is used to convert the two-dimensional geographic coordinates in the point data into a one-dimensional Geohash code, and the unique Geohash code is used as the Key value, and other attributes of the point data are used as Value values ​​and stored in the key-value database. Then, the characteristic that the similarity of the Geohash encoding prefix is ​​proportional to the spatial distance is used to establish an index table for the stored point data. Finally, the main table and the index table are combined to realize the function of quickly querying the point data around the target.

[0020] The technical solution of the present invention is further described below in conjunction with the accompanying drawings and embodiments.

[0021] like Figure 1 As shown, the process of the embodiment of the present invention includes the following steps:

[0022] Step 1: Create a spatial index for the point data and store it in the main table.

[0023] First, the spatial coordinates of the point data are reduced in dimensionality, and the Geohash algorithm is used to convert the longitude and latitude coordinates into a one-dimensional Geohash code. Then, the unique Geahash code is used as the Key value, and other attribute values ​​of the point data such as name, address, telephone, type, and areaid are used as Value values, and stored in the main table of the key-value database. This embodiment uses a 12-bit Geohash code as the Key value of the data. The 12-bit Geohash code can guarantee centimeter-level longitude and ensure the uniqueness of the Key value. The Geohash curve is a one-dimensional fractal of a space-filling curve and is an application of the Z-curve. Although it is a one-dimensional curve, it can fill all the space in a two-dimensional plane. The Geohash curve has locality and continuity, so it is usually used to express multiple variables in a linear order. The schematic diagram of the Geohash curve is shown in Figure 2 shown.

[0024] In the present invention, Geohash coding is used as the unique identifier of point data, and a 12-bit Geohash code is used. The range (precision) that can be covered by each level of Geohash is shown in Table 1.

[0025] Table 1 Geohash coverage (accuracy) at each level

[0026] Coding level Coverage 1 ≤5,000km×5,000km 2 ≤1,250km×625km 3 ≤156km×156km 4 ≤39.1km×19.5km 5 ≤4.89km×4.89km 6 ≤1.22km×0.61km 7 ≤153m×153m 8 ≤38.2m×19.1m 9 ≤4.77m×4.77m 10 ≤1.19m×0.596m 11 ≤149mm×149mm 12 ≤37.2mm×18.6mm

[0027] Step 2: Create an index table for the main table.

[0028] The index table establishment process is: all the key values ​​stored in the database main table, that is, the 12-bit Geohash code generated by each point data, are processed. Taking into account the actual storage point distribution and density, this embodiment combines all Geohash codes with the same first six digits of the Geohash code and stores them in the index table. That is, the Key value of the index table is the same first six digits of the Geohash code, and the Value value is a spliced ​​combination of the last six digits of the Geohash code. The significance of the index table is that it can query all the data in the main table with the same first six digits of the Geohash code.

[0029] Step 3: When a query request is received, the index table and the main table are searched according to the spatial location of the request point, and the query result is returned.

[0030] Step 3.1, when a query request is received, the Geohash algorithm is used to generate the corresponding Geohash code according to the latitude and longitude coordinates of the request point, and the first six digits of the code are queried in the index table to obtain the code values ​​of all Geohash in the main table that have the same first six digits.

[0031] In this embodiment, considering that the first six digits of the Geohash code are the same, it means that the area range of the request point and the target point is 1.22 km×0.61 km, and the search range is large enough, so the first six digits are selected for comparison.

[0032] Step 3.2: If the first six digits of the Geohash code that are the same as the requested point are not found in the index table, it is returned that there is no data around the requested point; if n first six digits of the Geohash code that are the same as the requested point are found in the index table, all the code values ​​obtained in step 3.1 are encoded and decoded to obtain n groups of longitude and latitude values, and the first m points closest to the requested point in Euclidean distance are calculated.

[0033] Step 3.3, query the attributes of the m point data obtained in step 3.2 in the main table, and return the query result, which is the latitude and longitude coordinates and attribute information of the point.

[0034] During specific implementation, the above process can be automatically operated using computer software technology.

[0035] The specific embodiments described herein are merely examples of the spirit of the present invention. Those skilled in the art may make various modifications or additions to the specific embodiments described or replace them in similar ways, but they will not deviate from the spirit of the present invention or exceed the scope defined by the appended claims.

Claims

1. A method for quickly querying neighboring points based on a key-value database, characterized in that: The steps include: Step 1: Create a spatial index for the point data and store it in the main table; Step 2, create an index table for the main table; Step 3: When a query request is received, the index table and the main table are searched according to the spatial position of the request point, and the query result is returned; Step 3.1, when a query request is received, a corresponding Geohash code is generated according to the longitude and latitude coordinates of the request point, and a code value identical to the first M bits of the Geohash code is searched in the index table; Step 3.2, if the Geohash code with the same first M bits as the requested point is not found in the index table, it is returned that there is no data around the requested point; If the Geohash code with the same first M digits as the requested point is found in the index table, all the queried code values ​​are decoded to obtain the corresponding longitude and latitude values, and the m points closest to the requested point are selected; Step 3.3, query the attributes of the m point data obtained in step 3.2 in the main table, and return the query result, which is the latitude and longitude coordinates and attribute information of the point.

2. The method for quickly querying neighboring points based on a key-value database as claimed in claim 1, characterized in that: In step 1, the spatial coordinates of the point data are first reduced in dimensionality, and the longitude and latitude coordinates are converted into one-dimensional Geohash codes using the Geohash algorithm. Then, the N-bit Geohash code is selected as the Key value, and other attribute values ​​of the point data are used as the Value value, which are stored in the main table of the key-value database.

3. The method for quickly querying neighboring points based on a key-value database as claimed in claim 2, characterized in that: In step 2, all the key values ​​stored in the main table of the database, that is, the N-bit Geohash codes generated by each point data, are processed; according to the actual stored point distribution and density, all Geohash codes with the same first M bits of the Geohash code are combined and stored in the index table, that is, the Key value of the index table is the same first M bits of the Geohash code, and the Value value is a splicing combination of the last NM bits of the Geohash code.

4. A method for quickly querying neighboring points based on a key-value database as claimed in claim 3, characterized in that: In step 3.1, when a query request is received, the Geohash algorithm is first used to generate the corresponding Geohash code according to the latitude and longitude coordinates of the request point, and then the first M bits of the code are queried in the index table to obtain all the code values ​​with the same first M bits of the Geohash.

5. The method for quickly querying neighboring points based on a key-value database as claimed in claim 4, characterized in that: In step 3.2, if the Geohash code with the same first M bits as the requested point is not found in the index table, it is returned that there is no data around the requested point. If n Geohash codes with the same first M digits as the requested point are found in the index table, these n Geohash code values ​​are encoded and decoded to obtain n sets of longitude and latitude values, and the first m points with the closest Euclidean distance to the requested point are calculated using the longitude and latitude.