Search Method, Device, Electronic Device and Storage Medium for Geographical Location

By performing K nearest neighbor search in a pre-built K-dimensional tree, the problems of low geographic location search speed and redundant calculation in the prior art are solved, and more efficient query speed and user experience are achieved.

CN113139032BActive Publication Date: 2025-06-20CHINA CONSTRUCTION BANK
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110546700.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-05-19
Publication Date
2025-06-20
Estimated Expiration
2041-05-19

AI Technical Summary

Technical Problem

When performing geographic location searches, the search speed is low and it is easy to generate redundant calculations. Especially when data points are sparse or dense, it is difficult to meet the real-time query needs.

Method used

A pre-constructed K-dimensional tree is used to search K neighbors. By converting the query latitude and longitude into the query point coordinates of the spatial rectangular coordinate system, and searching in the K-dimensional tree, the target data point corresponding to the query data point is obtained.

Benefits of technology

It improves the speed and efficiency of geographic location search, is not limited by distance range, reduces the number of queries, improves the query speed, and can respond to client data query requests faster, thereby improving user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113139032B_ABST
    Figure CN113139032B_ABST
Patent Text Reader

Abstract

Embodiments of the present invention relate to the technical field of automatic programming, and disclose a method, device, electronic device and storage medium for searching geographical locations. Among them, the method includes: receiving a data query request of a target page sent by a target client, and obtaining the query longitude and latitude of a query data point corresponding to the data query request; performing a K-nearest neighbor search in a pre-constructed K-d tree based on the query longitude and latitude to obtain at least one target data point corresponding to the query data point, where the K-d tree is constructed based on the data longitude and latitude of each sample data point; and displaying the target geographical locations corresponding to at least one of the target data points on the target page of the target client. The technical solution of the embodiments of the present invention, by performing a K-nearest neighbor search in a pre-constructed K-d tree, is not only not limited by the distance range, but also can reduce the query volume, improve the query speed, respond to the client request faster, and improve the user experience.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present invention relate to the technical field of automatic programming, and in particular, to a method, apparatus, electronic device, and storage medium for searching geographical locations. Background Art

[0002] Currently, banks have a large number of outlets, employees, devices, customers, etc. across the country. In terms of business, it is necessary to query specific objects across the country according to the longitude and latitude of a specified location, sort them from near to far, and visually display them on the client side to provide data support for resource scheduling and decision-making.

[0003] The prior art is based on dividing the map into small blocks of basically the same size, and then calculating the block to which each data point belongs. When querying, first find all the data points in the block where the query data point is located, and then query the outer blocks layer by layer. This method has low efficiency and slow response speed when dealing with relatively sparse data points and large-scale searches involving hundreds or thousands of kilometers, and it is difficult to meet the real-time query requirements; when dealing with very dense data points and a large number of data points in the block far exceeding the single-page display capacity of the display page, there is also a problem of a large amount of redundant calculation. Summary of the Invention

[0004] Embodiments of the present invention provide a method, apparatus, electronic device, and storage medium for searching geographical locations to achieve fast query of geographical locations.

[0005] In a first aspect, embodiments of the present invention provide a method for searching geographical locations, the method including:

[0006] Receiving a data query request for a target page sent by a target client, and obtaining the query longitude and latitude of a query data point corresponding to the data query request;

[0007] Performing a K-nearest neighbor search in a pre-constructed K-d tree based on the query longitude and latitude to obtain at least one target data point corresponding to the query data point, where the K-d tree is constructed based on the data longitude and latitude of each sample data point;

[0008] Displaying the target geographical locations corresponding to at least one target data point on the target page of the target client.

[0009] In a second aspect, embodiments of the present invention further provide a device for searching geographical locations, the device including:

[0010] A query request module, configured to receive a data query request for a target page sent by a target client, and obtain the query longitude and latitude of a query data point corresponding to the data query request;

[0011] A data search module, configured to perform K-nearest neighbor search in a pre-constructed K-d tree based on the query longitude and latitude, so as to obtain at least one target data point corresponding to the query data point, wherein the K-d tree is constructed based on the data longitude and latitude of each sample data point;

[0012] A data display module, configured to display the target geographical locations corresponding to at least one of the target data points on a target page of the target client.

[0013] In a third aspect, an embodiment of the present invention further provides an electronic device, which includes:

[0014] One or more processors;

[0015] A storage device, configured to store one or more programs,

[0016] When the one or more programs are executed by the one or more processors, the one or more processors are caused to implement the geographical location search method according to any one of the technical solutions in the embodiments of the present invention.

[0017] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, the geographical location search method according to any one of the technical solutions in the embodiments of the present invention is implemented.

[0018] The technical solution of the embodiment of the present invention solves the technical problems of low search speed and easy generation of redundant calculations in the existing search methods by performing K-nearest neighbor search in a pre-constructed K-d tree. It is not only not limited by the distance range, but also can reduce the query volume, improve the query speed, and respond to the data query requests of the target client faster, thereby improving the user experience. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the technical solutions of the exemplary embodiments of the present invention, the following briefly introduces the drawings required for describing the embodiments. Obviously, the introduced drawings are only the drawings of a part of the embodiments to be described in the present invention, rather than all the drawings. For those of ordinary skill in the art, other drawings can be obtained according to these drawings without creative efforts.

[0020] Figure 1 It is a schematic flowchart of a geographical location search method provided in Embodiment 1 of the present invention;

[0021] Figure 2 It is a schematic flowchart of a geographical location search method provided in Embodiment 2 of the present invention;

[0022] Figure 3It is a schematic structural diagram of a geographical location search device provided in Embodiment 3 of the present invention.

[0023] Figure 4 It is a schematic structural diagram of an electronic device provided in Embodiment 4 of the present invention. Detailed implementation manners

[0024] The present invention will be further described in detail below with reference to the drawings and embodiments. It can be understood that the specific embodiments described herein are only used to explain the present invention, rather than limiting the present invention. Additionally, it should be noted that for the sake of description, only parts related to the present invention rather than all structures are shown in the drawings.

[0025] It should also be noted that for the sake of description, only parts related to the present invention rather than all content are shown in the drawings. Before discussing the exemplary embodiments in more detail, it should be mentioned that some exemplary embodiments are described as processes or methods depicted as flowcharts. Although the flowcharts describe the operations (or steps) as sequential processes, many of the operations can be implemented in parallel, concurrently, or simultaneously. In addition, the order of the operations can be rearranged. When the operations are completed, the process can be terminated, but there can also be additional steps not included in the drawings. The process can correspond to a method, function, procedure, subroutine, subprogram, etc.

[0026] Embodiment 1

[0027] Figure 1 It is a schematic flowchart of a geographical location search method provided in Embodiment 1 of the present invention. This embodiment is applicable to the situation of searching for geographical locations. This method can be executed by a geographical location search device, and the device can be implemented in software and / or hardware.

[0028] As Figure 1 shown, the method of this embodiment can specifically include the following steps:

[0029] S110. Receive the data query request of the target page sent by the target client, and obtain the query longitude and latitude of the query data point corresponding to the data query request.

[0030] Among them, the query data point needs to calculate its nearest neighbor location point. In the embodiment of the present invention, the query data point can be understood as the geographical location requested to be queried. The geographical location of the query data point can be represented by the query longitude and latitude. The data query request can be understood as a request for the geographical location data to be displayed on the target page sent by the query target client. The data query request can be understood as a request instruction generated upon receiving a trigger operation for requesting data query.

[0031] It should be noted that the action area of the trigger operation and the action mode in the action area can be set according to actual needs and will not be specifically limited here. Optionally, the action mode of the trigger operation is the trigger operation input through the input device, or the operation input through human-computer interaction methods such as sound and gestures. The action area of the action mode of the trigger operation can be a preset trigger element, or a preset trigger operation recognition area, etc. For example, the trigger operation can be the operation when a certain list view is scrolled and triggered, the operation when a certain button is clicked and triggered, the operation when a certain page is displayed and triggered, etc.

[0032] S120. Perform K-nearest neighbor search in the pre-constructed K-d tree based on the query longitude and latitude to obtain at least one target data point corresponding to the query data point, where the K-d tree is constructed based on the data longitude and latitude of each sample data point.

[0033] Among them, the K-d tree is a tree-shaped data structure for storing sample data points in a k-dimensional space for rapid retrieval. K-nearest neighbor search can be understood as finding the k sample data points closest to the query data point. Among them, the data point can be understood as an object with longitude and latitude information, which can represent bank outlets, devices, enterprises, etc.

[0034] Specifically, performing K-nearest neighbor search in the pre-constructed K-d tree based on the query longitude and latitude includes: converting the query longitude and latitude into the query point coordinates in the spatial rectangular coordinate system, and performing K-nearest neighbor search in the pre-constructed K-d tree based on the query point coordinates.

[0035] Exemplarily, converting the query longitude and latitude into the query point coordinates in the spatial rectangular coordinate system includes: converting the query longitude and latitude into the query point coordinates in the spatial rectangular coordinate system based on the following formula:

[0036] lon = lon / 180 * π

[0037] lat = lat / 180 * π

[0038] x = R * cos(lat) * cos(lon)

[0039] y = R * cos(lat) * sin(lon)

[0040] z = R * sin(lat)

[0041] Wherein, R represents the radius of the earth; lon represents the longitude of the query data point; lat represents the latitude of the query data point; π is the pi; x represents the abscissa of the query data point in the space rectangular coordinate system; y represents the ordinate of the query data point in the space rectangular coordinate system; z represents the vertical axis coordinate of the query data point in the space rectangular coordinate system.

[0042] Optionally, performing a K-nearest neighbor search on the pre-constructed K-dimensional tree based on the query point coordinates includes: determining the split axis coordinate value corresponding to the split axis dimension corresponding to each node in the pre-constructed K-dimensional tree in the query point coordinates; performing a K-nearest neighbor search on the pre-constructed K-dimensional tree based on the split axis coordinate value.

[0043] In the embodiment of the present invention, the method for constructing the K-dimensional tree may specifically include: obtaining the data longitude and latitude of each collected sample data point; converting the data longitude and latitude into the data point coordinates of the space rectangular coordinate system; constructing the K-dimensional tree based on the data point coordinates of each sample data point in the sample data set, wherein the sample data set includes a plurality of sample data points.

[0044] Similarly, the data longitude and latitude (lon, lat) of each collected sample data point can be obtained, the data longitude and latitude (lon, lat) are converted into the data point coordinates (x, y, z) of the space rectangular coordinate system, and the data longitude and latitude are converted into the data point coordinates of the space rectangular coordinate system based on the following formula:

[0045] lon = lon / 180 * π

[0046] lat = lat / 180 * π

[0047] x = R * cos(lat) * cos(lon)

[0048] y = R * cos(lat) * sin(lon)

[0049] z = R * sin(lat)

[0050] Wherein, R represents the radius of the earth; lon represents the longitude of the query data point; lat represents the latitude of the query data point; π is the pi; x represents the abscissa of the query data point in the space rectangular coordinate system; y represents the ordinate of the query data point in the space rectangular coordinate system; z represents the vertical axis coordinate of the query data point in the space rectangular coordinate system.

[0051] Specifically, constructing the K-dimensional tree based on the data point coordinates of each sample data point in the sample data set may include: determining the current partition axis dimension of the K-dimensional tree based on the data point coordinates of multiple sample data points in the sample data set; and constructing the left branch and the right branch of the K-dimensional tree based on the current partition axis dimension and the sample data points, respectively.

[0052] Optionally, determining the current split axis dimension of the K-dimensional tree based on the data point coordinates of multiple sample data points in the sample data set includes: performing variance calculation on the data of each dimension in the data point coordinates of multiple sample data points in the sample data set, and taking the dimension corresponding to the maximum variance as the current split axis dimension of the K-dimensional tree; or randomly selecting the data of one dimension in the data point coordinates of the sample data point as the initial split axis dimension, and then taking different dimensions in turn as the current split axis dimension when the node changes.

[0053] Optionally, the left branch and the right branch of the K-dimensional tree are respectively determined based on the current partition axis dimension and the sample data points, including: searching the sample data set based on the current partition axis dimension to obtain the median data of the current partition axis dimension, and using the median data as the current node data; based on the current partition axis dimension, the current node data and the sample data points in the sample data set that are not constructed on the K-dimensional tree, respectively constructing the left branch and the right branch of the K-dimensional tree.

[0054] Specifically, based on the current partition axis dimension, the current node data, and the sample data points in the sample data set that are not constructed on the K-dimensional tree, the left branch and the right branch of the K-dimensional tree are constructed, including: based on the current partition axis dimension, all sample data points smaller than the current node data are divided into the left branch of the K-dimensional tree, and all sample data points greater than or equal to the current node data are divided into the right branch of the K-dimensional tree.

[0055] In an embodiment of the present invention, optionally, if the number of sample data points in the sample data set that are not constructed on the K-dimensional tree is less than a preset number threshold, the current node data is used as the leaf node data of the K-dimensional tree. The preset number threshold can be set according to actual needs, and its specific value is not limited here, for example, it can be 10 or 20. The advantage of such a setting is that it can effectively reduce the depth of the K-dimensional tree, simplify the construction operation, and speed up the search speed while ensuring that the amount of calculation is not large.

[0056] S130: Displaying a target geographical location corresponding to at least one of the target data points on a target page of the target client.

[0057] Exemplarily, the target geographical location corresponding to the target data point can be displayed by name and / or the city street where it is located, etc. The display method can be text and / or pictures, etc., which is not specifically limited here.

[0058] Specifically, if there are two or more target data points, the target display order of the target geographical location corresponding to the target data point on the target page can be determined according to the distance between the target data point and the query data point. Furthermore, the target geographical location corresponding to the target data point is displayed on the target page of the target client based on this target display order.

[0059] Exemplarily, the target geographical location corresponding to the target data point can be displayed on the target page of the target client from top to bottom or from front to back in the order of the distance between the target data point and the query data point from near to far. In other words, the target geographical location with a shorter distance between the target data point and the query data point is preferentially displayed.

[0060] Optionally, after performing K-nearest neighbor search in the pre-constructed K-dimensional tree based on the query point coordinates to obtain at least one target data point corresponding to the query data point, it further includes: calculating the straight-line distance between each target data point and the query data point; calculating the arc length between the target data point and the query data point based on the straight-line distance, and correspondingly displaying the arc length and the target geographical location on the target page.

[0061] Specifically, the straight-line distance between each target data point and the query data point can be calculated based on the following formula:

[0062]

[0063] where L represents the straight-line distance between the target data point and the query data point; x1 represents the horizontal axis coordinate of the target data point; y1 represents the vertical axis coordinate of the target data point; z1 represents the vertical axis coordinate of the target data point; x2 represents the horizontal axis coordinate of the query data point; y2 represents the vertical axis coordinate of the query data point; z2 represents the vertical axis coordinate of the query data point.

[0064] Among them, calculating the arc length between the target data point and the query data point based on the straight-line distance can be specifically implemented through the following formula:

[0065] S = 2 * R * arcsin(L / 2R),

[0066] where S is the arc length between the target data point and the query data point; L is the straight-line distance between the target data point and the query data point, and R is the radius of the earth.

[0067] In this technical solution, the arc length is used as the actual distance between the target geographical location and the query location corresponding to the query data point, which is more accurate than calculating based on two-dimensional longitude and latitude.

[0068] The technical solution of the embodiment of the present invention solves the technical problems of low search speed and easy generation of redundant calculations in the existing search methods by performing K-nearest neighbor search in a pre-constructed K-d tree. It is not only not limited by the distance range, but also can reduce the query volume, improve the query speed, and respond to the data query requests of the target client faster, thereby improving the user experience.

[0069] Embodiment 2

[0070] Figure 2 As shown in the flowchart of a method for searching geographical locations provided by Embodiment 2 of the present invention. Based on any optional technical solution in the embodiment of the present invention, optionally, the K-nearest neighbor search performed in the pre-constructed K-d tree based on the query longitude and latitude includes: using the root node as the root node of the current branch to determine the current branch; determining whether all the sample data points included in the current branch have been visited; if not all the sample data points included in the current branch have been visited, then determining whether the split axis coordinate value of the root node is less than the split axis coordinate value corresponding to the query longitude and latitude of the query data point; if so, entering the left branch of the pre-constructed K-d tree for search and updating the root node of the current branch to the root node of the left branch; if not, entering the right branch of the pre-constructed K-d tree for search and updating the root node of the current branch to the root node of the right branch; if all the sample data points included in the current branch have been visited, then obtaining the maximum branch distance and the minimum branch distance between the sample data points included in the current branch and the query data point included in the cache information; and performing K-nearest neighbor search in the pre-constructed K-d tree based on the maximum branch distance and the minimum branch distance.

[0071] As Figure 2 shown, the method of this embodiment may specifically include:

[0072] S210. Receive the data query request of the target page sent by the target client, and obtain the query longitude and latitude of the query data point corresponding to the data query request.

[0073] S220. Use the root node as the root node of the current branch to determine the current branch.

[0074] In other words, starting from the root node of the K-d tree for search, and using the branch where the root node is located as the current branch.

[0075] S230. Determine whether all the sample data points included in the current branch have been visited. If not all the sample data points included in the current branch have been visited, execute S240. If all the sample data points included in the current branch have been visited, execute S270.

[0076] In an embodiment of the present invention, if it is detected that the data query request based on the query data point is a first request, a preset number of target data points corresponding to the display pages can be searched out, and the target data points are stored corresponding to the display pages.

[0077] The advantage of such a setting is that when the subsequent data query request received by the target client queries the corresponding data and falls within the pre-cached sample data points, the target data points corresponding to the data query request are directly read and returned, avoiding frequent k-nearest neighbor queries. Only when it falls outside the cached sample data points is the k-nearest neighbor query performed, improving the response speed.

[0078] Considering that the existing data display methods mostly use paged display, in order to further improve the search efficiency and avoid re-reading the search and generating redundant calculations, the technical solution of the embodiment of the present invention can save the following two types of information when performing k-nearest neighbor paged search:

[0079] For the search result of each page, save the maximum distance from the sample data points included in this page to the query data point and the minimum distance of the page;

[0080] If all the sample data points included in the current branch have been visited, save the minimum distance and the maximum distance from the sample data points included in the current branch to the query data point.

[0081] If all the sample data points included in the current branch have been visited, there is no need to repeat the visit, and the maximum distance and the minimum distance from the sample data points included in the current branch to the query data point can be read.

[0082] If not all the sample data points included in the current branch have been visited, it is necessary to further search the data of this current branch.

[0083] S240. Determine whether the split axis coordinate value of the root node is less than the split axis coordinate value corresponding to the query longitude and latitude of the query data point. If so, execute S250, otherwise execute S260.

[0084] Specifically, the search path can be determined based on the magnitude relationship between the split axis coordinate value of the root node of the current branch and the split axis coordinate value corresponding to the query longitude and latitude of the query data point.

[0085] S250. Enter the left branch of the pre-constructed K-dimensional tree for search, update the root node of the current branch to the root node of the left branch, and return to execute S240.

[0086] S260. Enter the right branch of the pre-constructed K-dimensional tree for search, update the root node of the current branch to the root node of the right branch, and return to execute S240.

[0087] S270. Obtain the maximum branch distance and the minimum branch distance between the sample data points included in the current branch and the query data point included in the cache information, and execute S280.

[0088] Among them, for the maximum branch distance and the minimum branch distance between the sample data points included in the current branch and the query data point, it is necessary to calculate the straight-line distance between each sample data point included in the current branch and the query data point respectively, select the maximum value from all the calculated distances as the maximum branch distance, and select the minimum value as the minimum branch distance. Among them, the method for calculating the straight-line distance can refer to the foregoing method and will not be elaborated here.

[0089] S280. Perform K-nearest neighbor search in the pre-constructed K-dimensional tree based on the maximum branch distance and the minimum branch distance to obtain at least one target data point corresponding to the query data point, where the K-dimensional tree is constructed based on the data longitude and latitude of each sample data point.

[0090] Specifically, performing K-nearest neighbor search in the pre-constructed K-dimensional tree based on the maximum branch distance and the minimum branch distance may include: if the cache information contains the maximum page distance of the adjacent page corresponding to the target page and does not contain the maximum page distance and the minimum page distance of the target page, then determine the branch to be searched in the pre-constructed K-dimensional tree based on the maximum page distance of the adjacent page, the maximum page distance of the target page, the minimum branch distance of the current branch, and the minimum branch distance, and perform K-nearest neighbor search in the K-dimensional tree based on the branch to be searched.

[0091] If the cache information does not contain the maximum page distance and the minimum page distance of the target page, it means that the data of this page has not been searched before. At this time, it can be judged whether the cache contains the maximum page distance of the adjacent page corresponding to the target page. If so, the branch to be searched in the pre-constructed K-dimensional tree can be determined based on the maximum page distance of the adjacent page, the maximum page distance of the target page, the minimum branch distance of the current branch, and the minimum branch distance.

[0092] It should be noted that the maximum page distance of the target page can be set according to the actual situation, and its specific value is not limited here. For the convenience of calculation, it can be set to infinity.

[0093] Specifically, determining the branch to be searched in the pre-constructed K-dimensional tree based on the maximum page distance of the adjacent page, the maximum page distance of the target page, and the minimum and maximum branch distances of the current branch includes: if the maximum branch distance of the current branch is less than or equal to the maximum page distance of the adjacent page, or the minimum branch distance of the current branch is greater than the maximum page distance of the target page, then mark the current branch as visited, and update the parent node of the root node of the current branch to the root node of the current branch to update the current branch; furthermore, return to execute the operation of determining whether all the sample data points included in the current branch have been visited.

[0094] If the maximum branch distance of the current branch is less than or equal to the maximum page distance of the adjacent page, it indicates that these data points all fall on the pages before the (i + 1)-th page, so this branch can be marked as visited and there is no need to visit it again.

[0095] If the minimum branch distance of the current branch is greater than the maximum page distance of the target page, it indicates that the data points included in this branch all fall outside the (i + 1)-th page, and mark this branch as visited and there is no need to visit it again.

[0096] Optionally, determining the branch to be searched in the pre-constructed K-dimensional tree based on the maximum page distance of the adjacent page, the maximum page distance of the target page, and the minimum and maximum branch distances of the current branch includes: determining whether there is an intersection between the first distance interval formed by the minimum and maximum branch distances of the current branch and the second distance interval formed by the maximum page distance of the adjacent page and the maximum page distance of the target page; if there is an intersection between the first distance interval and the second distance interval, then use the current branch as the branch to be searched in the pre-constructed K-dimensional tree.

[0097] If there is a partial intersection between the first distance interval and the second distance interval, or there is no cache information for the current branch, it indicates that there may be sample data points in the current branch that fall within the target page, and at this time, it is necessary to search based on the current branch.

[0098] Optionally, perform a K-nearest neighbor search in a pre-constructed K-dimensional tree based on the maximum branch distance and / or the minimum branch distance, including: if the cache information contains the maximum page distance and the minimum page distance of the target page, perform a K-nearest neighbor search in the K-dimensional tree based on the minimum page distance and the maximum page distance of the target page, and the minimum branch distance and the maximum branch distance of the current branch.

[0099] If the cache information contains the maximum page distance and the minimum page distance of the target page, for the previously searched pages, at this time, a K-nearest neighbor search can be performed in the K-dimensional tree based on the minimum page distance and the maximum page distance of the target page, and the minimum branch distance and the maximum branch distance of the current branch.

[0100] Optionally, performing a K-nearest neighbor search in the K-dimensional tree based on the minimum page distance and the maximum page distance of the target page, and the minimum branch distance and the maximum branch distance of the current branch may include: if the maximum branch distance of the current branch is less than the minimum page distance of the target page, or the minimum branch distance of the current branch is greater than the maximum page distance of the target page, mark the current branch as visited, and update the parent node of the root node of the current branch to the root node of the current branch to update the current branch; then, return to perform the operation of determining whether all the sample data points included in the current branch have been visited, and continue the search.

[0101] Optionally, performing a K-nearest neighbor search in the K-dimensional tree based on the minimum page distance and the maximum page distance of the target page, and the minimum branch distance and the maximum branch distance of the current branch, includes: if the minimum distance of the target page is less than or equal to the minimum branch distance of the current branch and the maximum branch distance of the current branch is less than the maximum page distance of the target page, add the sample data points included in the current branch to the candidate set, mark the current branch as visited, and update the parent node of the root node of the current branch to the root node of the current branch to update the current branch; then, return to perform the operation of determining whether all the sample data points included in the current branch have been visited, and continue the search.

[0102] Optionally, perform K-nearest neighbor search in the K-dimensional tree based on the minimum page distance and maximum page distance of the target page and the minimum branch distance and maximum branch distance of the current branch, including: determining whether there is an intersection between the third distance interval formed by the minimum branch distance and maximum branch distance of the current branch and the fourth distance interval formed by the maximum page distance and minimum page distance of the target page; if there is an intersection between the third distance interval and the fourth distance interval, determining whether the root node of the current branch is a leaf node; if so, adding the sample data points in the leaf node corresponding to the sample data points whose distances to the query data points are within the range of the minimum page distance and maximum page distance of the target page to the candidate set; when the number of sample data points in the candidate set reaches a preset threshold, using the sample data points in the candidate set as the target data points corresponding to the query data points.

[0103] If the root node of the current branch is not a leaf node, enter the sub-branch of the current branch to continue recursive search.

[0104] S290. Display the target geographical locations corresponding to at least one of the target data points on the target page of the target client.

[0105] The technical solution of this embodiment can determine the search method in the K-nearest neighbor search in the K-dimensional tree by determining whether all the sample data points included in the current branch have been visited, avoiding unnecessary repeated visits to the branches that have been visited, improving the search efficiency, and then assisting in the K-nearest neighbor search through the maximum branch distance and minimum branch distance between the sample data points included in the cached branch in the cache information and the query data point, and can perform the K-nearest neighbor search more accurately and quickly without occupying too much cache space.

[0106] Embodiment III

[0107] This embodiment provides an optional example of performing geographical location search based on the geographical location search method in the embodiments of the present invention. The specific implementation process is as follows:

[0108] I. Establish a data index

[0109] Before performing K-nearest neighbor search based on the K-dimensional tree (KDTree), it is necessary to first establish a data index based on the KDTree. Specifically, it may include:

[0110] 1) Convert longitude and latitude to a rectangular coordinate system

[0111] Obtain the longitude and latitude (lon, lat) of each sample data point collected, convert the longitude and latitude (lon, lat) of the data into the coordinates (x, y, z) of a data point in a spatial rectangular coordinate system, and convert the longitude and latitude of the data into the coordinates of a data point in a spatial rectangular coordinate system based on the following formula:

[0112] lon = lon / 180 * π

[0113] lat = lat / 180 * π

[0114] x = R * cos(lat) * coS(lon)

[0115] y = R * cos(lat) * sin(lon)

[0116] z = R * sin(lat)

[0117] Among them, R represents the radius of the earth; lon represents the longitude of the sample data point; lat represents the latitude of the sample data point; π is the pi; x represents the abscissa of the sample data point in the spatial rectangular coordinate system; y represents the ordinate of the sample data point in the spatial rectangular coordinate system; z represents the vertical axis coordinate of the sample data point in the spatial rectangular coordinate system.

[0118] 2) Use the KDTree data structure to build a binary tree index for the (x, y, z) sample data set

[0119] KDTree is a data structure that divides the k-dimensional data space and is mainly applied to the efficient search of key data in multi-dimensional space, such as range search and nearest neighbor search. Therefore, a KDTree can be constructed based on the data point coordinates of each sample data point in the sample data set, where the sample data set contains multiple sample data points.

[0120] For the spatial coordinate data (x, y, z) of the sample data point, there are 3 dimensions. Specifically, the steps to build a KDTree can include:

[0121] 1. Initialize the splitting axis dimension: Calculate the variance of the data of each dimension in the data point coordinates of multiple sample data points in the sample data set, and take the dimension corresponding to the maximum variance as the current splitting axis dimension of the K-dimensional tree, marked as r.

[0122] 2. Select the splitting point: Retrieve the sample data set based on the current splitting axis dimension to obtain the median data of the current splitting axis dimension, and use the median data as the current node data, that is, retrieve the current data set according to the splitting axis dimension, find the median data of this dimension, and place it on the current node. If the number of sample data points contained in the current data set is less than the preset quantity threshold N, then use the current node data as the leaf node data of the K-dimensional tree. Here, the current data set can be understood as the data set containing the sample data points not yet constructed on the K-dimensional tree, and can be obtained by updating the sample data set; N is a positive integer. If the current node is a leaf node, no further binary splitting is performed.

[0123] 3. Binary splitting:

[0124] Split the left branch: Based on the current splitting axis dimension, divide all sample data points smaller than the current node data into the left branch of the K-dimensional tree;

[0125] Split the right branch: Based on the current splitting axis dimension, divide all sample data points greater than or equal to the current node data into the right branch of the K-dimensional tree.

[0126] 4. Update the splitting axis dimension:

[0127] Optionally, determine the splitting axis dimension in the way of r = (r + 1) % 3, alternately select different dimensions as the splitting axis dimension, or select the dimension with the largest variance as the splitting axis dimension.

[0128] 5. Build subtrees:

[0129] Build the left subtree: Recursively perform step 2 on the data in the left branch;

[0130] Build the right subtree: Recursively perform step 2 on the data in the right branch.

[0131] II. Data search

[0132] When receiving the data query request of the target page sent by the target client, obtain the query longitude and latitude of the query data point corresponding to the data query request, and convert the query longitude and latitude into the query point coordinates in the space rectangular coordinate system to convert into rectangular coordinates (x, y, z). Specifically, the query longitude and latitude can be converted into the query point coordinates in the space rectangular coordinate system based on the following formula:

[0133] lon = lon / 180 * π

[0134] lat = lat / 180 * π

[0135] x = R * cos(lat) * cos(lon)

[0136] y = R * cos(lat) * sin(lon)

[0137] z = R * sin(lat)

[0138] Wherein, R represents the radius of the earth; lon represents the longitude of the query data point; lat represents the latitude of the query data point; π is the pi; x represents the horizontal axis coordinate of the query data point in the space rectangular coordinate system; y represents the vertical axis coordinate of the query data point in the space rectangular coordinate system; z represents the vertical axis coordinate of the query data point in the space rectangular coordinate system.

[0139] Then, perform k-nearest neighbor search on the established KDTree index.

[0140] Each node on the KDTree represents a small area in space, and the search is based on the area for zonal retrieval. The search steps are as follows:

[0141] 1. Find the leaf node to which the query data point belongs:

[0142] 1) Set the current node as the root node

[0143] 2) If the coordinate value of the splitting axis of the current node is less than the coordinate value of the splitting axis corresponding to the query longitude and latitude of the query data point, enter the left subtree and update the current node as the root node of the left subtree; if the coordinate value of the splitting axis of the current node is greater than the coordinate value of the splitting axis corresponding to the query longitude and latitude of the query data point, enter the right subtree and update the current node as the root node of the right subtree

[0144] 3) Repeat step 2) until reaching the leaf node

[0145] 2. Recursive search

[0146] 1) Establish an empty candidate set S

[0147] 2) For branch nodes:

[0148] 2.1) If both the left and right sub-branches have been visited, mark this branch node as visited and jump to the parent node of this branch node;

[0149] 2.2) If there are unvisited child nodes in the current branch:

[0150] 2.2.1) If the number of sample data points in the candidate set S is less than k or the distance from the query data point to the splitting axis of the sub-branch is less than the maximum distance in the candidate set, enter the sub-branch and jump to step 2);

[0151] 2.2.2) If the number of sample data points in the candidate set S is k and the distance from the query data point to the splitting axis of the sub-branch is greater than or equal to the maximum distance in the candidate set, then pruning is performed in advance and the branch is marked as visited;

[0152] 3) For each sample data point corresponding to the leaf node, if the number of samples in the candidate set S is less than k or the distance from the query data point to each sample data point of the leaf node is less than the maximum distance in the candidate set S, then add the sample data point to the candidate set, kick out the sample data point with the maximum distance in the candidate set, and then jump to the parent node of the leaf node.

[0153] When the root node of the KDTree is visited, the search process is completed, and the data points in the candidate set S are the k nearest neighbors finally searched out.

[0154] It should be noted that during the search process, the nearest neighbor target data point can be determined by calculating the straight-line distance between the target data point and the query data point.

[0155] Specifically, the straight-line distance between each target data point and the query data point can be calculated based on the following formula:

[0156]

[0157] where L represents the straight-line distance between the target data point and the query data point; x1 represents the horizontal axis coordinate of the target data point; y1 represents the vertical axis coordinate of the target data point; z1 represents the vertical axis coordinate of the target data point; x2 represents the horizontal axis coordinate of the query data point; y2 represents the vertical axis coordinate of the query data point; z2 represents the vertical axis coordinate of the query data point.

[0158] The above technical solution is particularly applicable to the case where the arc length is less than 180 degrees. For example, within the national territory of China, at this time, when the chord length A is greater than the chord length B, the arc length A corresponding to the chord length A is greater than the arc length B corresponding to the chord length B; therefore, when finding the nearest neighbor, it is not necessary to accurately calculate the true arc length, as long as the straight-line distance between the target data point and the query data point is known.

[0159] III. Search State Caching and Recovery

[0160] In the embodiments of the present invention, in order to further improve the search efficiency, the efficient search can be ensured by establishing a secondary cache.

[0161] The first-level cache: result cache

[0162] If the actual paging size corresponding to the data query request sent by the target client received is n, then when performing k-nearest neighbor queries based on the KDTree each time, 10*n nearest sample data points can be queried and cached at one time; where n is a positive integer. For example, n can be a positive integer less than or equal to 100.

[0163] That is, if it is detected that the data query request based on the query data point is the first request, then the target data points corresponding to the preset number of display pages can be searched out, and the target data points are stored corresponding to the display pages.

[0164] The advantage of this setting is that when the data corresponding to the subsequent data query request received by the target client falls within the 10*n sample data points cached in advance, the target data points corresponding to the data query request are directly read and returned, avoiding frequent k-nearest neighbor queries. Only when it falls outside these 10*n data points, k-nearest neighbor queries are performed, improving the response speed.

[0165] Second-level cache: Cache of the search state when performing k-nearest neighbor search based on the KDTree

[0166] When performing k-nearest neighbor paging search, the following two types of information are saved:

[0167] a. For the search results of each paging, save the maximum distance from the sample data points included in the page to the query data point and the minimum distance of the page

[0168] b. Assume that all the sample data points included in the branch have been visited, then the branch is a fully visited branch, and save the minimum distance MinDist and the maximum distance MaxDist from the sample data points included in the branch to the query data point.

[0169] Based on the paging nearest neighbor query of the cached data, it is divided into two cases:

[0170] 1. Query a new page: Assume that the geographical location data from page 1 to page i has been queried, and now query page i + 1. The number of data points included in each page is n, and n is a positive integer:

[0171] First, initialize the of page i + 1 to infinity

[0172] 1) Find the visited branches: (Sink)

[0173] 1.1) Set the root node as the root node of the current branch

[0174] 1.2) If not all the sample data points contained in the current branch have been visited, there is no cached information. If the splitting axis coordinate value of the root node of the current branch is less than the splitting axis coordinate value corresponding to the query longitude and latitude of the query data point, then enter the left branch of the pre-constructed K-dimensional tree for search, and update the root node of the current branch to the root node of the left branch; otherwise, enter the right branch of the pre-constructed K-dimensional tree for search, and update the root node of the current branch to the root node of the right branch;

[0175] 1.3) Repeat step 1.2) until a visited branch is found and or reach a leaf node.

[0176] 2. Recursively search the (i + 1)-th page: (Backtracking)

[0177] 2.1) Establish an empty candidate set S for the sample data points on the (i + 1)-th page

[0178] 2.2) For the current branch:

[0179] 2.2.1) If all the sample data points contained in the current branch have been visited:

[0180] 2.2.1.1) If the of this branch, it indicates that all these data points fall on the pages before the (i + 1)-th page. Mark this branch as visited, and update the parent node of the root node of the current branch to the root node of the current branch to update the current branch;

[0181] 2.2.1.2) If the of this branch, it indicates that the data points contained in this branch all fall outside the (i + 1)-th page. Mark this branch as visited, and update the parent node of the root node of the current branch to the root node of the current branch to update the current branch;

[0182] 2.2.1.3) If the distance interval [MinDist, MaxDist] of this branch and the interval partially intersect, or there is no cached information, it indicates that this branch must have sample data points that fall outside the first i pages and may fall within the (i + 1)-th page; The processing steps are the same as the previous recursive search steps, and update

[0183] 3. When the root node of the KDTree is visited, the search process is completed, and the sample data points in the candidate set S are the finally searched k nearest neighbors.

[0184] (2) Query the previously searched pages: Assume that pages from 1 to i have been queried. Suppose now the user flips back to view the data on the j-th page (1 ≤ j < i), and the number of data points per page is n:

[0185] First, query from the cache information to obtain the and Then the distance between the target point and the query point must fall within the interval.

[0186] 1. Find the leaf node to which the query data point belongs. The method is the same as the method for finding the leaf node to which the query data point belongs described above, and will not be elaborated here.

[0187] 2. In the recursive search, for a branch node:

[0188] 2.1) If there is no cache information for this branch, the processing method is the same as the recursive search method described above

[0189] 2.2) If there is cache information under this branch, it means that all the sample data points included in this branch have been visited:

[0190] 2.2.1) If this branch then it indicates that these sample data points all fall in the pages before j. Mark this branch as visited and jump to the parent node of the root node of this branch;

[0191] 2.2.2) If this branch then it indicates that these sample data points all fall in the pages after j. Mark this branch as visited and jump to the parent node of the root node of this branch;

[0192] 2.2.3) If this branch then it indicates that these sample data points all fall in the j-th page. Add all the sample data points of this branch to the candidate set S, mark this branch as visited, and jump to the parent node of the root node of this branch;

[0193] 2.2.4) If the [MinDist, MaxDist] of this branch intersects with the interval partially, it means that there are sample data points in this branch that fall in this page. Then enter the sub-branch and jump to step 2) above; if it is a leaf node, test all the data points it contains, and add the data points whose distance to the query point falls within the range to the candidate set S.

[0194] 3. If the number of sample data points in the candidate set of the j-th page reaches n, end the search.

[0195] Take the sample data points in the candidate set as the target data points, determine the target geographical location corresponding to the target data points, and then the arc length between the target data points and the query data points can also be calculated based on the straight-line distance, and the arc length and the target geographical location are correspondingly displayed on the target page.

[0196] Among them, calculating the arc length between the target data point and the query data point based on the straight-line distance can be specifically implemented by the following formula:

[0197] S = 2 * R * arcsin(L / 2R),

[0198] where S is the arc length between the target data point and the query data point; L is the straight-line distance between the target data point and the query data point, and R is the radius of the earth.

[0199] In the technical solution of this embodiment, an index of data points is established in memory through KDTree. During real-time query, KDTree is used for fast nearest neighbor search, which is not limited by the distance range; at the same time, the KDTree search status is cached for each query data point. According to the paging parameters, the nearest neighbor search can be continued based on the historical search information, avoiding computational redundancy. By caching a small amount of data, without saving the specific data points of each page, the number of data points to be accessed for paging query can be greatly reduced, the candidate set can be reduced, the efficiency of paging query can be improved, and the response time can be improved; the optimal in terms of space and time is achieved.

[0200] Embodiment 4

[0201] Figure 3 It is a schematic structural diagram of a geographical location search device provided in Embodiment 3 of the present invention. This embodiment is applicable to the situation of searching for geographical locations. The device may specifically include: a query request module, a data search module, and a data display module.

[0202] Among them, the query request module is used to receive the data query request of the target page sent by the target client and obtain the query longitude and latitude of the query data point corresponding to the data query request; the data search module is used to perform K-nearest neighbor search in the pre-constructed K-dimensional tree based on the query longitude and latitude to obtain at least one target data point corresponding to the query data point, where the K-dimensional tree is constructed based on the data longitude and latitude of each sample data point; the data display module is used to display the target geographical locations corresponding to at least one of the target data points on the target page of the target client.

[0203] In the technical solution of this embodiment of the present invention, by performing K-nearest neighbor search in the pre-constructed K-dimensional tree, the technical problems of low search speed and easy redundant calculation in the existing search method are solved. It is not only not limited by the distance range, but also can reduce the query volume, improve the query speed, and respond to the data query request of the target client faster, thereby improving the user experience.

[0204] Based on any optional technical solution of the embodiments of the present invention, optionally, the data search module includes: a branch determination unit, an access judgment unit, a coordinate judgment unit, a left branch search unit, a right branch search unit, a branch distance acquisition unit, and a branch distance search unit.

[0205] Among them, the branch determination unit is used to determine the current branch with the root node as the root node of the current branch; the access judgment unit is used to judge whether all the sample data points included in the current branch have been accessed; the coordinate judgment unit is used to judge whether the split axis coordinate value of the root node is less than the split axis coordinate value corresponding to the query longitude and latitude of the query data point if not all the sample data points included in the current branch have been accessed; the left branch search unit is used to enter the left branch of the pre-constructed K-dimensional tree for search and update the root node of the current branch to the root node of the left branch if so; the right branch search unit is used to enter the right branch of the pre-constructed K-dimensional tree for search and update the root node of the current branch to the root node of the right branch if not; the branch distance acquisition unit is used to obtain the maximum branch distance and the minimum branch distance between the sample data points included in the current branch and the query data point included in the cache information if all the sample data points included in the current branch have been accessed; the branch distance search unit is used to perform K-nearest neighbor search in the pre-constructed K-dimensional tree based on the maximum branch distance and the minimum branch distance.

[0206] Based on any optional technical solution of the embodiments of the present invention, optionally, the branch distance search unit can be used for:

[0207] If the cache information includes the maximum page distance of the adjacent page corresponding to the target page and does not include the maximum page distance and the minimum page distance of the target page, determine the branch to be searched in the pre-constructed K-dimensional tree based on the maximum page distance of the adjacent page, the maximum page distance of the target page, the minimum branch distance of the current branch, and the minimum branch distance, and perform K-nearest neighbor search in the K-dimensional tree based on the branch to be searched.

[0208] Based on any optional technical solution of the embodiments of the present invention, optionally, the branch distance search unit is specifically used for:

[0209] If the maximum branch distance of the current branch is less than or equal to the maximum page distance of the adjacent page, or the minimum branch distance of the current branch is greater than the maximum page distance of the target page, mark the current branch as accessed, and update the parent node of the root node of the current branch to the root node of the current branch to update the current branch.

[0210] Return to perform the operation of determining whether all the sample data points included in the current branch have been visited.

[0211] Based on any optional technical solution of the embodiment of the present invention, optionally, the branch distance search unit may specifically be configured to:

[0212] Determine whether there is an intersection between a first distance interval formed by the minimum branch distance and the maximum branch distance of the current branch, and a second distance interval formed by the maximum page distance of the adjacent page and the maximum page distance of the target page;

[0213] If there is an intersection between the first distance interval and the second distance interval, use the current branch as the branch to be searched in the pre-constructed K-dimensional tree.

[0214] Based on any optional technical solution of the embodiment of the present invention, optionally, the branch distance search unit may be configured to:

[0215] If the cache information includes the maximum page distance and the minimum page distance of the target page, perform K-nearest neighbor search in the K-dimensional tree based on the minimum page distance and the maximum page distance of the target page, and the minimum branch distance and the maximum branch distance of the current branch.

[0216] Based on any optional technical solution of the embodiment of the present invention, optionally, the branch distance search unit may be configured to:

[0217] If the maximum branch distance of the current branch is less than the minimum page distance of the target page, or the minimum branch distance of the current branch is greater than the maximum page distance of the target page, mark the current branch as visited, and update the parent node of the root node of the current branch to the root node of the current branch to update the current branch;

[0218] Return to perform the operation of determining whether all the sample data points included in the current branch have been visited.

[0219] Based on any optional technical solution of the embodiment of the present invention, optionally, the branch distance search unit may be configured to:

[0220] If the minimum distance of the target page is less than or equal to the minimum branch distance of the current branch and the maximum distance of the current branch is less than the maximum page distance of the target page, add the sample data points included in the current branch to the candidate set, mark the current branch as visited, and update the parent node of the root node of the current branch to the root node of the current branch to update the current branch;

[0221] Return to perform an operation of determining whether all the sample data points included in the current branch have been visited.

[0222] Based on any optional technical solution of the embodiment of the present invention, optionally, the branch distance search unit may be used to:

[0223] Determine whether there is an intersection between a third distance interval formed by the minimum branch distance and the maximum branch distance of the current branch, and a fourth distance interval formed by the maximum page distance and the maximum page distance of the target page;

[0224] If there is an intersection between the third distance interval and the fourth distance interval, determine whether the root node of the current branch is a leaf node;

[0225] If so, add the sample data points whose distances from the query data point are within the range of the minimum page distance and the maximum page distance of the target page among the sample data points corresponding to the leaf node to the candidate set;

[0226] When the number of sample data points in the candidate set reaches a preset threshold, use the sample data points in the candidate set as the target data points corresponding to the query data point.

[0227] Based on any optional technical solution of the embodiment of the present invention, optionally, the data search module is used to:

[0228] Convert the query longitude and latitude into the coordinates of a query point in a spatial rectangular coordinate system, and perform K-nearest neighbor search in a pre-constructed K-dimensional tree based on the query point coordinates.

[0229] Based on any optional technical solution of the embodiment of the present invention, optionally, the data search module may specifically be used to:

[0230] Convert the query longitude and latitude into the coordinates of a query point in a spatial rectangular coordinate system based on the following formula:

[0231] lon = lon / 180 * π

[0232] lat = lat / 180 * π

[0233] x = R * cos(lat) * cos(lon)

[0234] y = R * cos(lat) * sin(lon)

[0235] z = R * sin(lat)

[0236] Wherein, R represents the radius of the Earth; lon represents the longitude of the query data point; lat represents the latitude of the query data point; π is the pi; x represents the horizontal axis coordinate of the query data point in the space rectangular coordinate system; y represents the vertical axis coordinate of the query data point in the space rectangular coordinate system; z represents the vertical axis coordinate of the query data point in the space rectangular coordinate system.

[0237] Based on any optional technical solution of the embodiment of the present invention, optionally, the data search module is further configured to:

[0238] Determine the split axis coordinate value corresponding to each node in the pre-constructed K-dimensional tree for the split axis dimension corresponding to the query point coordinates;

[0239] Perform K-nearest neighbor search in the pre-constructed K-dimensional tree based on the split axis coordinate value.

[0240] Based on any optional technical solution of the embodiment of the present invention, optionally, the search method for the geographical location further includes:

[0241] A distance display module, configured to calculate the straight-line distance between each of the target data points and the query data point after performing K-nearest neighbor search in the pre-constructed K-dimensional tree based on the query point coordinates to obtain at least one target data point corresponding to the query data point;

[0242] Calculate the arc length between the target data point and the query data point based on the straight-line distance, and display the arc length and the target data point correspondingly on the target page.

[0243] Based on any optional technical solution of the embodiment of the present invention, optionally, the distance display module is configured to:

[0244] Calculate the straight-line distance between each of the target data points and the query data point based on the following formula:

[0245]

[0246] Wherein, L represents the straight-line distance between the target data point and the query data point; x1 represents the horizontal axis coordinate of the target data point; y1 represents the vertical axis coordinate of the target data point; z1 represents the vertical axis coordinate of the target data point; x2 represents the horizontal axis coordinate of the query data point; y2 represents the vertical axis coordinate of the query data point; z2 represents the vertical axis coordinate of the query data point.

[0247] Based on any optional technical solution of the embodiment of the present invention, optionally, the search device for the geographical location further includes a construction module for the K-dimensional tree, wherein the construction module for the K-dimensional tree specifically includes:

[0248] A data longitude and latitude acquisition unit, configured to acquire the data longitude and latitude of each collected sample data point;

[0249] A data point coordinate conversion unit, configured to convert the data longitude and latitude into the data point coordinates in a space rectangular coordinate system;

[0250] A K-d tree construction unit, configured to construct the K-d tree based on the data point coordinates of each sample data point in a sample data set, where the sample data set includes a plurality of sample data points.

[0251] Based on any optional technical solution in the embodiment of the present invention, optionally, the K-d tree construction unit is configured to:

[0252] A splitting axis dimension determination subunit, configured to determine the current splitting axis dimension of the K-d tree based on the data point coordinates of a plurality of sample data points in the sample data set;

[0253] A left and right branch construction subunit, configured to construct the left branch and the right branch of the K-d tree respectively based on the current splitting axis dimension and the sample data points.

[0254] Based on any optional technical solution in the embodiment of the present invention, optionally, the splitting axis dimension determination subunit is configured to:

[0255] Calculate the variance of the data of each dimension in the data point coordinates of a plurality of sample data points in the sample data set, and take the dimension corresponding to the maximum variance as the current splitting axis dimension of the K-d tree.

[0256] Based on any optional technical solution in the embodiment of the present invention, optionally, the left and right branch construction subunit is configured to:

[0257] Retrieve the sample data set based on the current splitting axis dimension to obtain the median data of the current splitting axis dimension, and use the median data as the current node data;

[0258] Construct the left branch and the right branch of the K-d tree respectively based on the current splitting axis dimension, the current node data, and the sample data points in the sample data set that have not been constructed on the K-d tree.

[0259] Based on any optional technical solution in the embodiment of the present invention, optionally, the left and right branch construction subunit is specifically configured to:

