Geographic position coding algorithm based on spatial spherical triangle layer-by-layer segmentation

Through the geographic location encoding algorithm based on layer-by-layer segmentation of spatial spherical triangles, the problems of large decoding errors and uneven error distribution in the GeoHash encoding method are solved, and high-precision and safe encoding and decoding are achieved, which improves query efficiency.

CN120448611APending Publication Date: 2025-08-08NANTONG UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510539685.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-27
Publication Date
2025-08-08

AI Technical Summary

Technical Problem

The existing GeoHash encoding methods have problems such as large decoding errors, boundary mutations and uneven global regional error distribution, which affects query accuracy and efficiency.

Method used

The geographical position encoding algorithm based on layer-by-layer segmentation of spatial spherical triangles is adopted. By segmenting the meta-spherical triangles and geographic coordinates are converted into spatial rectangular coordinates, segmenting the spherical triangle encoding positions layer-by-layer, and compressing the position code using character codes to generate Base64 character codes for encoding and decoding.

Benefits of technology

Reduce decoding errors, make it more uniformly distributed in various regions around the world, improve coding accuracy and security, adapt to different accuracy requirements, and improve nearest neighbor query efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120448611A_ABST
    Figure CN120448611A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of spatial data coding of a geographic information system, in particular to a geographic position coding algorithm based on layer-by-layer segmentation of a spatial spherical triangle, which comprises the following steps of: 1, segmenting an element spherical triangle; 2, converting geographic coordinates into space rectangular coordinates; step 3, segmenting spherical triangle coding positions layer by layer; 4, compressing the position code by using the character code; and 5, decoding the character code and analyzing the position code. According to the method, layer-by-layer segmentation of the spatial spherical triangle is utilized, the method has remarkable hierarchical scalability, coding result character strings corresponding to points with closer geographic positions have higher prefix similarity, nearest neighbor point query can be converted into longest common prefix matching, and the nearest neighbor point query efficiency is improved. In addition, the coded result has higher information security, and the geographic information data protection capability is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of spatial data coding of geographic information systems, and in particular to a geographic location coding algorithm based on layer-by-layer segmentation of spatial spherical triangles. Background Art

[0002] Geolocation encoding technology has a wide range of applications in modern geographic information systems (GIS), location-based services (LBS), map navigation, and location retrieval. Currently, one of the mainstream geolocation encoding methods is the GeoHash algorithm, which encodes two-dimensional latitude and longitude coordinates into a one-dimensional string, enabling efficient indexing and querying of geographic locations.

[0003] The GeoHash encoding process mainly includes the following steps:

[0004] (1) Binary encoding of longitude and latitude: The longitude range [-180°, 180°] and latitude range [-90°, 90°] of the earth are continuously divided into two, and the binary code is used to represent the range.

[0005] (2) Merge coding: The binary codes of longitude and latitude are interleaved and merged, with longitude in front and latitude in the back.

[0006] (3) Base32 encoding: Convert the merged binary string into Base32 characters in groups of 5 to form the final GeoHash string.

[0007] GeoHash has hierarchical scaling properties, meaning that the longer the encoding length, the higher the accuracy of the geographic location. Furthermore, GeoHash can quickly index and locate neighboring areas through string prefix similarity, making it important in applications such as spatial database indexing, location clustering analysis, and geofencing.

[0008] Although GeoHash has many advantages in geolocation encoding, it still has the following disadvantages and limitations:

[0009] (1) Large decoding errors: GeoHash uses a binary search method to gradually approximate the actual latitude and longitude. However, due to the limited length of the code, the decoded geographic location always has a certain error. Improving the coding accuracy requires a longer string, which increases computing and storage costs and affects query efficiency.

[0010] (2) Boundary mutation: GeoHash uses a Z-shaped space-filling curve for encoding. As a result, at the boundaries of certain areas, even if two points are geographically close, their GeoHash codes may differ significantly. This coding discontinuity has a certain impact on proximity searches and range queries.

[0011] (3) Uneven global regional division: GeoHash uses a longitude-latitude dichotomy to divide geographic regions. Longitude division is uniform globally, while latitude division becomes denser in high-latitude regions and sparser near the equator. This makes encoding errors unevenly distributed globally, and the errors in low-latitude regions are greater than those in high-latitude regions, thus affecting query accuracy.

