CN113139032A - Geographic position searching method and device, electronic equipment and storage medium - Google Patents

Geographic position searching method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN113139032A
CN113139032A CN202110546700.0A CN202110546700A CN113139032A CN 113139032 A CN113139032 A CN 113139032A CN 202110546700 A CN202110546700 A CN 202110546700A CN 113139032 A CN113139032 A CN 113139032A
Authority
CN
China
Prior art keywords
branch
distance
page
query
data point
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110546700.0A
Other languages
Chinese (zh)
Inventor
周康
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Construction Bank Corp
Original Assignee
China Construction Bank Corp
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Construction Bank Corp filed Critical China Construction Bank Corp
Priority to CN202110546700.0A priority Critical patent/CN113139032A/en
Publication of CN113139032A publication Critical patent/CN113139032A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/29Geographical information databases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/901Indexing; Data structures therefor; Storage structures
    • G06F16/9027Trees
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/907Retrieval characterised by using metadata, e.g. metadata not derived from the content or metadata generated manually
    • G06F16/909Retrieval characterised by using metadata, e.g. metadata not derived from the content or metadata generated manually using geographical or spatial information, e.g. location
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/953Querying, e.g. by the use of web search engines
    • G06F16/9537Spatial or temporal dependent retrieval, e.g. spatiotemporal queries

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Library & Information Science (AREA)
  • Remote Sensing (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the invention relates to the technical field of automatic programming, and discloses a geographic position searching method and device, electronic equipment and a storage medium. Wherein, the method comprises the following steps: receiving a data query request of a target page sent by a target client, and acquiring query longitude and latitude of a query data point corresponding to the data query request; performing K 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; and displaying the target geographic position corresponding to at least one target data point on a target page of the target client. According to the technical scheme of the embodiment of the invention, the K neighbor search is carried out in the pre-constructed K dimensional tree, so that the method is not limited by the distance range, the query quantity can be reduced, the query speed is improved, the client request can be responded more quickly, and the user experience is improved.

Description

Geographic position searching method and device, electronic equipment and storage medium
Technical Field
The embodiment of the invention relates to the technical field of automatic program design, in particular to a geographic position searching method and device, electronic equipment and a storage medium.
Background
At present, banks have a large number of network points, employees, equipment, clients and the like nationwide, and need to inquire specific objects nationwide according to the longitude and latitude of a specified place in business, sort the objects in a near-to-far manner, visually display the objects at the client and provide data support for resource scheduling and decision making.
The prior art is based on dividing the map into small individual blocks of substantially the same size and then calculating the block to which each data point belongs. During query, all data points of the block where the query data points are located are found, and then the outer-layer block is queried layer by layer. If the data points are relatively sparse and the method relates to large-scale searching of hundreds of kilometers, the efficiency is low, the reaction speed is slow, and the method is difficult to meet the requirement of real-time query; if the data points are hit very densely, the data points contained in the block are very many, which greatly exceeds the single-page display capacity of the display page, and the problem of a large amount of redundant calculation exists.
Disclosure of Invention
The embodiment of the invention provides a geographic position searching method, a geographic position searching device, electronic equipment and a storage medium, and aims to realize quick query of geographic positions.
In a first aspect, an embodiment of the present invention provides a geographic location search method, where the method includes:
receiving a data query request of a target page sent by a target client, and acquiring query longitude and latitude of a query data point corresponding to the data query request;
performing K 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;
and displaying the target geographic position corresponding to at least one target data point on a target page of the target client.
In a second aspect, an embodiment of the present invention further provides an apparatus for searching for a geographic location, where the apparatus includes:
the query request module is used for receiving a data query request of a target page sent by a target client and acquiring query longitude and latitude of a query data point corresponding to the data query request;
the data search module is used for carrying out K 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;
and the data display module is used for displaying the target geographic position corresponding to at least one target data point on a target page of the target client.
In a third aspect, an embodiment of the present invention further provides an electronic device, where the electronic device includes:
one or more processors;
a storage device for storing one or more programs,
when the one or more programs are executed by the one or more processors, the one or more processors implement the method for searching for a geographic location according to any technical solution in the embodiment of the present invention.
In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the method for searching for a geographic location according to any of the technical solutions in the embodiments of the present invention.
According to the technical scheme of the embodiment of the invention, the K neighbor search is carried out in the pre-constructed K dimensional tree, so that the technical problems that the existing search mode is low in search speed and redundant calculation is easy to generate are solved, the search quantity is not limited by a distance range, the search speed is improved, the data query request of the target client side is responded more quickly, and the user experience is improved.
Drawings
In order to more clearly illustrate the technical solutions of the exemplary embodiments of the present invention, a brief description is given below of the drawings used in describing the embodiments. It should be clear that the described figures are only views of some of the embodiments of the invention to be described, not all, and that for a person skilled in the art, other figures can be derived from these figures without inventive effort.
Fig. 1 is a schematic flowchart of a geographic location searching method according to an embodiment of the present invention;
fig. 2 is a schematic flowchart of a geographic location searching method according to a second embodiment of the present invention;
FIG. 3 is a schematic structural diagram of a geographic location search apparatus according to a third embodiment of the present invention
Fig. 4 is a schematic structural diagram of an electronic device according to a fourth embodiment of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures.
It should be further noted that, for the convenience of description, only some but not all of the relevant aspects of the present invention are shown in the drawings. Before discussing exemplary embodiments in more detail, it should be noted that some exemplary embodiments are described as processes or methods depicted as flowcharts. Although a flowchart may describe the operations (or steps) as a sequential process, many of the operations can be performed in parallel, concurrently or simultaneously. In addition, the order of the operations may be re-arranged. The process may be terminated when its operations are completed, but may have additional steps not included in the figure. The processes may correspond to methods, functions, procedures, subroutines, and the like.
Example one
Fig. 1 is a flowchart illustrating a geographical location searching method according to an embodiment of the present invention, where the embodiment is applicable to a case of searching for a geographical location, and the method may be executed by a geographical location searching apparatus, and the apparatus may be implemented in a software and/or hardware manner.
As shown in fig. 1, the method of the present embodiment may specifically include the following steps:
s110, receiving a data query request of a target page sent by a target client, and acquiring query latitude and longitude of a query data point corresponding to the data query request.
Wherein the query data point is to calculate its nearest neighbor location point. In embodiments of the present invention, a query data point may be understood as a geographic location of a request query. The geographic location of the query data point may be represented in terms of a query latitude and longitude. The data query request can be understood as a request for querying the page of the target page sent by the target client for real geographic location data. A data query request may be understood as a request instruction generated upon receiving a trigger operation for requesting a data query.
It should be noted that the action region of the trigger operation and the action mode in the action region may be set according to actual requirements, and are not specifically limited herein. Optionally, the trigger operation functions as a trigger operation input through an input device, or an operation input through a human-computer interaction manner such as sound and gestures. The action region of the action mode of the trigger operation may be a preset trigger element, or a preset trigger operation recognition region or the like. For example, the trigger operation may be an operation when a certain list view is scroll-triggered, an operation when a certain button is click-triggered, an operation when a certain page is displayed, or the like.
S120, performing K 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.
Where a K-dimensional tree is a tree-like data structure that stores sample data points in K-dimensional space for fast retrieval thereof. A k-nearest neighbor search may be understood as finding the k sample data points that are closest in distance to the query data point. The data point can be understood as an object with latitude and longitude information, and can represent a bank outlet, equipment, an enterprise and the like.
Specifically, the K neighbor search is performed in a pre-constructed K-dimensional tree based on the query longitude and latitude, and includes: and converting the inquiry longitude and latitude into an inquiry point coordinate of a space rectangular coordinate system, and carrying out K neighbor search in a pre-constructed K-dimensional tree based on the inquiry point coordinate.
Illustratively, converting the query latitude and longitude into a query point coordinate of a spatial rectangular coordinate system includes: converting the query longitude and latitude into a query point coordinate of a space rectangular coordinate system based on the following formula:
lon=lon/180*π
lat=lat/180*π
x=R*cos(lat)*cos(lon)
y=R*cos(lat)*sin(lon)
z=R*sin(lat)
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; pi is the circumference ratio; x represents the horizontal axis coordinate of the query data point in a space rectangular coordinate system; y represents the longitudinal axis coordinate of the query data point in a space rectangular coordinate system; z represents the vertical axis coordinate of the query data point in the rectangular spatial coordinate system.
Optionally, performing a K neighbor search in a pre-constructed K-dimensional tree based on the query point coordinates includes: determining a segmentation axis coordinate value corresponding to a segmentation axis dimension corresponding to each node in a pre-constructed K-dimensional tree in the query point coordinates; and performing K neighbor search in a pre-constructed K dimensional tree based on the segmentation axis coordinate value.
In an embodiment of the present invention, the method for constructing a K-dimensional tree may specifically include: acquiring data longitude and latitude of each acquired sample data point; converting the longitude and latitude of the data into a data point coordinate of a space rectangular coordinate system; constructing the K-dimensional tree based on the data point coordinates of each sample data point in a sample data set, wherein the sample data set contains a plurality of sample data points.
Similarly, a data longitude and latitude (lon, lat) may be obtained for each sample data point collected, converted to data point coordinates (x, y, z) of a spatial rectangular coordinate system, and converted to data point coordinates of the spatial rectangular coordinate system based on the following formula:
lon=lon/180*π
lat=lat/180*π
x=R*cos(lat)*cos(lon)
y=R*cos(lat)*sin(lon)
z=R*sin(lat)
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; pi is the circumference ratio; x represents the horizontal axis coordinate of the query data point in a space rectangular coordinate system; y represents the longitudinal axis coordinate of the query data point in a space rectangular coordinate system; z represents the vertical axis coordinate of the query data point in the rectangular spatial coordinate system.
In particular, constructing the K-dimensional tree based on the data point coordinates of each sample data point in the sample dataset may include: determining a current segmentation axis dimension of the K-dimensional tree based on the data point coordinates of a plurality of sample data points in a sample dataset; constructing a left branch and a right branch of the K-dimensional tree, respectively, based on the current segmentation axis dimension and the sample data points.
Optionally, said determining a current segmentation axis dimension of said K-dimensional tree based on said data point coordinates of a plurality of sample data points in a sample dataset comprises: performing variance calculation on data of each dimension in the data point coordinates of a plurality of sample data points in the sample data set, and taking the dimension corresponding to the maximum variance as the current segmentation axis dimension of the K-dimensional tree; or randomly selecting data of one dimension in the data point coordinates of the sample data points as an initial segmentation axis dimension, and then taking different dimensions in turn as the current segmentation axis dimension when the nodes change.
Optionally, determining a left branch and a right branch of the K-dimensional tree, respectively, based on the current segmentation axis dimension and the sample data point, comprises: retrieving the sample data set based on the current segmentation axis dimension to obtain median data of the current segmentation axis dimension, and taking the median data as current node data; and respectively constructing a left branch and a right branch of the K-dimensional tree based on the current segmentation axis dimension, the current node data and the sample data points which are not constructed on the K-dimensional tree in the sample data set.
Specifically, constructing a left branch and a right branch of the K-dimensional tree based on the current segmentation axis dimension, the current node data, and sample data points in the sample data set that are not constructed on the K-dimensional tree includes: and dividing all sample data points smaller than the current node data into the left branch of the K-dimensional tree and dividing all sample data points larger than or equal to the current node data into the right branch of the K-dimensional tree based on the current segmentation axis dimension.
In this 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 leaf node data of the K-dimensional tree. The preset number threshold may be set according to actual requirements, and a specific value thereof is not limited herein, and may be, for example, 10 or 20. The method has the advantages that under the condition that the small calculation amount is ensured, the depth of the K-dimensional tree can be effectively reduced, the construction operation is simplified, and the searching speed is accelerated.
S130, displaying the target geographic position corresponding to at least one target data point on a target page of the target client.
For example, the target geographic location corresponding to the target data point may be displayed by name and/or city street. The display mode may be words and/or pictures, and is not limited in particular.
Specifically, if there are two or more target data points, a target display order of the target geographic location corresponding to the target data point on the target page may be determined according to a distance between the target data point and the query data point, and then the target geographic location corresponding to the target data point is displayed on the target page of the target client based on the target display order.
For example, the target geographic location corresponding to the target data point may be displayed on the target page of the target client from top to bottom or from front to back according to the order of the distance between the target data point and the query data point. In other words, target geographic locations with closer distances between the actual target data points and the query data points are prioritized.
Optionally, after performing K neighbor search in a 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, the method further includes: calculating a linear distance between each target data point and the query data point; and 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 geographic position on the target page.
Specifically, the linear distance between each of the target data points and the query data point may be calculated based on the following formula:
Figure BDA0003073940310000081
wherein L represents a linear distance between a target data point and the query data point; x is the number of1Coordinates of the horizontal axis representing the target data point; y is1A vertical axis coordinate representing a target data point; z is a radical of1Vertical axis coordinates representing a target data point; x is the number of2Coordinates of the horizontal axis representing the query data points; y is2A vertical axis coordinate representing the query data point; z is a radical of2Representing the vertical axis coordinates of the query data point.
Wherein calculating the arc length between the target data point and the query data point based on the linear distance may be specifically implemented by the following formula:
S=2*R*arcsin(L/2R),
wherein S is the arc length between the target data point and the query data point; l is the linear distance between the target data point and the query data point, and R is the radius of the earth.
In the technical scheme, the arc length is used as the actual distance between the target geographic position and the query position corresponding to the query data point, and the calculation is more accurate compared with the calculation according to the two-dimensional longitude and latitude.
According to the technical scheme of the embodiment of the invention, the K neighbor search is carried out in the pre-constructed K dimensional tree, so that the technical problems that the existing search mode is low in search speed and redundant calculation is easy to generate are solved, the search quantity is not limited by a distance range, the search speed is improved, the data query request of the target client side is responded more quickly, and the user experience is improved.
Example two
Fig. 2 is a schematic flow chart of a geographic location searching method according to a second embodiment of the present invention, where on the basis of any optional technical solution in the second embodiment of the present invention, optionally, the performing K neighbor search in a pre-constructed K-dimensional 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; judging whether all sample data points contained in the current branch are accessed; if the sample data points contained in the current branch are not completely accessed, judging whether the segmentation axis coordinate value of the root node is smaller than the segmentation axis coordinate value corresponding to the query longitude and latitude of the query data point; if yes, entering a left branch of a pre-constructed K-dimensional tree for searching, and updating the root node of the current branch into the root node of the left branch; if not, entering a right branch of a pre-constructed K-dimensional tree for searching, and updating the root node of the current branch into the root node of the right branch; if all sample data points contained in the current branch are accessed, acquiring the maximum branch distance and the minimum branch distance between the sample data points contained in the current branch contained in the cache information and the query data point; and performing K neighbor search in a pre-constructed K-dimensional tree based on the maximum branch distance and the minimum branch distance.
As shown in fig. 2, the method of the embodiment may specifically include:
s210, receiving a data query request of a target page sent by a target client, and acquiring query latitude and longitude of a query data point corresponding to the data query request.
And S220, taking the root node as the root node of the current branch to determine the current branch.
In other words, the search is performed with the root node of the K-dimensional tree as the starting point, and the branch where the root node is located is the current branch.
S230, determining whether all the sample data points included in the current branch have been accessed, if not, executing S240, and if all the sample data points included in the current branch have been accessed, executing S270.
In the embodiment of the present invention, if it is detected that the data query request based on the query data point is a first request, target data points corresponding to a preset number of display pages may be searched, and the target data points and the display pages are stored correspondingly.
The method has the advantages that when the data corresponding to the subsequent data query request received by the target client falls into the pre-cached sample data points, the target data points corresponding to the data query request are directly read and returned, so that frequent k neighbor query is avoided, and if the data falls out of the cached sample data points, the k neighbor query is performed, so that the response speed is improved.
Considering that the existing data display mode mostly adopts paging display, in order to further improve the search efficiency, avoid re-reading search and generate redundant computation, the technical scheme of the embodiment of the invention can store the following two types of information when performing k neighbor paging search:
for each paging search result, the maximum distance from the sample data point contained in the page to the page of the query data point is saved
Figure BDA0003073940310000111
And page minimum distance;
if all sample data points contained in the current branch have been visited, the branch minimum distance and the branch maximum distance from the sample data point contained in the current branch to the query data point are saved.
If all sample data points contained in the current branch are accessed, the maximum branch distance and the minimum branch distance between the sample data points contained in the current branch and the query data points can be read without repeated access.
If all of the sample data points contained in the current branch have not been accessed, further searching of the data of the current branch is required.
S240, judging whether the segmentation axis coordinate value of the root node is smaller than the segmentation axis coordinate value corresponding to the query longitude and latitude of the query data point, if so, executing S250, otherwise, executing S260.
Specifically, the search path may be determined based on the values of the segmented axis coordinate of the root node of the current branch and the values of the segmented axis coordinate corresponding to the query latitude and longitude of the query data point.
And S250, entering a pre-constructed left branch of the K-dimensional tree for searching, updating the root node of the current branch into the root node of the left branch, and returning to execute the S240.
And S260, entering a right branch of a pre-constructed K-dimensional tree for searching, updating the root node of the current branch into the root node of the right branch, and returning to execute S240.
S270, obtaining the maximum branch distance and the minimum branch distance between the sample data point contained in the current branch contained in the cache information and the query data point, and executing S280.
The maximum distance and the minimum distance between the sample data point contained in the current branch and the query data point are required to be calculated respectively, the maximum value is selected from all calculated distances to serve as the maximum distance of the branch, and the minimum value is selected to serve as the minimum distance of the branch. The manner of calculating the linear distance may be referred to as the foregoing manner, and is not described herein again.
S280, performing K neighbor search in a 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, wherein the K-dimensional tree is constructed based on the data longitude and latitude of each sample data point.
Specifically, performing a K neighbor search in a pre-constructed K-dimensional tree based on the branch maximum distance and the branch minimum 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, determining a branch to be searched in a 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 performing K neighbor search in the K-dimensional tree based on the branch to be searched.
If the cache information does not include the maximum page distance and the minimum page distance of the target page, it indicates that the data of the page has not been searched before, at this time, it may be determined whether the cache includes the maximum page distance of an adjacent page corresponding to the target page, and if so, the branch to be searched in the K-dimensional tree that is constructed in advance may 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.
It should be noted that the maximum page distance of the target page may be set according to an actual situation, and a specific numerical value of the maximum page distance is not limited herein.
Specifically, the determining a branch to be searched in a 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 branch distance and the maximum branch distance of the current branch includes: if the maximum branch distance of the current branch is smaller 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 be the root node of the current branch so as to update the current branch; and returning to execute the operation of judging whether all the sample data points contained in the current branch are accessed.
If the maximum distance of the branch of the current branch is less than or equal to the maximum distance of the page of the adjacent page, the data points are all in the page before the (i +1) th page, so that the branch can be marked as visited without further visiting.
If the minimum branch distance of the current branch is greater than the maximum page distance of the target page, the data points contained in the branch are all out of the (i +1) th page, and the branch is marked as accessed and does not need to be accessed any more.
Optionally, determining a branch to be searched in a 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 branch distance and the maximum branch distance of the current branch, includes: determining whether an intersection exists between a first distance interval formed by the minimum distance of the branch of the current branch and the maximum distance of the branch and a second distance interval formed by the maximum distance of the page of the adjacent page and the maximum distance of the page of the target page; and if the first distance interval and the second distance interval have intersection, using the current branch as a branch to be searched in a pre-constructed K-dimensional tree.
If the first distance interval and the second distance interval are partially intersected or the current branch does not have cache information, the current branch is indicated to have sample data points which are possibly in the target page, and searching needs to be carried out based on the current branch.
Optionally, performing a K neighbor search in a pre-constructed K-dimensional tree based on the branch maximum distance and/or the branch minimum distance, including: and if the cache information comprises the maximum page distance and the minimum page distance of the target page, performing K neighbor search in a 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.
If the cache information includes the maximum page distance and the minimum page distance of the target page, the previously searched page may be subjected to K 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.
Optionally, performing a K neighbor search in the K-dimensional tree based on the page minimum distance and the page maximum distance of the target page and the branch minimum distance and the branch maximum distance of the current branch may include: if the maximum branch distance of the current branch is smaller than the minimum page distance of the target page, or the minimum branch distance of the current branch is larger 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 be the root node of the current branch so as to update the current branch; and then returning to execute the operation of judging whether all the sample data points contained in the current branch are accessed or not, and continuing to search.
Optionally, performing a K neighbor search in the K-dimensional tree based on the page minimum distance and the page maximum distance of the target page and the branch minimum distance and the branch maximum distance of the current branch, including: if the minimum distance of the target page is less than or equal to the branch minimum distance of the current branch and the maximum distance of the current branch is less than the page maximum distance of the target page, adding the contained sample data point of the current branch into a candidate set, 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 so as to update the current branch; and then returning to execute the operation of judging whether all the sample data points contained in the current branch are accessed or not, and continuing to search.
Optionally, performing a K neighbor search in the K-dimensional tree based on the page minimum distance and the page maximum distance of the target page and the branch minimum distance and the branch maximum distance of the current branch, including: determining whether an intersection exists between a third distance interval formed by the minimum distance of the branch of the current branch and the maximum distance of the branch and a fourth distance interval formed by the maximum distance of the page of the target page and the maximum distance of the page of the target page; if the third distance interval and the fourth distance interval have intersection, judging whether the root node of the current branch is a leaf node; if so, adding sample data points, of the sample data points corresponding to the leaf nodes, of which the distances to the query data points are within the range of the minimum page distance and the maximum page distance of the target page into the candidate set; and when the number of the sample data points in the candidate set reaches a preset threshold value, taking the sample data points in the candidate set as target data points corresponding to the query data points.
If the root node of the current branch is not the leaf node, the sub-branch of the current branch is entered to continue the recursive search.
S290, displaying the target geographic position corresponding to at least one target data point on the target page of the target client.
According to the technical scheme, whether all sample data points contained in the current branch are visited can be judged, the search mode in K neighbor search in the K-dimensional tree is determined, unnecessary repeated access to the visited branch is avoided, the search efficiency is improved, and then K neighbor search is assisted through the maximum distance and the minimum distance of the branch between the sample data points contained in the cached branch in the cache information and the query data points, so that the K neighbor search can be accurately and quickly performed by means of the maximum distance and the minimum distance of the branch while too much cache space is not occupied.
EXAMPLE III
The embodiment of the invention provides an optional example of searching the geographic position based on the geographic position searching method in the embodiment of the invention. The specific implementation process is as follows:
firstly, establishing data index
Before K-neighborhood search based on a K-Dimensional tree (KDTree), a data index needs to be established based on the KDTree. The method specifically comprises the following steps:
1) longitude and latitude-to-rectangular coordinate system
Acquiring data longitude and latitude (lon, lat) of each acquired sample data point, converting the data longitude and latitude (lon, lat) into data point coordinates (x, y, z) of a space rectangular coordinate system, and converting the data longitude and latitude into the data point coordinates of the space rectangular coordinate system based on the following formula:
lon=lon/180*π
lat=lat/180*π
x=R*cos(lat)*coS(lon)
y=R*cos(lat)*sin(lon)
z=R*sin(lat)
wherein 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; pi is the circumference ratio; x represents the horizontal axis coordinate of the sample data point in a space rectangular coordinate system; y represents the longitudinal axis coordinate of the sample data point in a space rectangular coordinate system; z represents the vertical axis coordinate of the sample data point in the rectangular spatial coordinate system.
2) Building binary tree index for (x, y, z) sample data set by using KDTree data structure
KDTree is a data structure for dividing k-dimensional data space, and is mainly applied to efficient search of key data in multi-dimensional space, such as range search and nearest neighbor search. Accordingly, a KDTree may be constructed based on the data point coordinates of each sample data point in a sample data set, where the sample data set contains a plurality of sample data points.
For spatial coordinate data (x, y, z) of a sample data point, there are 3 dimensions, specifically, the step of establishing a KDTree may include:
1. initializing a segmentation axis dimension: and performing variance calculation on data of each dimension in the data point coordinates of a plurality of sample data points in the sample data set, and taking the dimension corresponding to the maximum variance as the current segmentation axis dimension of the K-dimensional tree and marking as r.
2. Selecting a dividing point: and retrieving the sample data set based on the current segmentation axis dimension to obtain median data of the current segmentation axis dimension, taking the median data as current node data, namely retrieving the current data set according to the segmentation axis dimension, finding the median data of the dimension, and putting the median data on the current node. And if the number of the sample data points contained in the current data set is smaller than a preset number threshold N, using the current node data as leaf node data of the K-dimensional tree. Wherein, the current data set can be understood as a data set containing sample data points which are not 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 double branches are divided.
3. Dividing two branches:
dividing a left branch: dividing all sample data points smaller than the current node data into left branches of the K-dimensional tree based on the current segmentation axis dimension;
dividing a right branch: based on the current segmentation axis dimension, dividing all sample data points which are larger than or equal to the current node data into the right branch of the K-dimensional tree.
4. Updating the dimension of the segmentation axis:
optionally, the dividing axis latitude is determined by adopting a mode of r ═ r + 1)% 3, different dimensions are selected as the dividing axis dimensions in turn, or the dimensions with the largest variance are selected as the dividing axis dimensions.
5. Establishing a subtree:
establishing a left subtree: recursively performing step 2 in the data of the left branch;
establishing a right subtree: step 2 is performed recursively in the data of the right branch.
Two, data search
When a data query request of a target page sent by a target client is received, acquiring query longitude and latitude of a query data point corresponding to the data query request, converting the query longitude and latitude into query point coordinates of a space rectangular coordinate system and converting the query point coordinates into rectangular coordinates (x, y, z), and specifically, converting the query longitude and latitude into the query point coordinates of the space rectangular coordinate system based on the following formula:
lon=lon/180*π
lat=lat/180*π
x=R*cos(lat)*cos(lon)
y=R*cos(lat)*sin(lon)
z=R*sin(lat)
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; pi is the circumference ratio; x represents the horizontal axis coordinate of the query data point in a space rectangular coordinate system; y represents the longitudinal axis coordinate of the query data point in a space rectangular coordinate system; z represents the vertical axis coordinate of the query data point in the rectangular spatial coordinate system.
And then, performing k neighbor search on the established KDTree index.
Each node on the KDTree represents a small region in space, and the search is based on the region for tile retrieval. The searching steps are as follows:
1. searching leaf nodes to which the query data points belong:
1) setting a current node as a root node
2) If the partition axis coordinate value of the current node is smaller than the partition axis coordinate value corresponding to the query latitude and longitude of the query data point, entering a left sub-tree, and updating the current node into a left sub-tree root node; if the value of the partitioning axis coordinate of the current node is larger than the value of the partitioning axis coordinate corresponding to the query latitude and longitude of the query data point, entering a right sub-tree, and updating the current node to be the root node of the right sub-tree
3) Repeating the step 2) until the leaf nodes are reached
2. Recursive search
1) Establishing an empty candidate set S
2) For a branch node:
2.1) if the left and right child branches are accessed, marking the branch node as accessed and jumping to a parent node of the branch node;
2.2) if the current branch has an unvisited child node:
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 segmentation axis of the subbranch is less than the maximum distance in the candidate set, entering the subbranch and jumping to the step 2);
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 segmentation axis of the subbranch is greater than or equal to the maximum distance in the candidate set, pruning in advance and marking the branch as visited;
3) and 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, adding the sample data point into the candidate set, kicking out the sample data point with the maximum distance in the candidate set, and then jumping to a father node of the leaf node.
And when the root node of the KDTree is visited, finishing the searching process, wherein the data point of the candidate set S is the k neighbor finally searched.
It should be noted that, in the search process, the nearest neighbor target data point may be determined by calculating a straight-line distance between the target data point and the query data point.
Specifically, the linear distance between each of the target data points and the query data point may be calculated based on the following formula:
Figure BDA0003073940310000201
wherein L represents a linear distance between a target data point and the query data point; x is the number of1Coordinates of the horizontal axis representing the target data point; y is1A vertical axis coordinate representing a target data point; z is a radical of1Vertical axis coordinates representing a target data point; x is the number of2Coordinates of the horizontal axis representing the query data points; y is2A vertical axis coordinate representing the query data point; z is a radical of2Representing the vertical axis coordinates of the query data point.
The technical scheme is particularly suitable for the case that the arc length is less than 180 degrees, for example, in the territory scope of China, 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 the nearest neighbor is obtained, the real arc length does not need to be accurately calculated, and only the linear distance between the target data point and the query data point is needed to be known.
Third, search state caching and recovery
In the embodiment of the invention, in order to further improve the search efficiency, efficient search can be ensured by establishing a secondary cache.
First-level caching: result caching
If the actual paging size corresponding to the received data query request sent by the target client is n, 10 × n nearest sample data points can be queried at one time and cached when k neighbor query is actually performed based on the KDTree each time; wherein n is a positive integer. For example, n may be a positive integer of 100 or less.
That is, if it is detected that the data query request based on the query data point is a first request, the target data points corresponding to a preset number of display pages may be searched, and the target data points are stored in correspondence with the display pages.
The method has the advantages that when the data corresponding to the subsequent data query request received by the target client falls into the pre-cached 10 × n sample data points, the target data points corresponding to the data query request are directly read and returned, so that frequent k neighbor query is avoided, and if the data fall out of the 10 × n data points, the k neighbor query is performed, so that the response speed is improved.
And (3) second-level caching: search state caching during k neighbor search based on KDTree
When k-neighbor paging search is performed, the following two types of information are stored:
a. for each paging search result, the maximum distance from the sample data point contained in the page to the page of the query data point is saved
Figure BDA0003073940310000211
Minimum distance to page
Figure BDA0003073940310000212
b. If all the sample data points included in the branch are accessed, the branch is an already-accessed branch, and the branch minimum distance minidet and the branch maximum distance MaxDist from the sample data point included in the branch to the query data point are saved.
The paging nearest neighbor query based on the cache data is divided into two cases:
1. query for a new page: let us consider that the geographical location data from page 1 to page i have been queried, now page i +1, each page containing n number of data points, n being a positive integer:
first, page i +1
Figure BDA0003073940310000213
Initialisation to infinity
1) Finding visited branches: (sinking)
1.1) setting root node as root node of current branch
1.2) if the sample data points contained in the current branch are not completely accessed, no cache information exists, if the segmentation axis coordinate value of the root node of the current branch is smaller than the segmentation axis coordinate value corresponding to the query latitude and longitude of the query data point, the left branch of a pre-constructed K-dimensional tree is entered for searching, and the root node of the current branch is updated to be the root node of the left branch; otherwise, entering a right branch of a pre-constructed K-dimensional tree for searching, and updating the root node of the current branch into the root node of the right branch;
1.3) repeat step 1.2) until an accessed branch is found and
Figure BDA0003073940310000221
or to a leaf node.
2. Recursive search page i + 1: (backtracking)
2.1) creating an empty candidate set S containing sample data points for page i +1
2.2) for the current branch:
2.2.1) if all the sample data points contained in the current branch have been visited:
2.2.1.1) if the branch is present
Figure BDA0003073940310000222
Indicating that the data points all fall in the page before the (i +1) th page, marking the branch as visited, and updating the parent node of the root node of the current branch into the root node of the current branch so as to update the current branch;
2.2.1.2) if the branch
Figure BDA0003073940310000223
Indicating that the data points contained in the branch fall outside the (i +1) th page, marking the branch as visited, and updating the parent node of the root node of the current branch into the root node of the current branch so as to update the current branch;
2.2.1.3) if the distance span of the branch [ MinDist, MaxdIst]And interval
Figure BDA0003073940310000224
If there is a partial intersection or no cache information, it indicates that there must be a sample data point of the branch that falls outside the previous i page, possibly within the i +1 th page; the processing steps are the same as the recursive search step described above, and are updated
Figure BDA0003073940310000225
3. And when the root node of the KDTree is visited, finishing the searching process, wherein the sample data point of the candidate set S is the k neighbor finally searched.
(II) inquiring the searched pages: assuming that pages from 1 to i are searched, assuming that the user turns pages forward at present, the data of the jth page is to be checked (j is more than or equal to 1 and less than i), and the number of data points of each page is n:
firstly, the jth page is obtained by inquiring the cache information
Figure BDA0003073940310000231
And
Figure BDA0003073940310000232
the distance between the target point and the query point is bound to fall
Figure BDA0003073940310000233
Within the interval.
1. The method for searching for the leaf node to which the query data point belongs is the same as the method for searching for the leaf node to which the query data point belongs, and is not described herein again.
2. In the recursive search, for a branch node:
2.1) if the branch does not have cached information, the processing is the same as the recursive search described above
2.2) if the branch has cache information, it indicates that all sample data points contained in the branch have been completely accessed:
2.2.1) if the branch
Figure BDA0003073940310000234
Indicating that the sample data points all fall in the page before j, marking the branch as visited, and jumping to the parent node of the root node of the branch;
2.2.2) if the branch
Figure BDA0003073940310000235
Indicating that the sample data points all fall in the page after j, marking the branch as visited, and jumping to the parent node of the root node of the branch;
2.2.3) if the branch
Figure BDA0003073940310000236
Indicating that the sample data points all fall into the jth page, adding all sample data points of the branch into a candidate set S, marking the branch as visited, and jumping to a parent node of a root node of the branch;
2.2.4) if the branch [ MinDist, MaxdIst]And interval
Figure BDA0003073940310000237
If the parts are crossed, the sample of the branch is presentIf the data point falls in the page, entering a sub-branch, and jumping to the step 2); if it is a leaf node, all data points it contains are tested, and the distance to the query point is fallen
Figure BDA0003073940310000238
Data points within the range are added to the candidate set S.
3. If the number of sample data points in the j page candidate set reaches n, the search is ended.
And taking the sample data points in the candidate set as target data points, determining target geographic positions corresponding to the target data points, then calculating the arc length between the target data points and the query data points based on the straight-line distance, and displaying the arc length and the target geographic positions on the target page correspondingly.
Wherein calculating the arc length between the target data point and the query data point based on the linear distance may be specifically implemented by the following formula:
S=2*R*arcsin(L/2R),
wherein S is the arc length between the target data point and the query data point; l is the linear distance between the target data point and the query data point, and R is the radius of the earth.
According to the technical scheme of the embodiment, indexes are built in the memory for the data points through the KDTree, and rapid nearest neighbor searching is carried out through the KDTree during real-time query without being limited by a distance range; meanwhile, the KDTree search state is cached for each query data point, nearest neighbor search can be continued on the basis of historical search information according to paging parameters, redundancy in calculation is avoided, the number of data points to be accessed in paging query can be greatly reduced by caching a small amount of data under the condition that each page of specific data points is not stored, a candidate set is reduced, paging query efficiency is improved, and response time is prolonged; the optimization in space and time is realized.
Example four
Fig. 3 is a schematic structural diagram of a geographic location search apparatus according to a third embodiment of the present invention, where the present embodiment is applicable to a geographic location search condition, and the apparatus specifically includes: the device comprises a query request module, a data search module and a data display module.
The query request module is used for receiving a data query request of a target page sent by a target client and acquiring query longitude and latitude of a query data point corresponding to the data query request; the data search module is used for carrying out K 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; and the data display module is used for displaying the target geographic position corresponding to at least one target data point on a target page of the target client.
According to the technical scheme of the embodiment of the invention, the K neighbor search is carried out in the pre-constructed K dimensional tree, so that the technical problems that the existing search mode is low in search speed and redundant calculation is easy to generate are solved, the search quantity is not limited by a distance range, the search speed is improved, the data query request of the target client side is responded more quickly, and the user experience is improved.
On the basis of any optional technical solution in the embodiment of the present invention, optionally, the data search module includes: the device comprises a branch determining unit, an access judging unit, a coordinate judging unit, a left branch searching unit, a right branch searching unit, a branch distance acquiring unit and a branch distance searching unit.
The branch determining unit is used for determining the current branch by taking the root node as the root node of the current branch; the access judging unit is used for judging whether all sample data points contained in the current branch are accessed; the coordinate judgment unit is used for judging whether the segmentation axis coordinate value of the root node is smaller than the segmentation axis coordinate value corresponding to the query longitude and latitude of the query data point or not if all the sample data points contained in the current branch are not visited; the left branch searching unit is used for entering a left branch of a pre-constructed K-dimensional tree for searching if the current branch is the left branch, and updating the root node of the current branch into the root node of the left branch; the right branch searching unit is used for entering a right branch of a pre-constructed K-dimensional tree for searching if the current branch is not the right branch, and updating the root node of the current branch into the root node of the right branch; a branch distance obtaining unit, configured to obtain a maximum branch distance and a minimum branch distance between the sample data point 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 visited; and the branch distance searching unit is used for carrying out K neighbor searching in a pre-constructed K-dimensional tree based on the maximum branch distance and the minimum branch distance.
On the basis of any optional technical solution in the embodiment of the present invention, optionally, the branch distance search unit may be configured to:
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, determining a branch to be searched in a 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 performing K neighbor search in the K-dimensional tree based on the branch to be searched.
On the basis of any optional technical solution in the embodiment of the present invention, optionally, the branch distance search unit may be specifically configured to:
if the maximum branch distance of the current branch is smaller 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 be the root node of the current branch so as to update the current branch;
and returning to execute the operation of judging whether all the sample data points contained in the current branch are accessed.
On the basis of any optional technical solution in the embodiment of the present invention, optionally, the branch distance search unit may be specifically configured to:
determining whether an intersection exists between a first distance interval formed by the minimum distance of the branch of the current branch and the maximum distance of the branch and a second distance interval formed by the maximum distance of the page of the adjacent page and the maximum distance of the page of the target page;
and if the first distance interval and the second distance interval have intersection, using the current branch as a branch to be searched in a pre-constructed K-dimensional tree.
On the basis of any optional technical solution in the embodiment of the present invention, optionally, the branch distance search unit may be configured to:
and if the cache information comprises the maximum page distance and the minimum page distance of the target page, performing K neighbor search in a 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.
On the basis of any optional technical solution in the embodiment of the present invention, optionally, the branch distance search unit may be configured to:
if the maximum branch distance of the current branch is smaller than the minimum page distance of the target page, or the minimum branch distance of the current branch is larger 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 be the root node of the current branch so as to update the current branch;
and returning to execute the operation of judging whether all the sample data points contained in the current branch are accessed.
On the basis of any optional technical solution in the embodiment of the present invention, optionally, the branch distance search unit may be configured to:
if the minimum distance of the target page is less than or equal to the branch minimum distance of the current branch and the maximum distance of the current branch is less than the page maximum distance of the target page, adding the contained sample data point of the current branch into a candidate set, 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 so as to update the current branch;
and returning to execute the operation of judging whether all the sample data points contained in the current branch are accessed.
On the basis of any optional technical solution in the embodiment of the present invention, optionally, the branch distance search unit may be configured to:
determining whether an intersection exists between a third distance interval formed by the minimum distance of the branch of the current branch and the maximum distance of the branch and a fourth distance interval formed by the maximum distance of the page of the target page and the maximum distance of the page of the target page;
if the third distance interval and the fourth distance interval have intersection, judging whether the root node of the current branch is a leaf node;
if so, adding sample data points, of the sample data points corresponding to the leaf nodes, of which the distances to the query data points are within the range of the minimum page distance and the maximum page distance of the target page into the candidate set;
and when the number of the sample data points in the candidate set reaches a preset threshold value, taking the sample data points in the candidate set as target data points corresponding to the query data points.
On the basis of any optional technical solution in the embodiment of the present invention, optionally, the data search module is configured to:
and converting the inquiry longitude and latitude into an inquiry point coordinate of a space rectangular coordinate system, and carrying out K neighbor search in a pre-constructed K-dimensional tree based on the inquiry point coordinate.
On the basis of any optional technical solution in the embodiment of the present invention, optionally, the data search module may be specifically configured to:
converting the query longitude and latitude into a query point coordinate of a space rectangular coordinate system based on the following formula:
lon=lon/180*π
lat=lat/180*π
x=R*cos(lat)*cos(lon)
y=R*cos(lat)*sin(lon)
z=R*sin(lat)
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; pi is the circumference ratio; x represents the horizontal axis coordinate of the query data point in a space rectangular coordinate system; y represents the longitudinal axis coordinate of the query data point in a space rectangular coordinate system; z represents the vertical axis coordinate of the query data point in the rectangular spatial coordinate system.
On the basis of any optional technical solution in the embodiment of the present invention, optionally, the data search module may be further configured to:
determining a segmentation axis coordinate value corresponding to a segmentation axis dimension corresponding to each node in a pre-constructed K-dimensional tree in the query point coordinates;
and performing K neighbor search in a pre-constructed K dimensional tree based on the segmentation axis coordinate value.
On the basis of any optional technical solution in the embodiment of the present invention, optionally, the method for searching for a geographic location further includes:
the distance display module is used for calculating the linear distance between each target data point and the query data point after K neighbor search is carried out in a 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;
and 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 data point on the target page.
On the basis of any optional technical solution in the embodiment of the present invention, optionally, the distance display module is configured to:
calculating a linear distance between each of the target data points and the query data point based on the following formula:
Figure BDA0003073940310000291
wherein L represents a linear distance between a target data point and the query data point; x is the number of1Coordinates of the horizontal axis representing the target data point; y is1A vertical axis coordinate representing a target data point; z is a radical of1Vertical axis coordinates representing a target data point; x is the number of2Coordinates of the horizontal axis representing the query data points; y is2A vertical axis coordinate representing the query data point; z is a radical of2Representing the vertical axis coordinates of the query data point.
On the basis of any optional technical solution in the embodiment of the present invention, optionally, the search apparatus for a geographic location further includes a building module of the K-dimensional tree, where the building module of the K-dimensional tree specifically may include:
the data longitude and latitude acquisition unit is used for acquiring the data longitude and latitude of each acquired sample data point;
the data point coordinate conversion unit is used for converting the longitude and latitude of the data into a data point coordinate of a space rectangular coordinate system;
and the K-dimensional tree construction unit is used for constructing the K-dimensional tree based on the data point coordinates of each sample data point in a sample data set, wherein the sample data set comprises a plurality of sample data points.
On the basis of any optional technical solution in the embodiment of the present invention, optionally, the K-dimensional tree building unit is configured to:
a segmentation axis dimension determination subunit configured to determine a current segmentation axis dimension of the K-dimensional tree based on the data point coordinates of a plurality of sample data points in a sample data set;
and the left and right branch constructing subunit is used for respectively constructing a left branch and a right branch of the K-dimensional tree based on the current segmentation axis dimension and the sample data point.
On the basis of any optional technical solution in the embodiment of the present invention, optionally, the split axis dimension determination subunit is configured to:
and performing variance calculation on data of each dimension in the data point coordinates of a plurality of sample data points in the sample data set, and taking the dimension corresponding to the maximum variance as the current segmentation axis dimension of the K-dimensional tree.
On the basis of any optional technical solution in the embodiment of the present invention, optionally, the left and right branch construction subunits are configured to:
retrieving the sample data set based on the current segmentation axis dimension to obtain median data of the current segmentation axis dimension, and taking the median data as current node data;
and respectively constructing a left branch and a right branch of the K-dimensional tree based on the current segmentation axis dimension, the current node data and the sample data points which are not constructed on the K-dimensional tree in the sample data set.
On the basis of any optional technical solution in the embodiment of the present invention, optionally, the left and right branch building subunits may be specifically configured to:
and dividing all sample data points smaller than the current node data into the left branch of the K-dimensional tree and dividing all sample data points larger than or equal to the current node data into the right branch of the K-dimensional tree based on the current segmentation axis dimension.
On the basis of any optional technical solution in the embodiment of the present invention, optionally, the K-dimensional tree building subunit may be specifically configured to:
and if the number of the sample data points which are not constructed on the K-dimensional tree in the sample data set is smaller than a preset number threshold, taking the current node data as leaf node data of the K-dimensional tree.
The searching device for the geographical position can execute the searching method for the geographical position provided by any embodiment of the invention, and has the corresponding functional modules and beneficial effects of executing the searching method for the geographical position.
EXAMPLE five
Fig. 4 is a schematic structural diagram of an electronic device according to a sixth embodiment of the present invention. FIG. 4 illustrates a block diagram of an exemplary electronic device 12 suitable for use in implementing embodiments of the present invention. The electronic device 12 shown in fig. 4 is only an example and should not bring any limitation to the function and the scope of use of the embodiment of the present invention.
As shown in FIG. 4, electronic device 12 is embodied in the form of a general purpose computing device. The components of 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 that couples various system components including the system memory 28 and the processing unit 16.
Bus 18 represents one or more of any of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, and a processor or local bus using any of a variety of bus architectures. By way of example, such 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.
Electronic device 12 typically includes a variety of computer system readable media. Such media may be any available media that is accessible by electronic device 12 and includes both volatile and nonvolatile media, removable and non-removable media.
The 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/nonvolatile computer system storage media. By way of example only, storage system 34 may be used to read from and write to non-removable, nonvolatile magnetic media (not shown in FIG. 4, and commonly referred to as a "hard drive"). Although not shown in FIG. 4, a magnetic disk drive for reading from and writing to a removable, nonvolatile magnetic disk (e.g., a "floppy disk") and an optical disk drive for reading from or writing to a removable, nonvolatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 18 by 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 carry out the functions of embodiments of the invention.
A program/utility 40 having a set (at least one) of program modules 42 may be stored, for example, in system memory 28, such program modules 42 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which examples or some combination thereof may comprise an implementation of a network environment. Program modules 42 generally carry out the functions and/or methodologies of the described embodiments of the invention.
Electronic device 12 may also communicate with one or more external devices 14 (e.g., keyboard, pointing device, display 24, etc.), with one or more devices that enable a user to interact with electronic device 12, and/or with any devices (e.g., network card, modem, etc.) that enable electronic device 12 to communicate with one or more other computing devices. Such communication may be through an input/output (I/O) interface 22. Also, the electronic device 12 may communicate with one or more networks (e.g., a Local Area Network (LAN), a Wide Area Network (WAN), and/or a public network, such as the Internet) via the network adapter 20. As shown in FIG. 4, the network adapter 20 communicates with the other modules of the electronic device 12 via the bus 18. It should be appreciated that although not shown in FIG. 4, other hardware and/or software modules may be used in conjunction with 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, among others.
The processing unit 16 executes various functional applications and data processing by executing programs stored in the system memory 28, for example, implementing a geographic location search method provided by the present embodiment.
EXAMPLE six
An embodiment of the present invention further provides a storage medium containing computer-executable instructions, which when executed by a computer processor, perform a method for searching for a geographic location, the method including:
receiving a data query request of a target page sent by a target client, and acquiring query longitude and latitude of a query data point corresponding to the data query request;
performing K 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;
and displaying the target geographic position corresponding to at least one target data point on a target page of the target client.
Computer storage media for embodiments of the invention may employ 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. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
A computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations for embodiments of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the 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 the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims (23)

