Rapid neighbor search method, apparatus and device, medium and program product
By traversing the nine-square grid and adaptively adjusting the grid side length, the problems of large computational complexity and high complexity in the existing technology are solved, efficient location service calculation is achieved, and the user experience is improved.
Patent Information
- Application Number
- CN202510896960.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-30
- Publication Date
- 2025-10-14
AI Technical Summary
In the existing location-based services, the fuzzy matching method has a large amount of calculation and high algorithm complexity, while the Geohash encoding method easily ignores the location points around the edge of the grid, resulting in low calculation efficiency.
The method of nine-square grid traversal and adaptive adjustment of grid side length is adopted. By obtaining the initial grid angle side length, calibrating and updating the grid angle side length, rasterization processing is performed to avoid missing grid edge points, select the appropriate grid size, and reduce the distance calculation amount and algorithm complexity.
It greatly reduces the distance calculation amount and algorithm complexity, improves computing efficiency, and enhances the user experience.
Smart Images

Figure CN120780744A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a fast neighbor search method, device, equipment, medium and program product. Background Art
[0002] Currently, in location-based service (LBS) related technologies, there is a common requirement: given two or more sets of geographic locations from different sources, it is necessary to batch calculate a list of several points closest to a certain location point in one set of locations and another set of locations.
[0003] In related technologies, fuzzy matching or Geohash coding methods are usually used for calculation. However, in actual applications, it is found that traditional fuzzy matching methods are computationally intensive, have high algorithm complexity, and are inefficient, while Geohash coding methods tend to ignore points around the edges of the grid.
[0004] In summary, the technical problems existing in the relevant technologies need to be improved. Summary of the Invention
[0005] The embodiments of the present application provide a fast neighbor search method, apparatus, device, medium and program product, which can significantly reduce the distance calculation amount and algorithm complexity, improve computing efficiency, and effectively improve the user experience.
[0006] In one aspect, an embodiment of the present application provides a fast neighbor search method, the method comprising the following steps:
[0007] Obtaining a geographic location set to be processed; wherein the geographic location set includes a first geographic location set and a second geographic location set; the first geographic location set and the second geographic location set each include a plurality of geographic location points, each of the geographic location points including longitude coordinate information and latitude coordinate information;
[0008] Obtaining an initial grid angle side length, and rasterizing the first set of geographic locations and the second set of geographic locations to obtain a first grid set corresponding to the first set of geographic locations and a second grid set corresponding to the second set of geographic locations;
[0009] Taking any geographical location point in any geographical location set as the target location, determining the grid code information of the target location in the corresponding grid set, and obtaining an initial nine-square grid based on the grid code information from another grid set;
[0010] Obtaining the number of geographic location points within the initial nine-square grid, and calibrating the initial grid angle side length based on a numerical relationship between the number of geographic location points and a preset threshold value to obtain an updated grid angle side length;
[0011] Re-rasterizing the target position and the initial nine-square grid based on the updated grid angle side length to obtain updated grid coding information of the target position and an updated nine-square grid set;
[0012] Acquire an updated nine-square grid based on the updated grid coding information from the updated nine-square grid set;
[0013] The distances between all geographical locations in the updated nine-square grid and the target location are determined to obtain a fast neighbor search result for the target location.
[0014] Optionally, obtaining the number of geographic location points in the initial nine-square grid, and calibrating the initial grid angle side length according to a numerical relationship between the number of geographic location points and a preset threshold to obtain an updated grid angle side length includes:
[0015] Obtaining the number of geographic location points within the initial nine-square grid;
[0016] When the number of the geographical location points is greater than or equal to a first preset threshold, obtaining a product of the initial grid angle side length and a first preset value to obtain the updated grid angle side length;
[0017] When the number of geographic location points is less than the first preset threshold and the number of geographic location points is greater than a second preset threshold, calibrating the initial grid angle side length based on an arithmetic square root of a ratio of the second preset threshold to the number of geographic location points to obtain the updated grid angle side length;
[0018] When the number of the geographical location points is less than or equal to the second preset threshold, the initial grid angle side length is kept unchanged and used as the updated grid angle side length.
[0019] Optionally, obtaining the initial grid angle side length, rasterizing the first set of geographic locations and the second set of geographic locations to obtain a first raster set corresponding to the first set of geographic locations and a second raster set corresponding to the second set of geographic locations includes:
[0020] Obtaining the initial grid angle side length; wherein the initial grid angle side length includes the initial longitude angle side length and the initial latitude angle side length;
[0021] According to the longitude coordinate information of any geographical location point in any geographical location set, obtaining a ratio of the longitude coordinate information to the length of the initial longitude angle and rounding it up as the longitude grid code information of the any geographical location point;
[0022] According to the latitude coordinate information of any geographical location point in any geographical location set, obtaining a ratio of the latitude coordinate information to the length of the initial latitude angle and rounding it up as the latitude grid code information of the any geographical location point;
[0023] rasterizing the first set of geographical locations by acquiring longitude grid code information and latitude grid code information of each geographical location point in the first set of geographical locations, thereby obtaining a first grid set corresponding to the first set of geographical locations;
[0024] By acquiring the longitude grid coding information and the latitude grid coding information of each geographical location point in the second geographical location set, the second geographical location set is rasterized to obtain a second grid set corresponding to the second geographical location set.
[0025] Optionally, obtaining the initial grid angle side length includes:
[0026] Based on the preset reference point and the spherical cosine formula, the distance corresponding to the unit latitude difference and the distance corresponding to the unit longitude difference are calculated;
[0027] Get the preset initial grid distance side length;
[0028] Calculating the ratio of the initial grid distance side length to the distance corresponding to the unit longitude difference to obtain the initial longitude angle side length;
[0029] Calculating the ratio of the initial grid distance side length to the distance corresponding to the unit latitude difference to obtain the initial latitude angle side length;
[0030] The initial grid angle side length is obtained based on the initial longitude angle side length and the initial latitude angle side length.
[0031] Optionally, after determining the distances between all geographical locations in the updated nine-square grid and the target location and obtaining a fast neighbor search result for the target location, the method further includes:
[0032] Return to the step of taking any geographic location point in any geographic location set as the target location, determining the grid code information of the target location in the corresponding grid set, and obtaining an initial nine-square grid based on the grid code information from another grid set, until the fast neighbor search results for each geographic location point in all geographic location sets are determined.
[0033] Optionally, determining the distances between all geographical locations in the updated nine-square grid and the target location to obtain a fast neighbor search result for the target location includes:
[0034] Obtaining the longitude and latitude coordinate information of all geographic locations within the updated nine-square grid and the target location, and calculating the distances between all geographic locations within the updated nine-square grid and the target location based on the spherical cosine formula;
[0035] The distances between all geographical locations in the updated nine-square grid and the target location are sorted from smallest to largest to obtain a fast neighbor search result of the target location.
[0036] On the other hand, an embodiment of the present application provides a fast neighbor search device, the device comprising:
[0037] a location set acquisition module, configured to acquire a location set to be processed; wherein the location set includes a first location set and a second location set; the first location set and the second location set each include a plurality of location points, each including longitude coordinate information and latitude coordinate information;
[0038] a grid set acquisition module, configured to acquire an initial grid angle side length, and rasterize the first set of geographic locations and the second set of geographic locations to obtain a first grid set corresponding to the first set of geographic locations and a second grid set corresponding to the second set of geographic locations;
[0039] A nine-square grid determination module is configured to determine the grid code information of any geographical location point in any geographical location set as the target location, and obtain an initial nine-square grid based on the grid code information from another grid set;
[0040] An angle side length calibration module, configured to obtain the number of geographic location points within the initial nine-square grid, and calibrate the initial grid angle side length based on a numerical relationship between the number of geographic location points and a preset threshold value to obtain an updated grid angle side length;
[0041] A grid set updating module, configured to re-grid the target position and the initial nine-square grid based on the updated grid angle side length, obtain updated grid coding information of the target position, and update the nine-square grid set;
[0042] A nine-square grid updating module, configured to obtain an updated nine-square grid based on the updated grid coding information from the updated nine-square grid set;
[0043] The fast neighbor search module is used to determine the distance between all geographical locations in the updated nine-square grid and the target location, and obtain a fast neighbor search result of the target location.
[0044] On the other hand, an embodiment of the present application provides an electronic device, which includes a memory and a processor, wherein the memory stores a computer program, and the processor implements the above method when executing the computer program.
[0045] On the other hand, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the above method is implemented.
[0046] On the other hand, an embodiment of the present application provides a computer program product, including a computer program, which implements the above method when executed by a processor.
[0047] The embodiment of the present application adopts a nine-square grid traversal to avoid missed detection of grid edge points, and adaptively adjusts the grid side length to select a more appropriate grid size, thereby significantly reducing the distance calculation amount and algorithm complexity, improving computing efficiency, and effectively improving the user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 Schematic diagram of an implementation environment of a fast neighbor search method provided in an embodiment of the present application;
[0049] Figure 2 This is a flowchart of a fast neighbor search method provided by an embodiment of the present application;
[0050] Figure 3 is a schematic diagram of a grid set provided in an embodiment of the present application;
[0051] Figure 4 This is a schematic diagram of determining an initial nine-square grid provided in an embodiment of the present application;
[0052] Figure 5 This is a schematic diagram of determining and updating a nine-square grid provided by an embodiment of the present application;
[0053] Figure 6 This is a schematic structural diagram of a fast neighbor search device provided in an embodiment of the present application;
[0054] Figure 7 This is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0055] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application is further described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the embodiments of the present application. They are merely examples of devices and methods consistent with some aspects of the embodiments of the present application as detailed in the appended claims.
[0056] It will be understood that the terms "first", "second", etc. used in this application may be used herein to describe various concepts, but unless otherwise specified, these concepts are not limited by these terms. These terms are only used to distinguish one concept from another. For example, without departing from the scope of the embodiments of the present application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the words "if" and "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0057] The terms "at least one", "plurality", "each", "any", etc. used in this application include "at least one", "two" or more, "plurality" or "each", "any" or "any one", "each" or "any one" as used herein.
[0058] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which this application pertains. The terms used herein are for the purpose of describing the embodiments of this application only and are not intended to limit this application.
[0059] Currently, in location-based service (LBS) related technologies, there is a common requirement: given two or more sets of geographic locations from different sources, it is necessary to batch calculate a list of several points closest to a certain location point in one set of locations and another set of locations.
[0060] In related technologies, fuzzy matching or Geohash coding methods are usually used for calculation. However, in actual applications, it is found that traditional fuzzy matching methods are computationally intensive, have high algorithm complexity, and are inefficient, while Geohash coding methods tend to ignore points around the edges of the grid.
[0061] In view of this, the embodiments of the present application provide a fast neighbor search method, device, equipment, medium and program product, which avoids the omission of grid edge points by adopting a nine-square grid traversal, and selects a more appropriate grid size by adaptively adjusting the grid side length, thereby greatly reducing the distance calculation amount and algorithm complexity, improving computing efficiency, and effectively improving the user experience.
[0062] It should be noted that in each specific embodiment of the present application, when it comes to the need to perform relevant processing based on data related to the user's identity or characteristics, such as user information, user behavior data, user historical data, and user location information, the user's permission or consent will be obtained first, and the collection, use, and processing of such data will comply with relevant laws, regulations, and standards. In addition, when the embodiment of the present application needs to obtain the user's sensitive personal information, the user's separate permission or consent will be obtained through a pop-up window or by jumping to a confirmation page. After clearly obtaining the user's separate permission or consent, the necessary user-related data for the normal operation of the embodiment of the present application will be obtained.
[0063] The following describes the specific implementation of the embodiment of the present application in detail with reference to the accompanying drawings. First, a fast neighbor search method provided in the embodiment of the present application is described with reference to the accompanying drawings.
[0064] Please refer to Figure 1 , Figure 1 1 is a schematic diagram of an implementation environment of a fast neighbor search method provided by an embodiment of the present application. In this implementation environment, the main hardware and software entities involved include a terminal processor 110 and a server 120.
[0065] Specifically, the terminal processor 110 may be installed with a control program for a related fast neighbor search method, and the server 120 is the backend server for the control program. The terminal processor 110 and the backend server 120 are in communication with each other. The fast neighbor search method provided in the embodiments of the present application may be executed on the terminal processor 110 side.
[0066] Server 120 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), as well as big data and artificial intelligence platforms.
[0067] In addition, the server 120 may also be a node server in the blockchain network.
[0068] A communication connection can be established between the terminal processor 110 and the server 120 via a wireless network. The wireless network uses standard communication technologies and / or protocols. The network can be the Internet or any other network, including, but not limited to, a local area network (LAN), a metropolitan area network (MAN), a wide area network (WAN), a mobile network, or any combination of a wireless network, a private network, or a virtual private network. Furthermore, the aforementioned software and hardware entities can use the same or different communication connection methods, and this application does not impose any specific restrictions on this.
[0069] Of course, it is understandable that Figure 1 The implementation environment in the embodiment of the present application is only some optional application scenarios of the fast neighbor search method provided in the embodiment of the present application. The actual application is not fixed to Figure 1 The software and hardware environment shown is not specifically limited in this application.
[0070] like Figure 2 As shown, Figure 2 This is a flowchart of a fast neighbor search method provided in an embodiment of the present application, specifically including but not limited to steps S100 to S700.
[0071] Step S100, obtaining a set of geographic locations to be processed; wherein the set of geographic locations includes a first geographic location set and a second geographic location set; the first geographic location set and the second geographic location set each include multiple geographic location points, each of which includes longitude coordinate information and latitude coordinate information.
[0072] In an embodiment of the present application, a fast neighbor search task can be generated by responding to a dispatch, and a set of geographic locations to be processed corresponding to the task target can be obtained from the server. For example, the two obtained geographic location sets can be respectively determined as a first geographic location set and a second geographic location set.
[0073] Furthermore, the acquired geographical location set may include multiple different geographical location points, and each geographical location point may be identified by latitude and longitude coordinate information to identify specific geographical location information.
[0074] Step S200: Obtain the initial grid angle side length, and rasterize the first geographic location set and the second geographic location set to obtain a first grid set corresponding to the first geographic location set and a second grid set corresponding to the second geographic location set.
[0075] In an embodiment of the present application, the initial grid angle side lengths are the longitude angle change amplitude and the latitude angle change amplitude corresponding to the side lengths of each grid. For example, when the initial grid angle side lengths correspond to a longitude angle change amplitude of 10 degrees, the first group of grids corresponds to geographic location points with longitude coordinates of 0 to 10 degrees, and the second group of grids corresponds to geographic location points with longitude coordinates of 10 to 20 degrees.
[0076] Furthermore, when the first geographic location set and the second geographic location set are rasterized, the grid grouping information can be confirmed for each geographic location point in the first geographic location set, and the grid grouping information can be confirmed for each geographic location point in the second geographic location set, and the grid number of each geographic location point can be determined by two-dimensional coding.
[0077] For example, please refer to Figure 3 , Figure 3 This is a schematic diagram of a grid set provided by an embodiment of the present application. Each black dot in the figure represents a geographic location. Based on the longitude and latitude coordinates of each geographic location, combined with the initial grid angle side length, the grid code information corresponding to each geographic location can be determined. For example, encoding is performed based on different rows and columns. The first grid set may include 16 grid groups, from A(i, j) to A(i+3, j+3), and the second grid set may include 16 grid groups, from B(i, j) to B(i+3, j+3). Using the grid code information of different grids (e.g., i+1, j+2), the corresponding geographic location points within the grid code (e.g., A(i+1, j+2) and B(i+1, j+2)) can be quickly and uniquely retrieved. In other words, the first grid set corresponding to the first geographic location set and the second grid set corresponding to the second geographic location set can share the same grid code rules and be distinguished by different alphabetic prefixes, facilitating subsequent rapid identification of the nine-square grid.
[0078] In practical applications, obtaining the initial grid angle side length, rasterizing the first set of geographic locations and the second set of geographic locations to obtain a first grid set corresponding to the first set of geographic locations and a second grid set corresponding to the second set of geographic locations includes:
[0079] Obtaining the initial grid angle side length; wherein the initial grid angle side length includes the initial longitude angle side length and the initial latitude angle side length;
[0080] According to the longitude coordinate information of any geographical location point in any geographical location set, obtaining a ratio of the longitude coordinate information to the length of the initial longitude angle and rounding it up as the longitude grid code information of the any geographical location point;
[0081] According to the latitude coordinate information of any geographical location point in any geographical location set, obtaining a ratio of the latitude coordinate information to the length of the initial latitude angle and rounding it up as the latitude grid code information of the any geographical location point;
[0082] rasterizing the first set of geographical locations by acquiring longitude grid code information and latitude grid code information of each geographical location point in the first set of geographical locations, thereby obtaining a first grid set corresponding to the first set of geographical locations;
[0083] By acquiring the longitude grid coding information and the latitude grid coding information of each geographical location point in the second geographical location set, the second geographical location set is rasterized to obtain a second grid set corresponding to the second geographical location set.
[0084] In the embodiment of the present application, the obtained initial grid angle side lengths mainly include the initial longitude angle side lengths and the initial latitude angle side lengths, which respectively represent the longitude angle change amplitude and the latitude angle change amplitude corresponding to each grid side length.
[0085] Furthermore, the longitude coordinate information of any geographic location in any geographic location set is obtained, and the longitude coordinate information of the geographic location is divided by the length of the initial longitude angle. The calculated ratio is rounded up to the nearest integer, and the longitude grid code information of the geographic location is obtained. For example, if the longitude coordinate information of a geographic location is 65 degrees and the length of the initial longitude angle is 10 degrees, the calculated ratio is 6.5, and the longitude grid code information of the geographic location is rounded up to 7.
[0086] Furthermore, the latitude coordinate information of any geographic point in any geographic location set is obtained, and the latitude coordinate information of the geographic point is divided by the length of the initial latitude angle. The calculated ratio is rounded up to the nearest integer, and the latitude grid code information of the geographic point is obtained. For example, if the latitude coordinate information of a geographic point is 50 degrees and the length of the initial longitude angle is 4 degrees, the calculated ratio is 12.5, and the latitude grid code information of the geographic point is rounded up to the nearest integer.
[0087] Therefore, by traversing and calculating the longitude raster coding information and latitude raster coding information of each geographic location point in the first geographic location set, the rasterization of the first geographic location set can be completed, and based on the raster coding information of each geographic location point, the corresponding first raster set can be obtained and determined; further, by traversing and calculating the longitude raster coding information and latitude raster coding information of each geographic location point in the second geographic location set, the rasterization of the second geographic location set can be completed, and based on the raster coding information of each geographic location point, the corresponding second raster set can be obtained and determined.
[0088] Specifically, as an optional implementation manner, obtaining the initial grid angle side length includes:
[0089] Based on the preset reference point and the spherical cosine formula, the distance corresponding to the unit latitude difference and the distance corresponding to the unit longitude difference are calculated;
[0090] Get the preset initial grid distance side length;
[0091] Calculating the ratio of the initial grid distance side length to the distance corresponding to the unit longitude difference to obtain the initial longitude angle side length;
[0092] Calculating the ratio of the initial grid distance side length to the distance corresponding to the unit latitude difference to obtain the initial latitude angle side length;
[0093] The initial grid angle side length is obtained based on the initial longitude angle side length and the initial latitude angle side length.
[0094] In an embodiment of the present application, the spherical cosine formula can be used to quickly calculate the distance between two points. Taking into account the spherical characteristics of the earth, the physical distances represented by the same longitude difference near different latitudes are different, while the physical distance represented by the same latitude difference is basically stable.
[0095] Therefore, by obtaining a preset reference point and using the spherical cosine formula, the distance corresponding to the unit latitude difference and the distance corresponding to the unit longitude difference can be calculated.
[0096] Exemplarily, the reference point can be a first reference point A (lon1, lat1) and a second reference point B (lon2, lat2), where lon1 is the longitude coordinate information of the first reference point A, lat1 is the latitude coordinate information of the first reference point A, lon2 is the longitude coordinate information of the second reference point B, and lat2 is the latitude coordinate information of the second reference point B.
[0097] Furthermore, when calculating the distance corresponding to the unit longitude difference, lat1=lat2=60, lon2=lon1+0.00001 can be set, that is, the latitude of the first reference point A and the second reference point B is the same and is located at 60 degrees, and the longitude difference between the first reference point A and the second reference point B is 0.00001 degrees. The distance between the first reference point A and the second reference point B is calculated according to the spherical cosine formula, which can be used as the distance corresponding to the unit longitude difference.
[0098] Furthermore, when calculating the distance corresponding to the unit latitude difference, lon1=lon2, lat2=lat1+0.00001 can be set, that is, the longitude of the first reference point A and the second reference point B are the same, and the latitude of the first reference point A and the second reference point B differ by 0.00001 degrees. The distance between the first reference point A and the second reference point B can be calculated according to the spherical cosine formula, which can be used as the distance corresponding to the unit latitude difference.
[0099] Furthermore, the preset initial grid distance side length is obtained. For example, the side length of each square grid can be set to 1000 meters. Then, combined with the distance corresponding to the unit longitude difference and the distance corresponding to the unit latitude difference obtained above, the ratio result can be calculated by division to obtain the initial longitude angle side length and the initial latitude angle side length. Finally, the initial grid angle side length is determined based on the initial longitude angle side length and the initial latitude angle side length, so as to facilitate the subsequent determination of the grid coding information of different geographical locations.
[0100] Step S300: Taking any geographical location point in any geographical location set as a target location, determining grid code information of the target location in a corresponding grid set, and obtaining an initial nine-square grid based on the grid code information from another grid set.
[0101] In the embodiment of the present application, any geographical location point in any geographical location set may be selected as a target location, and neighboring location points of the target location in another geographical location set may be determined.
[0102] In actual application, please refer to Figure 4 , Figure 4 This is a schematic diagram of determining an initial nine-square grid provided by an embodiment of the present application. For example, a geographical location point in the second position set is determined to be the target position, and the grid coding information of the target position in the corresponding grid set is (i+2, j+1). Then, the initial nine-square grid based on the coding information can be obtained in another grid set, that is, the first grid set, through the coding information, that is, a total of 9 grids consisting of A(i+2, j+1) as the center and 8 adjacent grids, as the initial nine-square grid.
[0103] Step S400: Obtain the number of geographic location points in the initial nine-square grid, and calibrate the initial grid angle side length according to the numerical relationship between the number of geographic location points and a preset threshold value to obtain an updated grid angle side length.
[0104] In an embodiment of the present application, considering that if there are too many geographic location points in the initial nine-square grid, there will still be problems such as excessive computational complexity when judging the neighbor distances one by one, therefore, the number of geographic location points in the initial nine-square grid can be obtained, and the initial grid angle side length can be calibrated based on the numerical relationship between the number of geographic location points and the preset threshold value to obtain the updated grid angle side length, so as to facilitate subsequent re-gridding based on the updated grid angle side length.
[0105] In practical applications, obtaining the number of geographic location points in the initial nine-square grid and calibrating the initial grid angle side length according to the numerical relationship between the number of geographic location points and a preset threshold to obtain the updated grid angle side length includes:
[0106] Obtaining the number of geographic location points within the initial nine-square grid;
[0107] When the number of the geographical location points is greater than or equal to a first preset threshold, obtaining a product of the initial grid angle side length and a first preset value to obtain the updated grid angle side length;
[0108] When the number of geographic location points is less than the first preset threshold and the number of geographic location points is greater than a second preset threshold, calibrating the initial grid angle side length based on an arithmetic square root of a ratio of the second preset threshold to the number of geographic location points to obtain the updated grid angle side length;
[0109] When the number of the geographical location points is less than or equal to the second preset threshold, the initial grid angle side length is kept unchanged and used as the updated grid angle side length.
[0110] In an embodiment of the present application, after obtaining the number of geographic location points in the initial nine-square grid, the initial grid angle side length can be calibrated based on the numerical relationship between the number of geographic location points and the first preset threshold and the second preset threshold, so as to select a more appropriate grid size by adaptively adjusting the grid side length, reduce the grid area, and thus reduce the number of candidate geographic location points, greatly reduce the distance calculation amount and algorithm complexity, and improve computing efficiency.
[0111] In practical applications, the second preset threshold can be set equal to the number of neighbor search targets, and the first preset threshold can be set twice the number of neighbor search targets. When the number of geographic location points is greater than or equal to the first preset threshold, the updated grid angle length can be obtained by multiplying the initial grid angle length by the first preset value. The first preset value is a positive number less than 1.
[0112] For example, when the number of geographic location points is greater than or equal to a first preset threshold, the initial grid angle length can be calibrated using the formula: Updated grid angle length = Initial grid angle length × sqrt(0.5), thereby obtaining the updated grid angle length. Here, sqrt(0.5) is the first preset value, and sqrt() is a square root operation.
[0113] When the number of geographic location points is less than the first preset threshold and the number of geographic location points is greater than the second preset threshold, the initial grid angle length can be calibrated using the calculation formula of updated grid angle side length = initial grid angle side length × sqrt(second preset threshold ÷ number of geographic location points) to obtain the updated grid angle side length. The initial grid angle side length is scaled according to the ratio of the second preset threshold and the number of geographic location points, so that the number of geographic location points in the nine-square grid approaches the target number.
[0114] When the number of geographical location points is less than or equal to the second preset threshold, the initial grid angle side length may be kept unchanged and used as the updated grid angle side length.
[0115] It is understandable that when the number of geographic location points is less than the second preset threshold and does not meet the target number, the nine-square grid can be expanded to a twenty-five-square grid or other shapes to obtain more geographic location points by obtaining a larger grid shape.
[0116] In practical applications, after completing the above calibration of the initial grid angle side length to obtain the updated grid angle side length, the number of geographic location points in the nine-square grid can be obtained again, the above calibration process can be repeated, and appropriate loop end conditions can be set in advance. For example, the loop end condition can be set to stop the loop after reaching a preset number of loops, or the number of geographic location points in the nine-square grid meets the target number.
[0117] It can be understood that the above-mentioned first preset threshold, second preset threshold and other parameters are just some optional application settings in the fast neighbor search method provided in the embodiments of this application. The actual application is not fixed to the specific values shown in the above embodiments. This application does not impose specific restrictions on this, and users can set them according to the specific usage scenario requirements.
[0118] Step S500, re-grid the target position and the initial nine-square grid based on the updated grid angle side length, to obtain updated grid encoding information of the target position and an updated nine-square grid set.
[0119] In the embodiment of the present application, the target position and the initial nine-square grid are re-gridded by using the updated grid angle side length obtained after calibration, to obtain updated grid encoding information of the target position and an updated nine-square grid set.
[0120] Exemplarily, please refer to Figure 5 , Figure 5 is a schematic diagram for determining an updated nine-square grid provided by the embodiment of the present application. After the updated grid angle side length is obtained by calibrating the initial grid distance side length, the grid encoding information of the target position is recalculated according to the updated grid angle side length, to obtain updated grid encoding information of the target position, and the initial nine-square grid is re-gridded to obtain an updated nine-square grid set.
[0121] Therefore, after re-gridding by using the updated grid angle side length, the number of geographic position points in the updated nine-square grid can be effectively reduced, the most suitable grid size is adaptively explored and selected, the distance calculation amount is greatly reduced, and the operation efficiency is improved.
[0122] Step S600, obtaining an updated nine-square grid based on the updated grid encoding information from the updated nine-square grid set.
[0123] In the embodiment of the present application, as Figure 5 shown, the updated nine-square grid based on the updated grid encoding information can be obtained from the updated nine-square grid set according to the updated grid encoding information of the target position, so as to calculate the distance between all geographic position points in the updated nine-square grid and the target position in subsequent calculation.
[0124] Step S700, determining the distance between all geographic position points in the updated nine-square grid and the target position, to obtain a fast neighbor search result of the target position.
[0125] In the embodiment of the present application, when the final updated nine-square grid is determined, the distance between all geographic position points in the updated nine-square grid and the target position can be calculated, to obtain a fast neighbor search result of the target position.
[0126] In actual application, the determination of the distance between all geographic position points in the updated nine-square grid and the target position, to obtain a fast neighbor search result of the target position, comprises:
[0127] Obtaining the longitude and latitude coordinate information of all geographic locations within the updated nine-square grid and the target location, and calculating the distances between all geographic locations within the updated nine-square grid and the target location based on the spherical cosine formula;
[0128] The distances between all geographical locations in the updated nine-square grid and the target location are sorted from smallest to largest to obtain a fast neighbor search result of the target location.
[0129] In an embodiment of the present application, the distance between each geographical location point and the target location can be calculated based on the updated latitude and longitude coordinate information of the geographical location points in the nine-square grid and the latitude and longitude information of the target location according to the spherical cosine formula, and sorted from small to large to screen out several geographical location points closest to the target location as the fast neighbor search results of the target location.
[0130] In practical applications, after determining the distances between all geographical locations in the updated nine-square grid and the target location and obtaining a fast neighbor search result for the target location, the method further includes:
[0131] Return to the step of taking any geographic location point in any geographic location set as the target location, determining the grid code information of the target location in the corresponding grid set, and obtaining an initial nine-square grid based on the grid code information from another grid set, until the fast neighbor search results for each geographic location point in all geographic location sets are determined.
[0132] In an embodiment of the present application, after completing the above-mentioned step of taking any geographic location point as the target location and obtaining the fast neighbor search result of the target location, you can return to the step of determining the target location, select another geographic location point as the target location, and repeat the above-mentioned step process of obtaining the fast neighbor search result of the target location until the fast neighbor search result of each geographic location point in all geographic location sets is traversed and determined, thereby completing the fast neighbor search task of the geographic location set to be processed, so that after completing the geographic location set from given multiple channel sources, batch calculate the list of several points closest to a certain location point in a certain location set and another location set, effectively meeting the user's usage needs.
[0133] See also Figure 6 , Figure 6 is a structural diagram of a fast neighbor search device provided in an embodiment of the present application. The embodiment of the present application also provides a fast neighbor search device that can implement the above-mentioned fast neighbor search method, and the device includes:
[0134] A location set acquisition module 610 is configured to acquire a location set to be processed; wherein the location set includes a first location set and a second location set; each of the first location set and the second location set includes a plurality of location points, each of which includes longitude and latitude coordinate information;
[0135] A grid set acquisition module 620 is configured to acquire an initial grid angle side length, and to rasterize the first set of geographic locations and the second set of geographic locations to obtain a first grid set corresponding to the first set of geographic locations and a second grid set corresponding to the second set of geographic locations.
[0136] The nine-grid determination module 630 is configured to determine the grid code information of any geographic location point in any geographic location set as the target location, and obtain an initial nine-grid grid based on the grid code information from another grid set;
[0137] Angle and side length calibration module 640 is used to obtain the number of geographic location points in the initial nine-square grid, and calibrate the initial grid angle and side length based on the numerical relationship between the number of geographic location points and a preset threshold value to obtain an updated grid angle and side length;
[0138] A grid set updating module 650 is configured to re-rasterize the target position and the initial nine-square grid based on the updated grid angle side length, obtain updated grid coding information of the target position, and update the nine-square grid set;
[0139] A nine-square grid updating module 660 is configured to obtain an updated nine-square grid based on the updated grid coding information from the updated nine-square grid set;
[0140] The fast neighbor search module 670 is used to determine the distance between all geographical locations in the updated nine-square grid and the target location, and obtain fast neighbor search results for the target location.
[0141] It can be understood that the contents of the above method embodiments are all applicable to the present device embodiments, the functions specifically implemented by the present device embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0142] See also Figure 7 , Figure 7 : This is a hardware structure diagram of an electronic device provided in an embodiment of the present application. The electronic device includes:
[0143] The processor 701 may be implemented as a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is configured to execute relevant programs to implement the technical solutions provided in the embodiments of the present application.
[0144] The memory 702 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 702 can store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 702 and is called by the processor 701 to execute the above-mentioned methods of the embodiments of this application.
[0145] Input / output interface 703, used to implement information input and output;
[0146] Communication interface 704, used to implement communication interaction between this device and other devices, which can be achieved through wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, WiFi, Bluetooth, etc.);
[0147] Bus 705 , which transmits information between various components of the device (e.g., processor 701 , memory 702 , input / output interface 703 , and communication interface 704 );
[0148] The processor 701 , the memory 702 , the input / output interface 703 and the communication interface 704 are connected to each other in communication within the device via a bus 705 .
[0149] An embodiment of the present application further provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the above method is implemented.
[0150] It can be understood that the contents of the above method embodiments are all applicable to the present storage medium embodiment, the functions specifically implemented by the present storage medium embodiment are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0151] An embodiment of the present application also provides a computer program product, including a computer program, which implements the above method when executed by a processor.
[0152] It is understandable that the contents of the above method embodiments are all applicable to the present program product embodiments, the functions specifically implemented by the present program product embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0153] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely arranged relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0154] The embodiments of the present application provide a fast neighbor search method, device, equipment, medium and program product, which avoids missing grid edge points by adopting a nine-square grid traversal, and selects a more appropriate grid size by adaptively adjusting the grid side length, thereby significantly reducing the distance calculation amount and algorithm complexity, improving computing efficiency, and effectively improving the user experience.
[0155] The embodiments described in the embodiments of this application are intended to more clearly illustrate the technical solutions of the embodiments of this application and do not constitute a limitation on the technical solutions provided by the embodiments of this application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of this application are also applicable to similar technical problems.
[0156] Those skilled in the art will understand that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than shown in the figures, or a combination of certain steps, or different steps.
[0157] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, i.e., they may be located in one place or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of this embodiment.
[0158] Those skilled in the art will appreciate that all or some of the steps in the methods, systems, and functional modules / units in the devices disclosed above may be implemented as software, firmware, hardware, or appropriate combinations thereof.
[0159] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0160] It should be understood that in this application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following items" or similar expressions refers to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0161] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of the above-mentioned units is only a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0162] The units described above as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0163] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0164] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes multiple instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: various media that can store programs, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0165] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but are not intended to limit the scope of the present invention. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and essence of the present invention should be within the scope of the present invention.
Claims
1. A fast nearest neighbor search method, characterized in that: The method comprises the following steps: Obtaining a geographic location set to be processed; wherein the geographic location set includes a first geographic location set and a second geographic location set; the first geographic location set and the second geographic location set each include a plurality of geographic location points, each of the geographic location points including longitude coordinate information and latitude coordinate information; Obtaining an initial grid angle side length, and rasterizing the first set of geographic locations and the second set of geographic locations to obtain a first grid set corresponding to the first set of geographic locations and a second grid set corresponding to the second set of geographic locations; Taking any geographical location point in any geographical location set as the target location, determining the grid code information of the target location in the corresponding grid set, and obtaining an initial nine-square grid based on the grid code information from another grid set; Obtaining the number of geographic location points within the initial nine-square grid, and calibrating the initial grid angle side length based on a numerical relationship between the number of geographic location points and a preset threshold value to obtain an updated grid angle side length; Re-rasterizing the target position and the initial nine-square grid based on the updated grid angle side length to obtain updated grid coding information of the target position and an updated nine-square grid set; Acquire an updated nine-square grid based on the updated grid coding information from the updated nine-square grid set; The distances between all geographical locations in the updated nine-square grid and the target location are determined to obtain a fast neighbor search result for the target location.
2. The method according to claim 1, characterized in that The obtaining of the number of geographic location points in the initial nine-square grid and calibrating the initial grid angle side length according to a numerical relationship between the number of geographic location points and a preset threshold value to obtain an updated grid angle side length includes: Obtaining the number of geographic location points within the initial nine-square grid; When the number of the geographical location points is greater than or equal to a first preset threshold, obtaining a product of the initial grid angle side length and a first preset value to obtain the updated grid angle side length; When the number of geographic location points is less than the first preset threshold and the number of geographic location points is greater than a second preset threshold, calibrating the initial grid angle side length based on an arithmetic square root of a ratio of the second preset threshold to the number of geographic location points to obtain the updated grid angle side length; When the number of the geographical location points is less than or equal to the second preset threshold, the initial grid angle side length is kept unchanged and used as the updated grid angle side length.
3. The method according to claim 1, characterized in that The obtaining of the initial grid angle side length, rasterizing the first set of geographic locations and the second set of geographic locations to obtain a first grid set corresponding to the first set of geographic locations and a second grid set corresponding to the second set of geographic locations includes: Obtaining the initial grid angle side length; wherein the initial grid angle side length includes the initial longitude angle side length and the initial latitude angle side length; According to the longitude coordinate information of any geographical location point in any geographical location set, obtaining a ratio of the longitude coordinate information to the length of the initial longitude angle and rounding it up as the longitude grid code information of the any geographical location point; According to the latitude coordinate information of any geographical location point in any geographical location set, obtaining a ratio of the latitude coordinate information to the length of the initial latitude angle and rounding it up as the latitude grid code information of the any geographical location point; rasterizing the first set of geographical locations by acquiring longitude grid code information and latitude grid code information of each geographical location point in the first set of geographical locations, thereby obtaining a first grid set corresponding to the first set of geographical locations; By acquiring the longitude grid coding information and the latitude grid coding information of each geographical location point in the second geographical location set, the second geographical location set is rasterized to obtain a second grid set corresponding to the second geographical location set.
4. The method according to claim 3, characterized in that The obtaining of the initial grid angle side length includes: Based on the preset reference point and the spherical cosine formula, the distance corresponding to the unit latitude difference and the distance corresponding to the unit longitude difference are calculated; Get the preset initial grid distance side length; Calculating the ratio of the initial grid distance side length to the distance corresponding to the unit longitude difference to obtain the initial longitude angle side length; Calculating the ratio of the initial grid distance side length to the distance corresponding to the unit latitude difference to obtain the initial latitude angle side length; The initial grid angle side length is obtained based on the initial longitude angle side length and the initial latitude angle side length.
5. The method according to claim 1, wherein After determining the distances between all geographical locations in the updated nine-square grid and the target location and obtaining a fast neighbor search result for the target location, the method further includes: Return to the step of taking any geographic location point in any geographic location set as the target location, determining the grid code information of the target location in the corresponding grid set, and obtaining an initial nine-square grid based on the grid code information from another grid set, until the fast neighbor search results for each geographic location point in all geographic location sets are determined.
6. The method according to claim 1, characterized in that Determining the distances between all geographical locations in the updated nine-square grid and the target location to obtain a fast neighbor search result for the target location includes: Obtaining the longitude and latitude coordinate information of all geographic locations within the updated nine-square grid and the target location, and calculating the distances between all geographic locations within the updated nine-square grid and the target location based on the spherical cosine formula; The distances between all geographical locations in the updated nine-square grid and the target location are sorted from smallest to largest to obtain a fast neighbor search result of the target location.
7. A fast neighbor search device, characterized in that: The device comprises: a location set acquisition module, configured to acquire a location set to be processed; wherein the location set includes a first location set and a second location set; the first location set and the second location set each include a plurality of location points, each including longitude coordinate information and latitude coordinate information; a grid set acquisition module, configured to acquire an initial grid angle side length, and rasterize the first set of geographic locations and the second set of geographic locations to obtain a first grid set corresponding to the first set of geographic locations and a second grid set corresponding to the second set of geographic locations; A nine-square grid determination module is configured to determine the grid code information of any geographical location point in any geographical location set as the target location, and obtain an initial nine-square grid based on the grid code information from another grid set; An angle side length calibration module, configured to obtain the number of geographic location points within the initial nine-square grid, and calibrate the initial grid angle side length based on a numerical relationship between the number of geographic location points and a preset threshold value to obtain an updated grid angle side length; A grid set updating module, configured to re-grid the target position and the initial nine-square grid based on the updated grid angle side length, obtain updated grid coding information of the target position, and update the nine-square grid set; A nine-square grid updating module, configured to obtain an updated nine-square grid based on the updated grid coding information from the updated nine-square grid set; The fast neighbor search module is used to determine the distance between all geographical locations in the updated nine-square grid and the target location, and obtain a fast neighbor search result of the target location.
8. An electronic device, characterized in that: The electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the method according to any one of claims 1 to 6 when executing the computer program.
9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
10. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.