[0012] Given the aforementioned issues, existing GeoHash encoding methods still have room for improvement in practical applications, particularly in reducing encoding / decoding errors, controlling the uneven spatial distribution of errors, and optimizing computational and storage efficiency. To address these issues, this application proposes a geolocation encoding algorithm based on layer-by-layer segmentation of spatial spherical triangles to address the shortcomings of existing technologies and improve the accuracy and stability of geolocation encoding / decoding. Summary of the Invention

[0013] The purpose of the present invention is to address the shortcomings of the existing technology and propose a geographic location coding algorithm based on layer-by-layer segmentation of spatial spherical triangles. This algorithm can effectively reduce the accuracy error of geographic location encoding / decoding and the uneven distribution of errors in global regions that exist in the existing technology.

[0014] In order to achieve the above object, the present invention adopts the following technical solutions:

[0015] A geographic location encoding algorithm based on layer-by-layer segmentation of spatial spherical triangles includes the following steps:

[0016] Step 1: Split the metasphere into triangles;

[0017] Step 2: Convert geographic coordinates to spatial rectangular coordinates;

[0018] Step 3: Segment the spherical triangle encoding position layer by layer;

[0019] Step 4: Use the character code to compress the position code;

[0020] Step 5: Character code decoding and position code analysis.

[0021] Preferably, in step 1, the following steps are included:

[0022] Step 1.1: Abstract the Earth into a unit sphere

[0023] The real Earth is an irregular ellipsoid with a slightly bulging equator and slightly flattened poles. To facilitate calculations, the Earth needs to be abstracted and simplified. Let the center of the Earth be O, the North Pole be N, the longitude and latitude point (180°E, 0°) be the spherical point P, and the longitude and latitude point (90°E, 0°) be the spherical point Q. With O as the origin, the line OP as the X-axis, the OP direction as the positive X-axis direction, the line OQ as the Y-axis, the OQ direction as the positive Y-axis direction, and the line ON as the Z-axis, the ON direction as the positive Z-axis direction, to establish a spatial rectangular coordinate system O-XYZ.

[0024] Abstract the surface of the earth as a sphere with a radius R in O-XYZ Σ:x 2 +y 2 +z 2 =R 2 In the present invention, the radius of the earth R has no effect on the algorithm implementation, so R = 1 is taken to facilitate calculation, that is, the sphere Σ is the unit sphere;

[0025] The agreed global longitude range is [-180°, 180°], with the prime meridian longitude being 0°, and increasing eastward from the prime meridian and decreasing westward; the agreed latitude range is [-90°, 90°], with the equatorial latitude being 0°, and increasing northward from the equator and decreasing southward;

[0026] Step 1.2: Construct a regular tetrahedron

[0027] Given four fixed points on Σ: E0(0,0,1), Construct the inscribed regular tetrahedron E0-E1E2E3 of Σ;

[0028] Step 1.3: Split the spherical triangle

[0029] Let OE0 = e0, OE1 = e1, OE2 = e2, OE3 = e3, and let the vector group F0 = (e1, e2, e3), F1 = (e0, e2, e3), F2 = (e0, e1, e3), F3 = (e0, e1, e2), connect the 6 great circle segments between E0, E1, E2, E3, and divide Σ into 4 spherical triangular areas. Let the area corresponding to F0 be numbered 0, the area corresponding to F1 be numbered 1, the area corresponding to F2 be numbered 2, and the area corresponding to F3 be numbered 3.

[0030] Preferably, in step 2, the following steps are included:

[0031] First, define a coordinate conversion function named geo_to_orth with the following input parameters: lon, lat, where lon and lat represent longitude and latitude, respectively. Then, use the conversion formula between spherical polar coordinates and spatial rectangular coordinates to implement the above conversion function. Finally, use this function to convert the geographic coordinates (lon, lat) of the input point into spatial rectangular coordinates (x, y, z).

[0032] Preferably, in step 3, the following steps are included:

[0033] Step 3.1: Obtaining the first position code and determining the vector basis