1. A method for searching geographic position is characterized by comprising the following steps:
receiving a data query request of a target page sent by a target client, and acquiring query longitude and latitude of a query data point corresponding to the data query request;
performing K 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;
and displaying the target geographic position corresponding to at least one target data point on a target page of the target client.
2. The method of claim 1, wherein performing a K-nearest neighbor search in a pre-constructed K-dimensional tree based on the query latitude and longitude comprises:
taking the root node as the root node of the current branch to determine the current branch;
judging whether all sample data points contained in the current branch are accessed;
if the sample data points contained in the current branch are not completely accessed, judging whether the segmentation axis coordinate value of the root node is smaller than the segmentation axis coordinate value corresponding to the query longitude and latitude of the query data point;
if yes, entering a left branch of a pre-constructed K-dimensional tree for searching, and updating the root node of the current branch into the root node of the left branch;
if not, entering a right branch of a pre-constructed K-dimensional tree for searching, and updating the root node of the current branch into the root node of the right branch;
if all sample data points contained in the current branch are accessed, acquiring the maximum branch distance and the minimum branch distance between the sample data points contained in the current branch contained in the cache information and the query data point;
and performing K neighbor search in a pre-constructed K-dimensional tree based on the maximum branch distance and the minimum branch distance.
3. The method of claim 2, wherein performing a K neighbor search in a pre-constructed K-dimensional tree based on the branch maximum distance and the branch minimum distance comprises:
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, determining a branch to be searched in a 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 performing K neighbor search in the K-dimensional tree based on the branch to be searched.
4. The method of claim 3, wherein the 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 branch distance and the maximum branch distance of the current branch comprises:
if the maximum branch distance of the current branch is smaller 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 be the root node of the current branch so as to update the current branch;
and returning to execute the operation of judging whether all the sample data points contained in the current branch are accessed.
5. The method of claim 3, wherein the 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 branch distance and the maximum branch distance of the current branch comprises:
determining whether an intersection exists between a first distance interval formed by the minimum distance of the branch of the current branch and the maximum distance of the branch and a second distance interval formed by the maximum distance of the page of the adjacent page and the maximum distance of the page of the target page;
and if the first distance interval and the second distance interval have intersection, using the current branch as a branch to be searched in a pre-constructed K-dimensional tree.
6. The method of claim 2, wherein performing a K neighbor search in a pre-constructed K-dimensional tree based on the branch maximum distance and/or the branch minimum distance comprises:
and if the cache information comprises the maximum page distance and the minimum page distance of the target page, performing K neighbor search in a 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.
7. The method of claim 6, wherein performing a K neighbor search in a K-dimensional tree based on the page minimum distance and the page maximum distance of the target page and the branch minimum distance and the branch maximum distance of the current branch comprises:
if the maximum branch distance of the current branch is smaller than the minimum page distance of the target page, or the minimum branch distance of the current branch is larger 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 be the root node of the current branch so as to update the current branch;
and returning to execute the operation of judging whether all the sample data points contained in the current branch are accessed.
8. The method of claim 6, wherein performing a K neighbor search in a K-dimensional tree based on the page minimum distance and the page maximum distance of the target page and the branch minimum distance and the branch maximum distance of the current branch comprises:
if the minimum distance of the target page is less than or equal to the branch minimum distance of the current branch and the maximum distance of the current branch is less than the page maximum distance of the target page, adding the contained sample data point of the current branch into a candidate set, 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 so as to update the current branch;
and returning to execute the operation of judging whether all the sample data points contained in the current branch are accessed.
9. The method of claim 6, wherein performing a K neighbor search in a K-dimensional tree based on the page minimum distance and the page maximum distance of the target page and the branch minimum distance and the branch maximum distance of the current branch comprises:
determining whether an intersection exists between a third distance interval formed by the minimum distance of the branch of the current branch and the maximum distance of the branch and a fourth distance interval formed by the maximum distance of the page of the target page and the maximum distance of the page of the target page;
if the third distance interval and the fourth distance interval have intersection, judging whether the root node of the current branch is a leaf node;
if so, adding sample data points, of the sample data points corresponding to the leaf nodes, of which the distances to the query data points are within the range of the minimum page distance and the maximum page distance of the target page into the candidate set;
and when the number of the sample data points in the candidate set reaches a preset threshold value, taking the sample data points in the candidate set as target data points corresponding to the query data points.
10. The method of claim 1, wherein performing a K-nearest neighbor search in a pre-constructed K-dimensional tree based on the query latitude and longitude comprises:
and converting the inquiry longitude and latitude into an inquiry point coordinate of a space rectangular coordinate system, and carrying out K neighbor search in a pre-constructed K-dimensional tree based on the inquiry point coordinate.
11. The method of claim 10, wherein converting the query latitude and longitude into query point coordinates of a spatial rectangular coordinate system comprises:
converting the query longitude and latitude into a query point coordinate of a space rectangular coordinate system based on the following formula:
lon=lon/180*π
lat=lat/180*π
x=R*cos(lat)*cos(lon)
y=R*cos(lat)*sin(lon)
z=R*sin(lat)
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; pi is the circumference ratio; x represents the horizontal axis coordinate of the query data point in a space rectangular coordinate system; y represents the longitudinal axis coordinate of the query data point in a space rectangular coordinate system; z represents the vertical axis coordinate of the query data point in the rectangular spatial coordinate system.
12. The method of claim 10, wherein performing a K-neighbor search in a pre-constructed K-dimensional tree based on the query point coordinates comprises:
determining a segmentation axis coordinate value corresponding to a segmentation axis dimension corresponding to each node in a pre-constructed K-dimensional tree in the query point coordinates;
and performing K neighbor search in a pre-constructed K dimensional tree based on the segmentation axis coordinate value.
13. The method of claim 10, further comprising, after said performing a K-nearest neighbor search in a pre-constructed K-dimensional tree based on said query point coordinates, resulting in at least one target data point corresponding to said query data point:
calculating a linear distance between each target data point and the query data point;
and 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 geographic position on the target page.
14. The method of claim 13, wherein said calculating a linear distance between each of said target data points and said query data point comprises:
calculating a linear distance between each of the target data points and the query data point based on the following formula:
Figure FDA0003073940300000061
wherein L represents a linear distance between a target data point and the query data point; x is the number of1Coordinates of the horizontal axis representing the target data point; y is1A vertical axis coordinate representing a target data point; z is a radical of1Vertical axis coordinates representing a target data point; x is the number of2Coordinates of the horizontal axis representing the query data points; y is2A vertical axis coordinate representing the query data point; z is a radical of2Representing the vertical axis coordinates of the query data point.
15. The method of claim 10, wherein the K-dimensional tree is constructed by:
acquiring data longitude and latitude of each acquired sample data point;
converting the longitude and latitude of the data into a data point coordinate of a space rectangular coordinate system;
constructing the K-dimensional tree based on the data point coordinates of each sample data point in a sample data set, wherein the sample data set contains a plurality of sample data points.
16. The method of claim 15, wherein constructing the K-dimensional tree based on the data point coordinates of each sample data point in the sample dataset comprises:
determining a current segmentation axis dimension of the K-dimensional tree based on the data point coordinates of a plurality of sample data points in a sample dataset;
constructing a left branch and a right branch of the K-dimensional tree, respectively, based on the current segmentation axis dimension and the sample data points.
17. The method of claim 16, wherein said determining a current segmentation axis dimension of the K-dimensional tree based on the data point coordinates of a plurality of sample data points in a sample data set comprises:
and performing variance calculation on data of each dimension in the data point coordinates of a plurality of sample data points in the sample data set, and taking the dimension corresponding to the maximum variance as the current segmentation axis dimension of the K-dimensional tree.
18. The method of claim 17, wherein determining a left branch and a right branch of the K-dimensional tree based on the current segmentation axis dimension and the sample data point, respectively, comprises:
retrieving the sample data set based on the current segmentation axis dimension to obtain median data of the current segmentation axis dimension, and taking the median data as current node data;
and respectively constructing a left branch and a right branch of the K-dimensional tree based on the current segmentation axis dimension, the current node data and the sample data points which are not constructed on the K-dimensional tree in the sample data set.
19. The method of claim 18, wherein constructing left and right branches of the K-dimensional tree based on the current split axis dimension, the current node data, and sample data points in the sample data set that are not constructed on the K-dimensional tree comprises:
and dividing all sample data points smaller than the current node data into the left branch of the K-dimensional tree and dividing all sample data points larger than or equal to the current node data into the right branch of the K-dimensional tree based on the current segmentation axis dimension.
20. The method of claim 15, wherein constructing the K-dimensional tree based on the data point coordinates of each sample data point in the sample dataset comprises:
and if the number of the sample data points which are not constructed on the K-dimensional tree in the sample data set is smaller than a preset number threshold, taking the current node data as leaf node data of the K-dimensional tree.
21. An apparatus for searching geographical locations, comprising:
the query request module is used for receiving a data query request of a target page sent by a target client and acquiring query longitude and latitude of a query data point corresponding to the data query request;
the data search module is used for carrying out K 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;
and the data display module is used for displaying the target geographic position corresponding to at least one target data point on a target page of the target client.
22. An electronic device, characterized in that the electronic device comprises:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement a method of searching for a geographic location as recited in any of claims 1-20.
23. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out a method of searching for a geographical location according to any one of claims 1-20.
CN202110546700.0A 2021-05-19 2021-05-19 Geographic position searching method and device, electronic equipment and storage medium Pending CN113139032A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110546700.0A CN113139032A (en) 2021-05-19 2021-05-19 Geographic position searching method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110546700.0A CN113139032A (en) 2021-05-19 2021-05-19 Geographic position searching method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN113139032A true CN113139032A (en) 2021-07-20