[0260] Based on the current splitting axis dimension, divide all sample data points smaller than the current node data into the left branch of the K-d tree, and divide all sample data points greater than or equal to the current node data into the right branch of the K-d tree.

[0261] Based on any optional technical solution of the embodiment of the present invention, optionally, the K-dimensional tree construction subunit may specifically be configured to:

[0262] If the number of sample data points in the sample data set that are not constructed on the K-dimensional tree is less than a preset number threshold, then use the current node data as the leaf node data of the K-dimensional tree.

[0263] The above geographical location search device can execute the geographical location search method provided by any embodiment of the present invention, and has corresponding functional modules and beneficial effects for executing the geographical location search method.

[0264] Embodiment Five

[0265] Figure 4 It is a schematic structural diagram of an electronic device provided by Embodiment Six of the present invention. Figure 4 It shows a block diagram of an exemplary electronic device 12 suitable for implementing the embodiments of the present invention. Figure 4 The shown electronic device 12 is only an example and should not impose any limitation on the functions and usage scope of the embodiments of the present invention.

[0266] As Figure 4 shown, the electronic device 12 is presented in the form of a general-purpose computing device. The components of the electronic device 12 may include, but are not limited to: one or more processors or processing units 16, a system memory 28, and a bus 18 connecting different system components (including the system memory 28 and the processing unit 16).

[0267] The bus 18 represents one or more of several types of bus structures, including a memory bus or a memory controller, a peripheral bus, a graphics acceleration port, a processor, or a local bus using any bus structure in a variety of bus structures. For example, these architectures include, but are not limited to, Industry Standard Architecture (ISA) bus, Micro Channel Architecture (MAC) bus, Enhanced ISA bus, Video Electronics Standards Association (VESA) local bus, and Peripheral Component Interconnect (PCI) bus.

[0268] The electronic device 12 typically includes a variety of computer system readable media. These media can be any available media accessible by the electronic device 12, including volatile and non-volatile media, removable and non-removable media.

[0269] System memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory 32. The electronic device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, storage system 34 can be used for reading and writing on non-removable, non-volatile magnetic media ( Figure 4 not shown, typically referred to as a "hard disk drive"). Although Figure 4 not shown in the figure, a disk drive for reading and writing on removable non-volatile disks (such as "floppy disks"), and an optical disk drive for reading and writing on removable non-volatile optical disks (such as CD-ROM, DVD-ROM or other optical media) can be provided. In these cases, each drive can be connected to the bus 18 through one or more data media interfaces. System memory 28 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the present invention.

[0270] A program / utility 40 having a set (at least one) of program modules 42 can be stored, for example, in system memory 28. Such program modules 42 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment. Program modules 42 generally perform the functions and / or methods in the embodiments described in the present invention.

[0271] The electronic device 12 can also communicate with one or more external devices 14 (such as a keyboard, a pointing device, a display 24, etc.), and can also communicate with one or more devices that enable a user to interact with the electronic device 12, and / or communicate with any device that enables the electronic device 12 to communicate with one or more other computing devices (such as a network card, a modem, etc.). Such communication can be carried out through the input / output (I / O) interface 22. Moreover, the electronic device 12 can also communicate with one or more networks (such as a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) through the network adapter 20. As Figure 4 shown, the network adapter 20 communicates with other modules of the electronic device 12 through the bus 18. It should be understood that although Figure 4 not shown in the figure, other hardware and / or software modules can be used in conjunction with the electronic device 12, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, etc.

[0272] The processing unit 16 executes various functional applications and data processing by running the programs stored in the system memory 28, for example, implementing a search method for a geographical location provided by the embodiments of the present invention.

[0273] Embodiment Six

[0274] Embodiment Six of the present invention further provides a storage medium containing computer-executable instructions, and the computer-executable instructions are used to execute a search method for a geographical location when executed by a computer processor. The method includes:

[0275] Receiving a data query request of a target page sent by a target client, and obtaining the query longitude and latitude of a query data point corresponding to the data query request;

[0276] Performing a K-nearest neighbor search in a pre-constructed K-dimensional tree based on the query longitude and latitude to obtain at least one target data point corresponding to the query data point, wherein the K-dimensional tree is constructed based on the data longitude and latitude of each sample data point;

[0277] Displaying the target geographical locations corresponding to at least one of the target data points on the target page of the target client.

[0278] The computer storage medium of the embodiments of the present invention may adopt any combination of one or more computer-readable media. The computer-readable medium may be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples (non-exhaustive list) of the computer-readable storage medium include: an electrical connection having one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, the computer-readable storage medium may be any tangible medium that contains or stores a program, and the program may be used by or in combination with an instruction execution system, apparatus, or device.

[0279] A computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries computer-readable program code. Such a propagated data signal may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the foregoing. The computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device.

[0280] The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including - but not limited to - wireless, wire, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

[0281] The computer program code for performing the operations of the embodiments of the present invention may be written in one or more programming languages or combinations thereof. The programming languages include object-oriented programming languages such as Java, Smalltalk, C++, and also include conventional procedural programming languages such as the "C" language or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, executed as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., by using an Internet service provider to connect through the Internet).

[0282] Note that the above is only the preferred embodiment of the present invention and the applied technical principles. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein. Various obvious changes, re-adjustments, and substitutions can be made by those skilled in the art without departing from the protection scope of the present invention. Therefore, although the present invention has been described in detail through the above embodiments, the present invention is not limited to the above embodiments. Without departing from the concept of the present invention, more other equivalent embodiments may be included, and the scope of the present invention is determined by the scope of the appended claims.

Claims

1. A method for searching for a geographical location, characterized in that, Including: Receiving a data query request for a target page sent by a target client, and obtaining the query longitude and latitude of a query data point corresponding to the data query request; Performing K-nearest neighbor search in a pre-constructed K-d tree based on the query longitude and latitude to obtain at least one target data point corresponding to the query data point, where the K-d tree is constructed based on the data longitude and latitude of each sample data point; Displaying the target geographical locations corresponding to at least one of the target data points on the target page of the target client; specifically, The performing K-nearest neighbor search in the pre-constructed K-d tree based on the query longitude and latitude includes: Taking the root node as the root node of the current branch to determine the current branch; Determining whether all sample data points included in the current branch have been visited; If all sample data points included in the current branch have been visited, obtaining the maximum branch distance and the minimum branch distance between the sample data points included in the current branch and the query data point included in the cache information; If the maximum page distance of an adjacent page corresponding to the target page is included in the cache information, and the maximum page distance and the minimum page distance of the target page are not included, determining a branch to be searched in the pre-constructed K-d tree based on the maximum page distance of the adjacent page, the maximum page distance of the target page, the minimum branch distance and the maximum branch distance of the current branch, and performing K-nearest neighbor search in the K-d tree based on the branch to be searched.

2. The method according to claim 1, characterized in that, The performing K-nearest neighbor search in the pre-constructed K-d tree based on the query longitude and latitude includes: If not all sample data points included in the current branch have been visited, determining whether the split axis coordinate value of the root node is less than the split axis coordinate value corresponding to the query longitude and latitude of the query data point; If so, entering the left branch of the pre-constructed K-d tree for search, and updating the root node of the current branch to the root node of the left branch; If not, entering the right branch of the pre-constructed K-d tree for search, and updating the root node of the current branch to the root node of the right branch.

3. The method according to claim 1, characterized in that, The determining a branch to be searched in the pre-constructed K-d tree based on the maximum page distance of the adjacent page, the maximum page distance of the target page, and the minimum branch distance and the maximum branch distance of the current branch includes: If the maximum branch distance of the current branch is less than or equal to the maximum page distance of the adjacent page, or the minimum branch distance of the current branch is greater than the maximum page distance of the target page, marking the current branch as visited, and updating the parent node of the root node of the current branch to the root node of the current branch to update the current branch; Returning to perform the operation of determining whether all sample data points included in the current branch have been visited.

4. The method according to claim 1, characterized in that, The determining a branch to be searched in the pre-constructed K-d tree based on the maximum page distance of the adjacent page, the maximum page distance of the target page, and the minimum branch distance and the maximum branch distance of the current branch includes: Determine whether there is an intersection between the first distance interval formed by the minimum branch distance and the maximum branch distance of the current branch, and the second distance interval formed by the maximum page distance of the adjacent page and the maximum page distance of the target page; If there is an intersection between the first distance interval and the second distance interval, use the current branch as the branch to be searched in the pre-constructed K-d tree.

5. The method according to claim 1, characterized in that, The K-nearest neighbor search in the pre-constructed K-d tree based on the maximum branch distance and / or the minimum branch distance includes: If the cache information contains the maximum page distance and the minimum page distance of the target page, perform a K-nearest neighbor search in the K-d tree based on the minimum page distance and the maximum page distance of the target page, and the minimum branch distance and the maximum branch distance of the current branch.

6. The method according to claim 5, characterized in that, The K-nearest neighbor search in the K-d tree based on the minimum page distance and the maximum page distance of the target page, and the minimum branch distance and the maximum branch distance of the current branch includes: If the maximum branch distance of the current branch is less than the minimum page distance of the target page, or the minimum branch distance of the current branch is greater than the maximum page distance of the target page, mark the current branch as visited, and update the parent node of the root node of the current branch to the root node of the current branch to update the current branch; Return to perform the operation of determining whether all the sample data points included in the current branch have been visited.

7. The method according to claim 5, characterized in that, The K-nearest neighbor search in the K-d tree based on the minimum page distance and the maximum page distance of the target page, and the minimum branch distance and the maximum branch distance of the current branch includes: If the minimum distance of the target page is less than or equal to the minimum branch distance of the current branch and the maximum distance of the current branch is less than the maximum page distance of the target page, add the sample data points included in the current branch to the candidate set, mark the current branch as visited, and update the parent node of the root node of the current branch to the root node of the current branch to update the current branch; Return to perform the operation of determining whether all the sample data points included in the current branch have been visited.

8. The method according to claim 5, characterized in that, The K-nearest neighbor search in the K-d tree based on the minimum page distance and the maximum page distance of the target page, and the minimum branch distance and the maximum branch distance of the current branch includes: Determine whether there is an intersection between the third distance interval formed by the minimum branch distance and the maximum branch distance of the current branch, and the fourth distance interval formed by the maximum page distance of the target page and the maximum page distance of the target page; If there is an intersection between the third distance interval and the fourth distance interval, determine whether the root node of the current branch is a leaf node; If so, add the sample data points whose distances to the query data point are within the range of the minimum page distance and the maximum page distance of the target page among the sample data points corresponding to the leaf node to the candidate set; When the number of sample data points in the candidate set reaches a preset threshold, the sample data points in the candidate set are used as the target data points corresponding to the query data points.

9. The method according to claim 1, wherein, The K-nearest neighbor search based on the query longitude and latitude in the pre-constructed K-d tree includes: Converting the query longitude and latitude into the coordinates of a query point in a spatial rectangular coordinate system, and performing K-nearest neighbor search in the pre-constructed K-d tree based on the coordinates of the query point.

10. The method according to claim 9, wherein, The conversion of the query longitude and latitude into the coordinates of a query point in a spatial rectangular coordinate system includes: Converting the query longitude and latitude into the coordinates of a query point in a spatial rectangular coordinate system based on the following formula: ; ; ; ; Among them, represents the radius of the earth; represents the longitude of the query data point; represents the latitude of the query data point; is the pi; represents the abscissa of the query data point in the space rectangular coordinate system; represents the ordinate of the query data point in the space rectangular coordinate system; represents the applicate of the query data point in the space rectangular coordinate system.

11. The method according to claim 9, wherein, The K-nearest neighbor search based on the coordinates of the query point in the pre-constructed K-d tree includes: Determining the coordinate values of the splitting axes corresponding to each node in the pre-constructed K-d tree for each dimension of the query point coordinates; Performing K-nearest neighbor search in the pre-constructed K-d tree based on the coordinate values of the splitting axes.

12. The method according to claim 9, wherein, After performing K-nearest neighbor search based on the coordinates of the query point in the pre-constructed K-d tree to obtain at least one target data point corresponding to the query data point, it further includes: Calculating the straight-line distance between each target data point and the query data point; Calculating the arc length between the target data point and the query data point based on the straight-line distance, and displaying the arc length and the target geographical location correspondingly on the target page.

13. The method according to claim 12, wherein, The calculation of the straight-line distance between each target data point and the query data point includes: Calculating the straight-line distance between each target data point and the query data point based on the following formula: , Among them, represents the straight-line distance between the target data point and the query data point; represents the horizontal axis coordinate of the target data point; represents the vertical axis coordinate of the target data point; represents the vertical axis coordinate of the target data point; represents the horizontal axis coordinate of the query data point; represents the vertical axis coordinate of the query data point; represents the vertical axis coordinate of the query data point.

14. The method according to claim 9, wherein, The method for constructing the K-d tree includes: Obtaining the data longitude and latitude of each collected sample data point; Converting the data longitude and latitude into the coordinates of a data point in a spatial rectangular coordinate system; Constructing the K-d tree based on the coordinates of each sample data point in the sample data set, where the sample data set contains multiple sample data points.

15. The method according to claim 14, wherein, The construction of the K-d tree based on the coordinates of each sample data point in the sample data set includes: Determining the current splitting axis dimension of the K-d tree based on the coordinates of multiple sample data points in the sample data set; Constructing the left and right branches of the K-d tree based on the current splitting axis dimension and the sample data points respectively.

16. The method according to claim 15, wherein, The determination of the current splitting axis dimension of the K-d tree based on the coordinates of multiple sample data points in the sample data set includes: Calculating the variance of the data in each dimension of the coordinates of multiple sample data points in the sample data set, and taking the dimension corresponding to the maximum variance as the current splitting axis dimension of the K-d tree.

17. The method according to claim 16, wherein, Determining the left and right branches of the K-d tree based on the current splitting axis dimension and the sample data points respectively includes: Retrieving the sample data set based on the current splitting axis dimension to obtain the median data of the current splitting axis dimension, and using the median data as the current node data; Construct the left and right branches of the K-d tree respectively based on the current splitting axis dimension, the current node data, and the sample data points in the sample dataset that have not been constructed on the K-d tree.

18. The method according to claim 17, wherein The constructing of the left and right branches of the K-d tree based on the current splitting axis dimension, the current node data, and the sample data points in the sample dataset that have not been constructed on the K-d tree includes: Based on the current splitting axis dimension, divide all sample data points smaller than the current node data into the left branch of the K-d tree, and divide all sample data points greater than or equal to the current node data into the right branch of the K-d tree.

19. The method according to claim 14, wherein The constructing of the K-d tree based on the data point coordinates of each sample data point in the sample dataset includes: If the number of sample data points in the sample dataset that have not been constructed on the K-d tree is less than a preset number threshold, use the current node data as the leaf node data of the K-d tree.

20. A search device for a geographical location, wherein Includes: A query request module, configured to receive a data query request for a target page sent by a target client, and obtain the query longitude and latitude of a query data point corresponding to the data query request; A data search module, configured to perform a K-nearest neighbor search in a pre-constructed K-d tree based on the query longitude and latitude to obtain at least one target data point corresponding to the query data point, where the K-d tree is constructed based on the data longitude and latitude of each sample data point; A data display module, configured to display the target geographical locations corresponding to at least one of the target data points on the target page of the target client; Wherein, the data search module includes a branch determination unit, an access judgment unit, a branch distance acquisition unit, and a branch distance search unit; the branch determination unit is configured to use the root node as the root node of the current branch to determine the current branch; the access judgment unit is configured to judge whether all the sample data points included in the current branch have been accessed; the branch distance acquisition unit is configured to, if all the sample data points included in the current branch have been accessed, obtain the maximum branch distance and the minimum branch distance between the sample data points included in the current branch and the query data point included in the cache information; the branch distance search unit is configured to, if the cache information includes the maximum page distance of an adjacent page corresponding to the target page and does not include the maximum page distance and the minimum page distance of the target page, determine the branch to be searched in the pre-constructed K-d tree based on the maximum page distance of the adjacent page, the maximum page distance of the target page, the minimum branch distance of the current branch, and the minimum branch distance, and perform a K-nearest neighbor search in the K-d tree based on the branch to be searched.

21. An electronic device, wherein The electronic device includes: One or more processors; A storage device, configured to store one or more programs, When the one or more programs are executed by the one or more processors, enable the one or more processors to implement the geographical location search method as described in any one of claims 1-19.

22. A computer-readable storage medium having a computer program stored thereon, wherein When the program is executed by a processor, it implements the method for searching for a geographical location as described in any one of claims 1-19.

Citation Information

Patent Citations

  • Clustering method based on local direction centrality measurement

    CN111291276A

  • Earth simulation system grid remapping method based on rapid construction of KD tree

    CN112181991A