[0034] First, define a position judgment function named position_judge with the following input parameters: F and T, where F represents the vector group (a, b, c). The initial basis vectors a, b, c all start from the coordinate origin O and are linearly independent. T represents the target point (x, y, z) in space. OT is linearly represented with F as the basis, and the expression is OT = k1·a+k2·b+k3·c. If the coefficients k1, k2, and k3 are all non-negative, then T is within the conical space region determined by F, and the function returns 1. If k1, k2, and k3 are not all non-negative, then T is outside the conical space region determined by F, and the function returns 0.

[0035] Then, use the geo_to_orth function to convert the geographic coordinates of the point to be coded T into spatial rectangular coordinates, substitute the coordinate value into the position_judge function to determine the spherical triangle area number where the point to be coded T is located, as the first position code, the value is an integer between [0,3], and at the same time obtain the vector basis F corresponding to the area;

[0036] Step 3.2: Acquisition of subsequent position codes and update of vector bases

[0037] First, define a spherical great circle segment midpoint calculation function, named sph_mid, with the following input parameters: A, B, where A and B represent two different points on the sphere, respectively. Use the spherical great circle segment midpoint coordinate formula to calculate the coordinates of the midpoint M of the great circle segment between points A and B. Then, use the sph_mid function to calculate the coordinates of the three sides of the spherical triangle area determined in 3.1, and use the great circle segments between the midpoints to divide the spherical triangle area into four sub-spherical triangle areas. Finally, use the position_judge function to determine the sub-area where point T is located, and use the sub-area number as a new round of encoding, while updating the vector basis F. Repeat the above operations until the length of the position coding list reaches the predetermined precision value pre. The present invention stipulates that pre must be a multiple of 3 and must be at least 12. The larger the pre value, the higher the encoding and decoding accuracy.

[0038] Step 3.3: Processing method for boundary points

[0039] During the encoding process, some ground points may fall on the common edges of two spherical triangle regions or on the common vertices of six spherical triangle regions. To handle these boundary points, the present invention sets a truncation mechanism during the layer-by-layer segmentation of the spherical triangle: the four sub-regions of the current spherical triangle region are traversed in the order of codes 0, 1, 2, and 3. When an intersection between the target point and a current sub-region is detected (for example, located on the boundary), the sub-region number is used as the new 1-bit code of the target point, and the current sub-region is updated to the spherical triangle region of the next cycle. Then, the current traversal process is interrupted and the next round of segmentation is directly entered to obtain the next 1-bit code.

[0040] This mechanism can ensure that boundary points are properly and reasonably encoded, and the encoding is unique, while reducing unnecessary traversal and calculation, and improving encoding efficiency.

[0041] Preferably, in step 4, the following steps are included:

[0042] Step 4.1: Split the location code list

[0043] Split the position code list obtained in step 3 to generate a two-dimensional list consisting of pre / 3 one-dimensional lists containing three elements;

[0044] Step 4.2: Convert quaternary to decimal

[0045] Consider each one-dimensional list in the two-dimensional list obtained in 4.1 as a quaternary number, convert them into decimal numbers one by one and return them as elements of the one-dimensional list. It is easy to find that the decimal number corresponding to the three quaternary numbers ranges from 0 to 63.

[0046] Step 4.3, generate character code

[0047] First, design a Base64 character code. This code consists of 64 randomly arranged base characters: the digits 0 through 9, the 26 lowercase English letters, the 26 uppercase English letters, and the two special characters "@" and "#." Character indexes in the Base64 character code range from 0 to 63. Define the encoding rule: use integers as character indices in the Base64 character code. To do this, encode the integer elements in the one-dimensional list obtained in 4.2 into their corresponding characters. Finally, generate the determined character sequence in sequence as a string. This process compresses the position code into a character code.

[0048] Preferably, in step 5, the following steps are included:

[0049] Step 5.1: Character code decoding

[0050] Perform the reverse process on the character code generated in step 4 to decode the encoded string;

[0051] First, use the Base64 character code to determine the index value corresponding to each character in the encoded string, return it as a list, then convert the index value into a quaternary number. Finally, concatenate the two-dimensional list consisting of several quaternary number lists into a one-dimensional list to decode the encoded string and generate the position code;

[0052] Step 5.2: Location code analysis

[0053] Read the first bit of the position code to determine the spherical triangle region number where the target point T is located, and obtain the vector basis F corresponding to the region; divide the spherical triangle region based on the midpoint of the great circle segment, then read the next bit of the code to determine the sub-region where T is located, and update the vector basis F; repeat the above operation until the position code list is read; executing this process will eventually calculate the spatial rectangular coordinates of the target point position based on the last updated vector basis F;

[0054] Step 5.3: Calculation of the geographical coordinates of the nearest point

[0055] First, define a coordinate conversion function named orth_to_geo. The input parameter is: orth, where orth is the spatial rectangular coordinate (x, y, z). Use the conversion formula between spatial rectangular coordinates and spherical polar coordinates to convert the spatial rectangular coordinates to geographic coordinates. According to the spatial rectangular coordinates calculated in 5.2, use the orth_to_geo() function to convert them to geographic coordinates (lon, lat).

[0056] By adopting the above technical solution: after all the above steps, the present invention can be used to encode the geographic location with high precision, while ensuring a low precision deviation after decoding.

[0057] Compared with the prior art, the present invention has the following beneficial effects:

[0058] 1. When using the same code length, the present invention has a lower decoding error than the existing GeoHash algorithm, and the decoding error is relatively evenly distributed across regions around the world.

[0059] 2. The present invention can control encoding accuracy by adjusting the code length, thereby adapting to the accuracy requirements of different application scenarios. At the same time, the decoding error decreases rapidly with increasing code length, and the decoding result converges quickly, ensuring high decoding accuracy while occupying a small amount of storage space.

[0060] 3. The character code generated by this invention generates a location key based on a Base64 code consisting of a random arrangement of 64 base characters. Compared to the 32-bit fixed Base32 character code used by the GeoHash algorithm, this character code is more secure and more difficult to crack, effectively resisting brute force and reverse engineering attacks. While maintaining the same encoding accuracy, this significantly improves the security of the location code and achieves stronger geographic information protection.

[0061] 4. The present invention utilizes spatial spherical triangles for layer-by-layer segmentation, and has significant hierarchical scalability. The encoding result strings corresponding to points with closer geographical locations have higher prefix similarity, and the nearest neighbor query can be converted into the longest common prefix match, thereby improving the efficiency of the nearest neighbor query. BRIEF DESCRIPTION OF THE DRAWINGS

[0062] Figure 1 is a flow chart of the present invention;

[0063] Figure 2 Schematic diagram of the unit sphere of the present invention;

[0064] Figure 3 Schematic diagram of the metasphere triangle segmentation of the present invention;

[0065] Figure 4 This is a functional diagram of the position_judge function of the present invention;

[0066] Figure 5 This is a functional diagram of the sph_mid function of the present invention;

[0067] Figure 6 A schematic diagram of the process of constructing a position code list according to the present invention;

[0068] Figure 7 This is a schematic diagram of the process of compressing position codes into character codes according to the present invention;

[0069] Figure 8 This is a schematic diagram of the character code decoding process of the present invention;

[0070] Figure 9 This is a schematic diagram of the position code parsing process of the present invention;

[0071] Figure 10 This is a comparison diagram of the decoding errors after encoding the geographic location using the present invention and the reference algorithm. DETAILED DESCRIPTION

[0072] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the accompanying drawings so that those skilled in the art can better understand the advantages and features of the present invention and thus more clearly define the scope of protection of the present invention. The embodiments described in the present invention are only some of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making any creative work shall fall within the scope of protection of the present invention.

[0073] like Figure 1 As shown, a geographic location encoding algorithm based on layer-by-layer segmentation of spatial spherical triangles includes the following steps:

[0074] Step 1: Split the metasphere into triangles;

[0075] Step 2: Convert geographic coordinates to spatial rectangular coordinates;

[0076] Step 3: Segment the spherical triangle encoding position layer by layer;

[0077] Step 4: Use the character code to compress the position code;

[0078] Step 5: Character code decoding and position code analysis.

[0079] Specifically, in step 1, the following steps are included:

[0080] Step 1.1: Abstract the Earth into a unit sphere

[0081] The real earth is an irregular ellipsoid with a slightly bulging equator and slightly flattened poles. To facilitate calculations, the earth needs to be abstracted and simplified. Let the center of the earth be O, the North Pole be N, the longitude and latitude point (180°E, 0°) be the spherical point P, and the longitude and latitude point (90°E, 0°) be the spherical point Q. With O as the origin, the straight line OP as the X-axis, the OP direction as the positive direction of the X-axis, the straight line OQ as the Y-axis, the OQ direction as the positive direction of the Y-axis, the straight line ON as the Z-axis, and the ON direction as the positive direction of the Z-axis, a spatial rectangular coordinate system O-XYZ is established, as shown in the following example: Figure 2 shown.

[0082] Abstract the surface of the earth as a sphere with a radius R in O-XYZ Σ:x 2 +y 2 +z 2 =R 2 In the present invention, the radius of the earth R has no effect on the algorithm implementation, so R = 1 is taken to facilitate calculation, that is, the sphere Σ is the unit sphere;

[0083] The agreed global longitude range is [-180°, 180°], with the prime meridian longitude being 0°, and increasing eastward from the prime meridian and decreasing westward; the agreed latitude range is [-90°, 90°], with the equatorial latitude being 0°, and increasing northward from the equator and decreasing southward;

[0084] Step 1.2: Construct a regular tetrahedron

[0085] Given four fixed points on Σ: E0(0,0,1), Construct the inscribed regular tetrahedron E0-E1E2E3 of Σ;

[0086] Step 1.3: Split the spherical triangle

[0087] Let OE0 = e0, OE1 = e1, OE2 = e2, OE3 = e3, let the vector group F0 = (e1, e2, e3), F1 = (e0, e2, e3), F2 = (e0, e1, e3), F3 = (e0, e1, e2), connect the 6 great circle segments between E0, E1, E2, E3, and divide Σ into 4 spherical triangle areas, such as Figure 3 As shown, the area number corresponding to F0 is 0, the area number corresponding to F1 is 1, the area number corresponding to F2 is 2, and the area number corresponding to F3 is 3.

[0088] Specifically, in step 2, the following steps are included:

[0089] First, define a coordinate conversion function named geo_to_orth with the following input parameters: lon, lat, where lon and lat represent longitude and latitude, respectively. Then, use the conversion formula between spherical polar coordinates and spatial rectangular coordinates to implement the above conversion function. Finally, use this function to convert the geographic coordinates (lon, lat) of the input point into spatial rectangular coordinates (x, y, z).

[0090] Specifically, in step 3, the following steps are included:

[0091] Step 3.1: Obtaining the first position code and determining the vector basis

[0092] First, define the position judgment function, named position_judge, with the following input parameters: F, T, where F represents the vector group (a, b, c), the initial basis vectors a, b, c all start from the coordinate origin O and are linearly independent, and T represents the target point (x, y, z) in space. OT is linearly represented with F as the basis, and the expression is OT = k1·a+k2·b+k3·c. If the coefficients k1, k2, k3 are all non-negative numbers, then T is within the conical space region determined by F, and the function returns 1; if k1, k2, k3 are not all non-negative numbers, then T is outside the conical space region determined by F, and the function returns 0. The function of position_judge is as follows: Figure 4 shown.

[0093] Then, use the geo_to_orth() function to convert the geographic coordinates of the point to be coded T into spatial rectangular coordinates, substitute the coordinate value into the position_judge function to determine the spherical triangle area number where the point to be coded T is located, as the first position code, the value is an integer between [0,3], and at the same time obtain the vector basis F corresponding to the area.

[0094] Step 3.2: Acquisition of subsequent position codes and update of vector bases

[0095] First, define a function to calculate the midpoint of a spherical great circle segment, named sph_mid, with the input parameters A and B, where A and B represent two different points on the sphere. Use the midpoint coordinate formula of a spherical great circle segment to calculate the coordinates of the midpoint M of the great circle segment between points A and B. Figure 5 Then, use the sph_mid function to calculate the coordinates of the three midpoints of the spherical triangle area determined in 3.1, and use the great circle segments between the midpoints to divide the spherical triangle area into four sub-spherical triangle areas. Finally, use the position_judge function to determine the sub-area where point T is located, and use the sub-area number as the new round of encoding, while updating the vector basis F. Repeat the above operation until the length of the position encoding list reaches the predetermined precision value pre, as shown in the following example. Figure 6 As shown, the present invention stipulates that pre must be a multiple of 3 and its value is at least 12. The larger the pre value, the smaller the precision loss.

[0096] Step 3.3: Processing method for boundary points

[0097] During the encoding process, some ground points may fall on the common edges of two spherical triangle regions or on the common vertices of six spherical triangle regions. To handle these boundary points, the present invention sets a truncation mechanism during the layer-by-layer segmentation of the spherical triangle: the four sub-regions of the current spherical triangle region are traversed in the order of codes 0, 1, 2, and 3. When an intersection between the target point and a current sub-region is detected (for example, located on the boundary), the sub-region number is used as the new 1-bit code of the target point, and the current sub-region is updated to the spherical triangle region of the next cycle. Then, the current traversal process is interrupted and the next round of segmentation is directly entered to obtain the next 1-bit code.

[0098] This mechanism can ensure that boundary points are properly and reasonably encoded, and the encoding is unique, while reducing unnecessary traversal and calculation, and improving encoding efficiency.

[0099] Specifically, in step 4, the following steps are included:

[0100] Step 4.1: Split the location code list

[0101] Split the position code list obtained in step 3 to generate a two-dimensional list consisting of pre / 3 one-dimensional lists containing three elements;

[0102] Step 4.2: Convert quaternary to decimal

[0103] Consider each one-dimensional list in the two-dimensional list obtained in 4.1 as a quaternary number, convert them into decimal numbers one by one and return them as elements of the one-dimensional list. It is easy to find that the decimal number corresponding to the three quaternary numbers ranges from 0 to 63.

[0104] Step 4.3, generate character code

[0105] First, design the Base64 character code, which consists of 64 randomly arranged base characters. The base characters include: numbers 0 to 9, 26 lowercase English letters, 26 uppercase English letters, and two special characters "@" and "#". The character index range in the Base64 character code is 0 to 63. Define the encoding rule: use integers as the index values of characters in the Base64 character code. To this end, the integer elements in the one-dimensional list obtained in 4.2 can be encoded as corresponding characters; finally, the determined character sequence is generated in sequence as a string; through the above process, the position code can be compressed into a character code, such as Figure 7 shown.

[0106] Specifically, in step 5, the following steps are included:

[0107] Step 5.1: Character code decoding

[0108] Perform the reverse process on the character code generated in step 4 to decode the encoded string;

[0109] First, use the Base64 character code to determine the index value corresponding to each character in the encoded string, return it as a list, then convert the index value into a quaternary number, and finally concatenate the two-dimensional list composed of several quaternary number lists into a one-dimensional list to decode the encoded string and generate a position code, such as Figure 8 shown.

[0110] Step 5.2: Location code analysis

[0111] Read the first bit of the position code to determine the spherical triangle area number where the target point T is located, and obtain the vector basis F corresponding to the area; divide the spherical triangle area based on the midpoint of the great circle segment, and then read the next bit of the code to determine the sub-area where T is located, and update the vector basis F; repeat the above operation until the position code list is read, as shown in the following example: Figure 9 This process will eventually calculate the spatial rectangular coordinates of the target point position based on the last updated vector basis F.

[0112] Step 5.3: Calculation of the geographical coordinates of the nearest point

[0113] First, define a coordinate conversion function named orth_to_geo. The input parameter is: orth, where orth is the spatial rectangular coordinate (x, y, z). Use the conversion formula between spatial rectangular coordinates and spherical polar coordinates to convert the spatial rectangular coordinates to geographic coordinates. According to the spatial rectangular coordinates calculated in 5.2, use the orth_to_geo() function to convert them to geographic coordinates (lon, lat).

[0114] After all the above steps, the present invention can be used to encode the geographic location with high precision, while ensuring low precision deviation after decoding.

[0115] In summary, the present invention utilizes spatial spherical triangles for layer-by-layer segmentation, and has significant hierarchical scalability. The encoding result strings corresponding to points with closer geographical locations have higher prefix similarity, and the nearest neighbor query can be converted into the longest common prefix match, thereby improving the efficiency of the nearest neighbor query.

[0116] The descriptions and practices disclosed in this invention are easy to understand and comprehend for those skilled in the art, and modifications and refinements may be made without departing from the principles of the invention. Therefore, modifications and improvements made without departing from the spirit of the invention should also be considered within the scope of protection of this invention.

Claims

1. A geographic location coding algorithm based on layer-by-layer segmentation of spatial spherical triangles, characterized in that: The steps include: Step 1: Split the metasphere into triangles; Step 2: Convert geographic coordinates to spatial rectangular coordinates; Step 3: Segment the spherical triangle encoding position layer by layer; Step 4: Use the character code to compress the position code; Step 5: Character code decoding and position code analysis.

2. The geographic location coding algorithm based on layer-by-layer segmentation of spatial spherical triangles according to claim 1, characterized in that: In step 1, the following steps are included: Step 1.1: Abstract the Earth into a unit sphere To facilitate calculations, the Earth needs to be abstracted and simplified. Let the center of the Earth be O, the North Pole be N, the longitude and latitude point (180°E, 0°) be spherical point P, and the longitude and latitude point (90°E, 0°) be spherical point Q. With O as the origin, the line OP as the X-axis, the OP direction as the positive X-axis direction, the line OQ as the Y-axis, the OQ direction as the positive Y-axis direction, the line ON as the Z-axis, and the ON direction as the positive Z-axis direction, a spatial rectangular coordinate system O-XYZ is established. Abstract the surface of the earth as a sphere with a radius R in O-XYZ Σ:x 2 +y 2 +z 2 =R 2 , the radius of the earth R has no effect on the algorithm implementation, so R = 1 is taken for the convenience of calculation, that is, the sphere Σ is the unit sphere; The agreed global longitude range is [-180°, 180°], with the prime meridian longitude being 0°, and increasing eastward from the prime meridian and decreasing westward; the agreed latitude range is [-90°, 90°], with the equatorial latitude being 0°, and increasing northward from the equator and decreasing southward; Step 1.2: Construct a regular tetrahedron Given four fixed points on Σ: E0(0,0,1), Construct the inscribed regular tetrahedron E0-E1E2E3 of Σ; Step 1.3: Split the spherical triangle Let OE0 = e0, OE1 = e1, OE2 = e2, OE3 = e3, and let the vector group F0 = (e1, e2, e3), F1 = (e0, e2, e3), F2 = (e0, e1, e3), F3 = (e0, e1, e2), connect the 6 great circle segments between E0, E1, E2, E3, and divide Σ into 4 spherical triangular areas. Let the area corresponding to F0 be numbered 0, the area corresponding to F1 be numbered 1, the area corresponding to F2 be numbered 2, and the area corresponding to F3 be numbered 3.

3. The geographic location coding algorithm based on layer-by-layer segmentation of spatial spherical triangles according to claim 1 is characterized in that: In step 2, the following steps are included: First, define the coordinate conversion function, named geo_to_orth, with input parameters: lon, lat. lon and lat represent longitude and latitude respectively; then, the conversion formula between spherical polar coordinates and spatial rectangular coordinates is used to implement the above conversion function; finally, this function is used to convert the geographic coordinates of the input point (lon, lat) into spatial rectangular coordinates (x, y, z).

4. The geographic location coding algorithm based on layer-by-layer segmentation of spatial spherical triangles according to claim 1, characterized in that: In step 3, the following steps are included: Step 3.1: Obtaining the first position code and determining the vector basis First, define a position judgment function named position_judge with the following input parameters: F and T, where F represents the vector group (a, b, c). The initial basis vectors a, b, c all start from the coordinate origin O and are linearly independent. T represents the target point (x, y, z) in space. OT is linearly represented with F as the basis, and the expression is OT = k1·a+k2·b+k3·c. If the coefficients k1, k2, and k3 are all non-negative, then T is within the conical space region determined by F, and the function returns 1. If k1, k2, and k3 are not all non-negative, then T is outside the conical space region determined by F, and the function returns 0. Then, use the geo_to_orth function to convert the geographic coordinates of the point to be coded T into spatial rectangular coordinates, substitute the coordinate value into the position_judge function to determine the spherical triangle area number where the point to be coded T is located, as the first position code, the value is an integer between [0,3], and at the same time obtain the vector basis F corresponding to the area; Step 3.2: Acquisition of subsequent position codes and update of vector bases First, define a spherical great circle segment midpoint calculation function named sph_mid, with the following input parameters: A and B, where A and B represent two different points on the sphere, respectively. Use the spherical great circle segment midpoint coordinate formula to calculate the coordinates of the midpoint M of the great circle segment between points A and B. Then, use the sph_mid function to calculate the coordinates of the three midpoints of the spherical triangle area determined in 3.

1. Use the great circle segments between the midpoints to divide the spherical triangle area into four sub-spherical triangle areas. Finally, use the position_judge function to determine the sub-area where point T is located, and use the sub-area number as the new round of encoding, while updating the vector basis F. Repeat the above operation until the length of the position encoding list reaches the predetermined precision value pre. Step 3.3: Processing method for boundary points A truncation mechanism is set during the layer-by-layer segmentation of the spherical triangle: the four sub-regions of the current spherical triangle region are traversed in the order of codes 0, 1, 2, and 3. When an intersection is detected between the target point and a current sub-region, the sub-region number is used as the new bit code of the target point, and the current sub-region is updated to the spherical triangle region of the next cycle. Then, the current traversal process is interrupted and the next round of segmentation is directly entered to obtain the next bit code.

5. The geographic location coding algorithm based on layer-by-layer segmentation of spatial spherical triangles according to claim 1 is characterized in that: In step 4, the following steps are included: Step 4.1: Split the location code list Split the position code list obtained in step 3 to generate a two-dimensional list consisting of pre / 3 one-dimensional lists containing three elements; Step 4.2: Convert quaternary to decimal Consider each one-dimensional list in the two-dimensional list obtained in 4.1 as a quaternary number, convert them into decimal numbers one by one and return them as elements of the one-dimensional list. It is easy to find that the decimal number corresponding to the three quaternary numbers ranges from 0 to 63. Step 4.3, generate character code First, design a Base64 character code. This code consists of 64 randomly arranged base characters. The base characters include the numbers 0 to 9, the 26 lowercase English letters, the 26 uppercase English letters, and the two special characters @ and #. The character index range in the Base64 character code is 0 to 63. Define the encoding rule: use integers as the index values of the characters in the Base64 character code. To this end, the integer elements in the one-dimensional list obtained in 4.2 can be encoded into the corresponding characters in the Base64 character code. Finally, the determined character sequence is sequentially generated into a string. The position code can be compressed into a character code through the above process.

6. The geographic location coding algorithm based on layer-by-layer segmentation of spatial spherical triangles according to claim 5, characterized in that: In step 5, the following steps are included: Step 5.1: Character code decoding Perform the reverse process on the character code generated in step 4 to decode the encoded string; First, use the Base64 character code to determine the index value corresponding to each character in the encoded string, return it as a list, then convert the index value into a quaternary number. Finally, concatenate the two-dimensional list consisting of several quaternary number lists into a one-dimensional list to decode the encoded string and generate the position code; Step 5.2: Location code analysis Read the first bit of the position code to determine the spherical triangle region number where the target point T is located, and obtain the vector basis F corresponding to the region; divide the spherical triangle region based on the midpoint of the great circle segment, then read the next bit of the code to determine the sub-region where T is located, and update the vector basis F; repeat the above operation until the position code list is read; executing this process will eventually calculate the spatial rectangular coordinates of the target point position based on the last updated vector basis F; Step 5.3: Calculation of the geographical coordinates of the nearest point First, define a coordinate conversion function named orth_to_geo. The input parameter is: orth, where orth is the spatial rectangular coordinate (x, y, z). Use the conversion formula between spatial rectangular coordinates and spherical polar coordinates to convert the spatial rectangular coordinates to geographic coordinates. According to the spatial rectangular coordinates calculated in 5.2, use the orth_to_geo() function to convert them to geographic coordinates (lon, lat).