Family

ID=76818071

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110546700.0A Pending CN113139032A (en) 2021-05-19 2021-05-19 Geographic position searching method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN113139032A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115630203A (en) * 2022-12-12 2023-01-20 杭州数梦工场科技有限公司 Method for generating n-ary tree and method and device for determining intersection relation

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115630203A (en) * 2022-12-12 2023-01-20 杭州数梦工场科技有限公司 Method for generating n-ary tree and method and device for determining intersection relation

Similar Documents

Publication Publication Date Title
CN109165215B (en) Method and device for constructing space-time index in cloud environment and electronic equipment
US9880012B2 (en) Hybrid road network and grid based spatial-temporal indexing under missing road links
CN102693266B (en) Search for method, the navigation equipment and method of generation index structure of database
CN113434623B (en) Fusion method based on multi-source heterogeneous space planning data
CN109033314B (en) Real-time query method and system for large-scale knowledge graph under condition of limited memory
CN110263117B (en) Method and device for determining POI (Point of interest) data
CN101493329A (en) Multiple target point path planning method and device
CN107886717B (en) Parking guidance method and device, computing equipment and storage medium
US9910878B2 (en) Methods for processing within-distance queries
JP2023530795A (en) Geolocation zone encoding method, method for establishing encoding model, and apparatus
CN103077201A (en) Estimation method for unknown position based on internet initiative iteration detection
CN110555432B (en) Method, device, equipment and medium for processing interest points
CN113535788A (en) Retrieval method, system, equipment and medium for marine environment data
US6865479B2 (en) Programmatically calculating paths from a spatially-enabled database
CN113139032A (en) Geographic position searching method and device, electronic equipment and storage medium
Abbasifard et al. Efficient indexing for past and current position of moving objects on road networks
Cho et al. A basis of spatial big data analysis with map-matching system
CN114201480A (en) Multi-source POI fusion method and device based on NLP technology and readable storage medium
CN107590260B (en) Point cloud data real-time retrieval method and system
CN113642313A (en) Address text processing method, device, equipment, storage medium and program product
CN114138925A (en) Location point belonging area retrieval method, device, electronic equipment, medium and product
CN112861023A (en) Map information processing method, map information processing apparatus, map information processing device, storage medium, and program product
CN111797183A (en) Method and device for mining road attribute of information point and electronic equipment
US20240184809A1 (en) Reverse geocoding apparatus, reverse geocoding method, and program
Arzubov et al. Concept of Server-side Clusterization of Semi-Static Big Geodata for Web Maps

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination