WO2021068346A1 - 基于Geohash算法的位置查询方法、装置、计算机设备及存储介质 - Google Patents

基于Geohash算法的位置查询方法、装置、计算机设备及存储介质 Download PDF

Info

Publication number
WO2021068346A1
WO2021068346A1 PCT/CN2019/118264 CN2019118264W WO2021068346A1 WO 2021068346 A1 WO2021068346 A1 WO 2021068346A1 CN 2019118264 W CN2019118264 W CN 2019118264W WO 2021068346 A1 WO2021068346 A1 WO 2021068346A1
Authority
WO
WIPO (PCT)
Prior art keywords
query
location
data set
points
location point
Prior art date
Application number
PCT/CN2019/118264
Other languages
English (en)
French (fr)
Inventor
陈润红
沈兵林
Original Assignee
平安科技(深圳)有限公司
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 平安科技(深圳)有限公司 filed Critical 平安科技(深圳)有限公司
Publication of WO2021068346A1 publication Critical patent/WO2021068346A1/zh

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/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
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Definitions

  • This application relates to the field of data processing technology, and in particular to a location query method, device, computer equipment, and storage medium based on the Geohash algorithm.
  • LBS location-based services
  • spatial query is widely used in the field of LBS
  • spatial index is used to effectively support spatial query
  • spatial index refers to a data structure arranged in a certain order according to the position and shape of spatial objects or a certain spatial relationship between spatial objects , Which is used to filter and exclude a large number of geographic objects that have nothing to do with specific spatial operations, thereby reducing the scope of spatial operations.
  • the research on the structure of spatial index is mostly focused on the structure of R-Tree and its variants and the structure based on the space filling curve.
  • the R-Tree variant is to optimize the R-Tree multi-path query problem, but the retrieval efficiency is still restricted by it. When the query range is small, it is especially obvious, and the user experience is poor.
  • the embodiments of the present application provide a location query method, device, computer equipment, and storage medium based on the Geohash algorithm, aiming to solve the problems of low query efficiency, slow response speed, and poor user experience of the existing spatial index structure.
  • an embodiment of the present application provides a location query method based on the Geohash algorithm, which includes: if a query command is received, determining whether the query range distance of the query command is greater than a preset threshold, wherein the query command Including the query location point and the query range distance; if the query range distance of the query instruction is not greater than the preset threshold, the extended dictionary tree constructed in advance based on the Geohash algorithm is used to query the location points in the query domain and return the queried target Location point; if the query range distance of the query instruction is greater than the preset threshold, the R tree pre-built based on the Z-curve sequence is used to query the location point in the query domain and return the queried target location point.
  • an embodiment of the present application also provides a location query device based on the Geohash algorithm, which includes: a determining unit, configured to determine whether the query range distance of the query command is greater than a preset threshold if a query command is received, Wherein, the query instruction includes a query location point and a query range distance; the first query unit is configured to, if the query range distance of the query instruction is not greater than a preset threshold, use an extended dictionary tree constructed in advance based on the Geohash algorithm to query Query the location points in the domain and return the queried target location points; the second query unit is used for querying if the query range distance of the query instruction is greater than a preset threshold value, using an R-tree constructed in advance based on the Z-curve sequence Query the location point in the domain and return the target location point that was queried.
  • an embodiment of the present application also provides a computer device, which includes a memory and a processor connected to the memory; the memory is used to store a computer program; the processor is used to run the A computer program to execute the following steps: if a query command is received, it is determined whether the query range distance of the query command is greater than a preset threshold, wherein the query command includes a query location point and a query range distance; if the query command is If the query range distance is not greater than the preset threshold, the expanded dictionary tree constructed in advance based on the Geohash algorithm is used to query the location points in the query domain and return the queried target location points; if the query range distance of the query instruction is greater than the preset Threshold, the pre-built R tree based on the Z-curve sequence is used to query the location points in the query domain and return the queried target location points.
  • the embodiments of the present application also provide a computer-readable storage medium, the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor executes the following steps: Upon receiving the query instruction, it is determined whether the query range distance of the query instruction is greater than the preset threshold, wherein the query instruction includes the query location point and the query range distance; if the query range distance of the query instruction is not greater than the preset threshold, Then an expanded dictionary tree constructed in advance based on the Geohash algorithm is used to query the location points in the query domain and return the queried target location points; if the query range distance of the query instruction is greater than the preset threshold, the pre-order based on the Z curve is used The constructed R-tree queries the location points in the query domain and returns the queried target location points.
  • FIG. 1 is a schematic diagram of a sub-flow of a location query method based on the Geohash algorithm provided by an embodiment of the application;
  • FIG. 2 is a schematic diagram of a sub-flow of a location query method based on the Geohash algorithm provided by an embodiment of the application;
  • Figure 3 is the Geohash accuracy table
  • Figure 4 shows the Base32 coding table
  • FIG. 5 is a schematic diagram of a sub-flow of a location query method based on the Geohash algorithm provided by an embodiment of the application;
  • FIG. 6 is a schematic diagram of a sub-flow of a location query method based on the Geohash algorithm provided by an embodiment of the application;
  • FIG. 7 is a schematic flowchart of a location query method based on the Geohash algorithm provided by an embodiment of the application.
  • FIG. 8 is a schematic diagram of a sub-process of a location query method based on the Geohash algorithm provided by an embodiment of the application;
  • FIG. 9 is a schematic diagram of a sub-flow of a location query method based on the Geohash algorithm provided by an embodiment of the application.
  • FIG. 10 is a schematic block diagram of a location query device based on Geohash algorithm provided by an embodiment of the application.
  • FIG. 11 is a schematic block diagram of a location query device based on the Geohash algorithm according to another embodiment of the application.
  • FIG. 12 is a schematic block diagram of a location query device based on Geohash algorithm according to another embodiment of this application.
  • FIG. 13 is a schematic block diagram of specific units of a location query device based on the Geohash algorithm provided by an embodiment of the application;
  • FIG. 14 is a schematic block diagram of a verification unit of a location query device based on the Geohash algorithm provided by an embodiment of the application.
  • FIG. 15 is a schematic block diagram of a computer device provided by an embodiment of the application.
  • This application uses a pre-built extended dictionary tree and an R tree based on the Geohash algorithm and the Z-curve order to implement the location query.
  • a query instruction When a query instruction is received, first determine whether the query range distance is greater than the preset threshold. When the query range distance is not greater than the preset threshold, the extended dictionary tree is used for query; when the query range distance is greater than the preset threshold, the R tree is used for query.
  • Query can achieve efficient support for queries in any spatial range, adaptively select a suitable index structure, quickly respond to queries, improve user experience, and achieve high system resource utilization.
  • the step of pre-building an extended dictionary tree based on the Geohash algorithm includes the following steps: S101-S102.
  • S101 Encode all position points in the preset data set according to the Geohash algorithm to obtain corresponding character strings, and sort and number the position points in lexicographic order according to the character strings to obtain a first data set, where
  • the first data set includes position points, character strings, and numbers.
  • Geohash is a kind of geocoding, its essence is to map a multi-dimensional spatial target into a one-dimensional target, and then realize the spatial query based on the one-dimensional index structure.
  • the preset data set refers to a collection composed of multiple location points, which are composed of longitude and latitude.
  • the location points in the preset data set are encoded into a string of preset lengths by the Geohash algorithm, and then the location points are sorted and numbered in lexicographic order according to the string String to obtain the first data set.
  • each row of data is composed of serial number ID, latitude, longitude, and character string.
  • the step S101 may include steps: S1011-S1014.
  • the preset code length refers to the length of the position point converted into binary code.
  • the preset code length is determined according to the Geohash accuracy table according to the actual situation. When the preset length is 8, it means that the size is about 20 meters. The area range can meet the minimum query requirements under normal circumstances. Therefore, in this solution, the default length is designated as 8, and the number of position points obtained is 40, which is the default code length, where the latitude is 20 and the longitude is 20. Is 20.
  • the Geohash accuracy table is shown in Figure 3. Specifically, the latitude interval of the earth is [-90,90] and the longitude interval is [-180,180]. The latitude and longitude of the location point are divided into two using the dichotomy method.
  • the latitude interval is divided into [-90,0] and [0, 90], [-90,0] is the left interval, [0,90] is the right interval, similarly the longitude interval is divided into [-180,0] and [0,180], [-180,0] is the left interval, [ 0,180] is the right interval, the latitude or longitude of the location point falls in the left interval, and it is coded as 0, and the right interval is coded as 1.
  • the recursive process continues to divide the latitude and longitude intervals and code according to the longitude and latitude of the location point until it is obtained
  • the length of the longitude bit string and the latitude bit string are 20 respectively.
  • the longitude bit string and the latitude bit string are combined to obtain a position point string, thereby mapping the two-dimensional position point into a one-dimensional bit string.
  • the longitude bit string and the latitude bit string are combined according to the rule that the odd digits are latitude and the even digits are longitude.
  • the latitude bit string is 10011011110111101101 and the longitude bit string is 00111001011100011010. If the even digit is longitude, the first digit of the position string is the first digit 0 of the longitude string.
  • the position is The second digit of the string is the first digit 1 of the latitude string; the third digit of the location point string is the second digit 0 of the longitude string, and the fourth digit of the location point string is the second digit of the latitude string. Bit number 0; and so on to get the combined position point string 0100101111000111011110110101011011001.
  • S1013 Encode the position point string according to the character encoding rule to obtain a corresponding character string.
  • the character encoding rule refers to Base32, which is a data encoding mechanism, which is mainly used to encode binary data into a string.
  • the encoding rule is: given a binary data arbitrarily, with 5 bits ( bit) is a group of segmentation, and each segmented group is encoded to obtain 1 character.
  • the position string obtained by combining is encoded by Base32 to obtain the corresponding character string.
  • the position point string 0100101111000111011110110101011011001 is divided into 5 bits as a group of 01001, 01111, 00011, 10111, 10110, 10101, 10110, and 11001.
  • the Base32 encoding table is shown in Figure 4.
  • all the position points are sorted in lexicographic order, which is a method of arranging character strings in alphabetical order.
  • lexicographic order is a method of arranging character strings in alphabetical order.
  • 9g3rqpqt and 9g3rw04d are sorted before 9g3rqpqt, and the position corresponding to 9g3rw04d is sorted before the position corresponding to 9g3rqpqt.
  • the position corresponding to 9g3rw04d is numbered 1, and the position corresponding to 9g3rqpqt is numbered. , Thus forming the first data set. For example, 1 19.596412-99.219501 9g3rw04d.
  • the dictionary tree (Trie tree) is a variant of the hash tree, which is used to count, sort and store a large number of strings. It can use the common prefix of the string to reduce the query time and storage space. Reduce unnecessary string comparisons to a minimum, and query efficiency is high.
  • the dictionary tree includes a root node and a leaf node. The root node does not include characters, and each node outside the root node includes a character; from the root node to a node, the characters passing through the path are connected to the string corresponding to the node; All child nodes of this node include different characters. Specifically, insert each character of the string into the node of the dictionary tree in turn. Before inserting, you need to find whether the prefix exists.
  • the dictionary tree node is expanded to obtain the extended dictionary tree (GeoExTrie). Specifically, the starting ID containing the prefix of the current node and its number are added to the nodes of the dictionary tree, so that for a larger range of spatial queries, only the path from the root to an internal node is required, without the need to access To the leaf node, thereby improving the response rate of the spatial range query.
  • the query string is 9g3r, which represents a larger spatial query range.
  • the query expands the dictionary tree. It does not need to traverse to the leaf nodes to obtain the corresponding ID. Only the r node needs to be queried. The ID and number corresponding to the r node can get all the IDs in the query domain.
  • the step of pre-constructing an R-tree based on the Z-curve sequence includes the following steps S103-S104.
  • the Z curve is a space-filling curve.
  • the generation principle of the Z curve is the theoretical basis of the Geohash algorithm.
  • Geohash essentially uses the Z-order curve for encoding, so the processing method of the Z curve is similar to that of Geohash.
  • the Z curve expresses the two-dimensional spatial location points in the form of a one-dimensional bit string, and sorts the location points in the preset data set according to the binary bit string corresponding to the location point, that is, according to the Z curve Sort the position points in the preset data set, and get the second data set after numbering; wherein, each row of data is composed of number ID, latitude, and longitude. For example, 1 19.596412-99.219501.
  • the step S103 may include steps: S1031-S1033.
  • S1031 Perform binary coding on the longitude and latitude of all the position points in the preset data set by the dichotomy according to the preset coding length to obtain the corresponding longitude bit string and latitude bit string.
  • the process of encoding all the position points in the preset data set according to the Z curve to obtain the corresponding position point string is the same as encoding all the position points in the preset data set according to the Geohash algorithm to obtain the corresponding characters
  • the stringing process is basically similar and will not be repeated here. The difference is that the Geohash algorithm also needs to encode the obtained position string to obtain the string.
  • the size of all binary position point strings is compared, where the binary position point string is the Z value, and the position points are ascended from small to large according to the binary system.
  • the bit string is sorted, and the sequence of the position point bit string is taken as the sort of the position point, and the second data set is obtained by numbering. For example, if the location point string is 1111 and 1000, then according to the size of the location code, 1000 is ranked before 1111, the location point number corresponding to 1000 is 1, and the location point number corresponding to 1111 is 2.
  • the R-tree is a balanced tree, which is a natural expansion of the B-tree in k dimensions.
  • the MBR of the spatial object is used to approximate the spatial object.
  • the R-tree is built according to the MBR, which can directly occupy a certain amount of space.
  • the range of spatial objects is indexed. Therefore, the Minimum Bounding Rectangle (MBR) is used to approximate the location points (latitude, longitude) in the second data set, and the smallest Bounding Rectangle refers to the area that exactly surrounds several location points.
  • MBR Minimum Bounding Rectangle
  • the target definition method is used to divide the space area that includes all the location points corresponding to the MBR in the second data set according to the R-tree construction rules.
  • the height of the R-tree is set to 5 and the root node layer is the first layer.
  • the space area of the MBR is divided four times. Among them, the root node stores the space area of the MBR in the second data set, the first-level child nodes of the root node store the space area after the first division, and so on, until the fourth level, and the fifth level stores the space area corresponding to the parent node Within the MBR, construct an R tree according to the above operation process.
  • FIG. 7 is a schematic flowchart of a location query method based on the Geohash algorithm according to an embodiment of the application.
  • the location query method based on the Geohash algorithm is applied to the terminal, which is executed by the terminal as the execution subject, and is executed after receiving the query command operated by the user through the terminal.
  • the method includes the following steps S110-S130.
  • the query location point refers to the location point where the user is in the query
  • the query range distance refers to a diameter distance from the query location point with the query location point as the center of the circle.
  • the preset threshold is proved by experiments. The experimental results show that when the query range is less than 1000 meters, the extended dictionary tree query response time is shorter; when the query range is greater than 1000 meters, the R-tree query response time is shorter. Therefore, the preset threshold is specifically 1000 meters. Specifically, the query distance is compared with a preset threshold. When the query distance is greater than 1000 meters, the R-tree is used for query, and when the query distance is not greater than 1000 meters, the extended dictionary tree is used for query to adaptively select the appropriate The index structure speeds up the query response speed.
  • an extended dictionary tree (GeoExTrie) is used for query.
  • the query location point is encoded into a string of selected length; then, the eight regions around the character string corresponding to the query location point are obtained.
  • Character string (Geohash code), the character string corresponding to the query location point and the character strings in the 8 areas around it are used as the query domain; the extended dictionary tree is retrieved, and the location point in the query domain is returned; then, the return is filtered according to the latitude and longitude range To obtain the candidate set; finally verify the position points in the candidate set to finally obtain the position points within the query area.
  • the selected length refers to the Geohash code length corresponding to the query range distance selected according to the Geohash accuracy table.
  • the area range distance corresponding to the Geohash code length is not less than the query range distance and is the minimum value.
  • the step S120 may include steps: S121-S124.
  • the Geohash code length p corresponding to the query range distance d is selected according to the Geohash accuracy table, and the query location point q is coded into p-bit characters through the Geohash algorithm String; where the area range distance corresponding to p is not less than d and is the minimum value.
  • the query distance d is 500 meters
  • the Geohash code length p is 6, and the area range distance corresponding to P is 610, which is greater than the query distance d and is the minimum
  • the query location point is coded by the Geohash algorithm to obtain the corresponding character string. This process is the same as the above-mentioned Geohash coding process, and will not be repeated here.
  • S122 Acquire character strings in eight areas around the character string corresponding to the query position point.
  • the surrounding eight areas specifically refer to the east, west, south and north areas, the southeast area, the northeast area, the southwest area, and the northwest area.
  • the latitude bit string and the longitude bit string corresponding to the character string of the eight surrounding areas are calculated according to the latitude bit string and the longitude bit string of the string of the query location.
  • the latitude bit string corresponding to the character string in the northern region is equal to the latitude bit string of the character string at the query location point
  • the longitude bit string corresponding to the character string in the northern region is equal to the longitude bit string of the character string at the query location point plus one.
  • the latitude bit string corresponding to the character string in the southern region is equal to the latitude bit string of the character string at the query position
  • the longitude bit string corresponding to the character string in the southern region is equal to the longitude bit string of the character string at the query position minus one.
  • the latitude bit string corresponding to the character string in the eastern region is equal to the latitude bit string of the character string of the query location point plus 1
  • the longitude bit string corresponding to the character string in the eastern region is equal to the longitude bit string of the character string of the query location point.
  • the latitude bit string corresponding to the character string in the western region is equal to the latitude bit string of the character string at the query location point minus 1
  • the longitude bit string corresponding to the character string in the eastern region is equal to the longitude bit string of the character string at the query location point.
  • the latitude bit string corresponding to the character string in the northeast area is equal to the latitude bit string of the character string at the query location point plus 1
  • the longitude bit string corresponding to the character string in the northeast area is equal to the longitude bit string of the query location point plus 1.
  • the latitude bit string corresponding to the character string in the northwest region is equal to the latitude bit string of the character string at the query location point minus 1
  • the longitude bit string corresponding to the character string in the northwest region is equal to the longitude bit string of the query location point plus one.
  • the latitude bit string corresponding to the character string in the southeast area is equal to the latitude bit string of the character string at the query location point plus 1, and the longitude bit string corresponding to the character string in the southeast area is equal to the longitude bit string of the query location point minus one.
  • the latitude bit string corresponding to the character string in the southwest region is equal to the latitude bit string of the character string at the query location point minus 1
  • the longitude bit string corresponding to the character string in the southwest region is equal to the longitude bit string of the query location point minus 1.
  • the character string of the location point is 9g3rqp
  • the corresponding latitude bit string is 100110111101111
  • the longitude bit string is 001110010111000
  • the latitude bit string corresponding to the character string in the northern region is 100110111101111
  • S123 Use the character string corresponding to the query location point and the character strings in eight areas around the character string corresponding to the query location point as a query domain to query the extended dictionary tree to obtain a location point in the query domain.
  • the dictionary tree is traversed according to the character string at the query location point and the character strings in the eight surrounding areas, the dictionary tree is searched for the same character string, and if so, the position corresponding to the character string is returned
  • the point ID is the location point in the query domain.
  • the location point in the query domain is verified to verify whether the location point in the query domain is within the query range distance. Specifically, first calculate the longitude range and latitude range of the query location point, and then filter the location points in the query domain according to the longitude range and latitude range of the query location point to obtain the candidate set, and finally perform the search on the location points in the candidate set. Verification, calculating the distance from the location point in the candidate set to the query location point, and returning the location point in the candidate set that is not greater than the query range distance.
  • the step S124 may include steps: S1241-S1244.
  • S1241 Calculate the longitude range and the latitude range of the query location point by using a preset formula according to the query location point and the query range distance.
  • the longitude range and the latitude range are calculated through a preset formula according to the query location point and the query range distance.
  • the preset formula is as follows:
  • lat represents the latitude value of the query location point
  • lon represents the longitude value of the query location point
  • d is the query range distance
  • range and lngR are variables
  • (minLat, maxLat) represents the latitude range
  • (minLng, maxLng) represents the longitude range
  • the query location point (19.596412-99.219501) and the query distance range 500m according to the above formula
  • the longitude range is [19.591917,19.600907]
  • the latitude range is [-99.224272,-99.214730].
  • the latitude and longitude corresponding to ID 1 is (19.600038-99.22491), 19.600038 is located in [19.591917,19.600907], and -99.22491 is not located in [-99.224272,-99.214730], so the ID is 1 Location point. Only if the longitude and latitude values of the location point fall within the longitude and latitude ranges, the location point is retained, so that the location points that are not within the latitude and longitude range are filtered out, and the candidate set is finally obtained.
  • the distance from the location point in the candidate set to the query location point is calculated according to a preset formula, where the preset formula is as follows:
  • A(x 1 , y 1 ) is the location point in the candidate set
  • B(x 2 , y 2 ) is the query location point
  • is the distance from the location point in the candidate set to the query location point.
  • (19.59918, -99.21667) is a location point in the candidate set
  • the query range distance is 500 meters.
  • the location point satisfies the spatial range query condition, and the location point is returned as a location point within the query area.
  • the R-tree is used for query.
  • the latitude range and longitude range of the query location point are determined according to the query location point and the query range distance.
  • the calculation method is the same as the above steps, and will not be repeated here.
  • the location point at the distance of the query range is the target location point.
  • the verification process is the same as the foregoing verification process, and will not be repeated here.
  • This embodiment of the application shows a location query method based on the Geohash algorithm. If a query command is received, it is determined whether the query range distance of the query command is greater than a preset threshold, wherein the query command includes a query location point and a query Range distance; if the query range distance of the query instruction is not greater than the preset threshold, an extended dictionary tree constructed in advance based on the Geohash algorithm is used to query the location points in the query domain and return the queried target location points; if said If the query range distance of the query command is greater than the preset threshold, the R-tree pre-built based on the Z-curve sequence is used to query the location points in the query domain and return the queried target location points, which can achieve efficient support for arbitrary spatial range queries. Select the appropriate index structure adaptively, quickly respond to queries, improve user experience, and have the effect of high system resource utilization.
  • FIG. 10 is a schematic block diagram of a location query device 200 based on the Geohash algorithm provided by an embodiment of the present application.
  • the present application also provides a location query device 200 based on the Geohash algorithm.
  • the location query device 200 based on the Geohash algorithm includes a unit for executing the location query method based on the Geohash algorithm.
  • the device can be configured in a desktop computer, a tablet computer, a laptop computer, and other terminals.
  • the location query device 200 based on the Geohash algorithm includes: a judgment unit 210, a first query unit 220, and a second query unit 230.
  • the location query device 200 based on the Geohash algorithm further includes: a first data set unit 201 and a first construction unit 202.
  • the first data set unit 201 is configured to encode all position points in the preset data set according to the Geohash algorithm to obtain corresponding character strings, and to sort and number the position points in lexicographic order according to the character strings to obtain the first A data set, wherein the first data set includes a location point, a character string, and a serial number.
  • the first data set unit 201 includes: a first dichotomy unit 2011, a first merging unit 2012, a first encoding unit 2013, and a first sorting unit 2014.
  • the first dichotomy unit 2011 is configured to perform binary encoding on the longitude and latitude of all position points in the preset data set by dichotomy according to the preset encoding length to obtain the corresponding longitude bit string and latitude bit string.
  • the first merging unit 2012 is configured to merge the longitude bit string and the latitude bit string according to the rule that the odd digits are latitude and the even digits are longitude to obtain a corresponding position point string.
  • the first encoding unit 2013 is configured to encode the position point string according to character encoding rules to obtain a corresponding character string.
  • the first sorting unit 2014 is configured to sort the character strings in lexicographic order, and use the sorting of the character strings as the sorting and numbering of the corresponding position points to obtain the first data set.
  • the first construction unit 202 is configured to construct an extended dictionary tree according to the character strings in the first data set.
  • the location query device 200 based on the Geohash algorithm further includes: a second data set unit 203 and a second construction unit 204.
  • the second data set unit 203 is configured to sort and number all the position points in the preset data set according to the Z-curve order to obtain a second data set, where the second data set includes the position points and the numbers.
  • the second data set unit 203 includes: a second dichotomy unit 2031, a second merging unit 2032, and a second sorting unit 2033.
  • the second dichotomy unit 2031 is configured to perform binary encoding on the longitude and latitude of all position points in the preset data set by dichotomy according to the preset encoding length to obtain the corresponding longitude bit string and latitude bit string.
  • the second merging unit 2032 is configured to merge the longitude bit string and the latitude bit string according to the rule that odd digits are latitude and even digits are longitude to obtain a corresponding position point string.
  • the second sorting unit 2033 is configured to sort the position and point strings according to the size of the position and point strings, and use the sorting of the position and point strings as the corresponding sorting and numbering of the position points to obtain The second data set.
  • the second construction unit 204 is configured to construct an R-tree according to the location points in the second data set.
  • the judging unit 210 is configured to, if a query instruction is received, determine whether the query range distance of the query instruction is greater than a preset threshold, wherein the query instruction includes a query location point and a query range distance.
  • the first query unit 220 is configured to, if the query range distance of the query instruction is not greater than a preset threshold, use the extended dictionary tree to query and return the target location point.
  • the first query unit 220 includes: a second encoding unit 221, an acquiring unit 222, a query sub-unit 223 and a verification unit 224.
  • the second coding unit 221 is configured to determine the coding length of the query location point according to the query range distance and the Geohash accuracy table, and encode the query location point into a string of the code length by using the Geohash algorithm.
  • the obtaining unit 222 is configured to obtain character strings in eight areas around the character string corresponding to the query location point.
  • the query subunit 223 is configured to use the character string corresponding to the query position point and the character strings in the eight regions around the character string corresponding to the query position point as a query domain to query the extended dictionary tree to obtain the query domain Location point.
  • the verification unit 224 is configured to verify the location point in the query domain to obtain the target location point.
  • the verification unit 224 includes: a first calculation unit 2241, a filtering unit 2242, a second calculation unit 2243, and a returning unit 2244.
  • the first calculation unit 2241 is configured to calculate the longitude range and the latitude range of the query location point through a preset formula according to the query location point and the query range distance.
  • the filtering unit 2242 is configured to filter the location points in the query domain according to the longitude range and the latitude range of the query location point to obtain a candidate set.
  • the second calculation unit 2243 is configured to calculate the distance from the location point in the candidate set to the query location point, and compare the distance from the location point in the candidate set to the query location point with the query range distance .
  • the returning unit 2244 is configured to return the location point in the candidate set as a target location point if the distance from the location point in the candidate set to the query location point is not greater than the query range distance.
  • the second query unit 230 is configured to use the R-tree to query and return the target location point if the query range distance of the query instruction is greater than a preset threshold.
  • the above-mentioned location query device based on the Geohash algorithm may be implemented in the form of a computer program, and the computer program may run on the computer device as shown in FIG. 15.
  • FIG. 15 is a schematic block diagram of a computer device according to an embodiment of the present application.
  • the computer device 500 may be a terminal, where the terminal may be an electronic device with communication functions such as a smart phone, a tablet computer, a notebook computer, a desktop computer, a personal digital assistant, and a wearable device.
  • the computer device 500 includes a processor 502, a memory, and a network interface 505 connected through a system bus 501, where the memory may include a non-volatile storage medium 503 and an internal memory 504.
  • the non-volatile storage medium 503 can store an operating system 5031 and a computer program 5032.
  • the computer program 5032 includes program instructions.
  • the processor 502 can execute a location query method based on the Geohash algorithm.
  • the processor 502 is used to provide calculation and control capabilities to support the operation of the entire computer device 500.
  • the internal memory 504 provides an environment for the operation of the computer program 5032 in the non-volatile storage medium 503.
  • the processor 502 can execute a location query method based on the Geohash algorithm.
  • the network interface 505 is used for network communication with other devices.
  • the structure shown in FIG. 15 is only a block diagram of part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device 500 to which the solution of the present application is applied.
  • the specific computer device 500 may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.
  • the processor 502 is configured to run a computer program 5032 stored in a memory to implement the location query method based on the Geohash algorithm in the embodiment of the present application.
  • the processor 502 may be a central processing unit (Central Processing Unit, CPU), and the processor 502 may also be other general-purpose processors, digital signal processors (Digital Signal Processors, DSPs), Application Specific Integrated Circuit (ASIC), Field-Programmable Gate Array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc.
  • the general-purpose processor may be a microprocessor or the processor may also be any conventional processor.
  • the computer program includes program instructions, and the computer program can be stored in a storage medium, which is a computer-readable storage medium.
  • the program instructions are executed by at least one processor in the computer system to implement the process steps of the foregoing method embodiments.
  • the storage medium may be a computer-readable storage medium.
  • the storage medium stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the location query method based on the Geohash algorithm described in the above embodiments.
  • the storage medium may be a U disk, a mobile hard disk, a read-only memory (Read-Only Memory, ROM), a magnetic disk or an optical disk, and other computer-readable storage media that can store program codes.
  • ROM Read-Only Memory

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)
  • Remote Sensing (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本申请实施例公开了一种基于Geohash算法的位置查询方法、装置、计算机设备及存储介质。本申请应用于数据处理中的数据查询领域。所述方法包括:若接收到查询指令,判断所述查询指令的查询范围距离是否大于预设阈值,其中,所述查询指令包括查询位置点以及查询范围距离;若所述查询指令的查询范围距离不大于预设阈值,则采用基于Geohash算法预先构建的扩展字典树对查询域内的位置点进行查询并返回所查询到的目标位置点;若所述查询指令的查询范围距离大于预设阈值,则采用基于Z曲线序预先构建的R树对查询域内的位置点进行查询并返回所查询到的目标位置点。

Description

基于Geohash算法的位置查询方法、装置、计算机设备及存储介质
本申请要求于2019年10月12日提交中国专利局、申请号为201910969194.9、申请名称为“位置查询方法、装置、计算机设备及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及数据处理技术领域,尤其涉及一种基于Geohash算法的位置查询方法、装置、计算机设备及存储介质。
背景技术
随着智能手机的普及,定位技术的发展,基于位置的服务(Location-based Services,LBS)已成为人们生活中最经常使用的功能服务之一。其中,空间查询广泛用于LBS领域,空间索引用于有效支持空间查询,空间索引是指依据空间对象的位置和形状或空间对象之间的某种空间关系按一定的顺序排列的一种数据结构,即用于过滤、排除大量与特定空间操作无关的地理对象,从而缩减空间操作范围。目前,对空间索引结构的研究较多围绕R-Tree及其变体的结构和基于空间填充曲线的结构展开。R-Tree的变体是对R-Tree多路径查询问题进行优化,但检索效率仍受其制约,查询范围较小时,尤其明显,用户使用体验差。
发明内容
本申请实施例提供了一种基于Geohash算法的位置查询方法、装置、计算机设备及存储介质,旨在解决现有的空间索引结构查询效率低,响应速度慢,用户使用体验不佳的问题。
第一方面,本申请实施例提供了一种基于Geohash算法的位置查询方法,其包括:若接收到查询指令,判断所述查询指令的查询范围距离是否大于预设阈值,其中,所述查询指令包括查询位置点以及查询范围距离;若所述查询指令的查询范围距离不大于预设阈值,则采用基于Geohash算法预先构建的扩展字典树对查询域内的位置点进行查询并返回所查询到的目标位置点;若所述查 询指令的查询范围距离大于预设阈值,则采用基于Z曲线序预先构建的R树对查询域内的位置点进行查询并返回所查询到的目标位置点。
第二方面,本申请实施例还提供了一种基于Geohash算法的位置查询装置,其包括:判断单元,用于若接收到查询指令,判断所述查询指令的查询范围距离是否大于预设阈值,其中,所述查询指令包括查询位置点以及查询范围距离;第一查询单元,用于若所述查询指令的查询范围距离不大于预设阈值,则采用基于Geohash算法预先构建的扩展字典树对查询域内的位置点进行查询并返回所查询到的目标位置点;第二查询单元,用于若所述查询指令的查询范围距离大于预设阈值,则采用基于Z曲线序预先构建的R树对查询域内的位置点进行查询并返回所查询到的目标位置点。
第三方面,本申请实施例还提供了一种计算机设备,其包括存储器以及与所述存储器相连的处理器;所述存储器用于存储计算机程序;所述处理器用于运行所述存储器中存储的计算机程序,以执行如下步骤:若接收到查询指令,判断所述查询指令的查询范围距离是否大于预设阈值,其中,所述查询指令包括查询位置点以及查询范围距离;若所述查询指令的查询范围距离不大于预设阈值,则采用基于Geohash算法预先构建的扩展字典树对查询域内的位置点进行查询并返回所查询到的目标位置点;若所述查询指令的查询范围距离大于预设阈值,则采用基于Z曲线序预先构建的R树对查询域内的位置点进行查询并返回所查询到的目标位置点。
第四方面,本申请实施例还提供了一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时使所述处理器执行以下步骤:若接收到查询指令,判断所述查询指令的查询范围距离是否大于预设阈值,其中,所述查询指令包括查询位置点以及查询范围距离;若所述查询指令的查询范围距离不大于预设阈值,则采用基于Geohash算法预先构建的扩展字典树对查询域内的位置点进行查询并返回所查询到的目标位置点;若所述查询指令的查询范围距离大于预设阈值,则采用基于Z曲线序预先构建的R树对查询域内的位置点进行查询并返回所查询到的目标位置点。
附图说明
为了更清楚地说明本申请实施例技术方案,下面将对实施例描述中所需要 使用的附图作简单地介绍,显而易见地,下面描述中的附图是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1为本申请实施例提供的基于Geohash算法的位置查询方法的子流程示意图;
图2为本申请实施例提供的基于Geohash算法的位置查询方法的子流程示意图;
图3为Geohash精度表;
图4为Base32编码表;
图5为本申请实施例提供的基于Geohash算法的位置查询方法的子流程示意图;
图6为本申请实施例提供的基于Geohash算法的位置查询方法的子流程示意图;
图7为本申请实施例提供的基于Geohash算法的位置查询方法的流程示意图;
图8为本申请实施例提供的基于Geohash算法的位置查询方法的子流程示意图;
图9为本申请实施例提供的基于Geohash算法的位置查询方法的子流程示意图;
图10为本申请实施例提供的基于Geohash算法的位置查询装置的示意性框图;
图11为本申请另一实施例提供的基于Geohash算法的位置查询装置的示意性框图;
图12为本申请又一实施例提供的基于Geohash算法的位置查询装置的示意性框图;
图13为本申请实施例提供的基于Geohash算法的位置查询装置的具体单元的示意性框图;
图14为本申请实施例提供的基于Geohash算法的位置查询装置的验证单元的示意性框图;以及
图15为本申请实施例提供的计算机设备的示意性框图。
具体实施方式
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
应当理解,当在本说明书和所附权利要求书中使用时,术语“包括”和“包含”指示所描述特征、整体、步骤、操作、元素和/或组件的存在,但并不排除一个或多个其它特征、整体、步骤、操作、元素、组件和/或其集合的存在或添加。
还应当理解,在此本申请说明书中所使用的术语仅仅是出于描述特定实施例的目的而并不意在限制本申请。如在本申请说明书和所附权利要求书中所使用的那样,除非上下文清楚地指明其它情况,否则单数形式的“一”、“一个”及“该”意在包括复数形式。
还应当进一步理解,在本申请说明书和所附权利要求书中使用的术语“和/或”是指相关联列出的项中的一个或多个的任何组合以及所有可能组合,并且包括这些组合。
本申请采用基于Geohash算法和基于Z曲线序预先构建的扩展字典树以及R树来实现位置查询。当接收到查询指令时,首先判断查询范围距离是否大于预设阈值,当查询范围距离不大于预设阈值时,采用扩展字典树进行查询,当查询范围距离大于预设阈值时,采用R树进行查询,可实现高效支持任意空间范围查询,自适应地选择合适的索引结构,快速响应查询,提高用户使用体验,系统资源利用率高的效果。
因此本申请首先需要基于Geohash算法和基于Z曲线序预先构建扩展字典树以及R树。在一实施例中,如图1所示,其中,基于Geohash算法预先构建扩展字典树该步骤包括以下步骤:S101-S102。
S101、根据Geohash算法对预设数据集中的所有位置点进行编码得到对应的字符串,并根据所述字符串按照字典序对所述位置点进行排序和编号以得到第一数据集,其中,所述第一数据集包括位置点、字符串以及编号。
具体地,Geohash是一种地理编码,其本质是将多维的空间目标映射成一维目标,之后基于一维索引结构实现空间查询。预设数据集指的是由多个位置点 组成的集合,位置点由经度和纬度组成。在本实施例中,通过Geohash算法将预设数据集中的位置点编码为预设长度的字符串String,之后,根据字符串String按照字典序对位置点进行排序并编号,得到第一数据集,其中,每行数据由编号ID、纬度、经度以及字符串构成。
在一实施例中,如图2所示,所述步骤S101可包括步骤:S1011-S1014。
S1011、根据预设编码长度,通过二分法对预设数据集中所有位置点的经度和纬度进行二进制编码,以得到对应的经度位串和纬度位串。
在一实施例中,预设编码长度指的是位置点转换为二进制编码的长度,预设编码长度依据Geohash精度表根据实际情况而定,预设长度为8时,表示大小为20米左右的区域范围,通常情况下能满足最小查询需求,故而本方案将预设长度指定为8,得到的位置点位串位数为40,即预设编码长度,其中纬度位数为20,经度位数为20。Geohash精度表如图3所示。具体地,地球的纬度区间为[-90,90],经度区间为[-180,180],采用二分法将位置点的纬度和经度进行二分,纬度区间划分为[-90,0]和[0,90],[-90,0]为左区间,[0,90]为右区间,同理经度区间划分为[-180,0]和[0,180],[-180,0]为左区间,[0,180]为右区间,位置点的纬度或者经度落在左区间则编码为0,右区间则编码为1,递归上述过程继续划分纬度和经度区间并根据位置点的经度和纬度进行编码,直到得到的经度位串和纬度位串的长度分别为20。例如,给定一个位置点(19.596412-99.219501),19.596412位于右区间则编码为1,再将[0,90]划分为[0,45)和[45,90],19.596412位于左区间则编码为0,以此类推直到得到纬度位串长度为20,最终得到的纬度位串为10011011110111101101。同理,得到的经度位串为00111001011100011010。
S1012、根据奇数位为纬度、偶数位为经度的规则,将所述经度位串和所述纬度位串进行合并,以得到对应的位置点位串。
在一实施例中,在得到经度位串和纬度位串后,将经度位串和纬度位串进行合并以得到位置点位串,从而将二维位置点映射为一维位串。具体地,根据奇数位为纬度、偶数位为经度的规则,对经度位串和纬度位串进行合并。例如,纬度位串为10011011110111101101,经度位串为00111001011100011010,根据偶数位为经度,则位置点位串的第一位取经度位串的第一位数字0,根据奇数位为纬度,则位置点位串的第二位取纬度位串的第一位数字1;位置点位串的第三 位取经度位串的第二位数字0,位置点位串的第四位取纬度位串的第二位数字0;以此类推从而得到合并的位置点位串0100101111000111011110110101011011011001。
S1013、根据字符编码规则对所述位置点位串进行编码以得到对应的字符串。
在一实施例中,字符编码规则指的是Base32,Base32是一种数据编码机制,主要用于将二进制数据编码成字符串,其编码规则是:任意给定一个二进制数据,以5个位(bit)为一组进行切分,对切分而成的每个组进行编码得到1个字符。具体地,将合并得到的位置点位串通过Base32进行编码得到对应的字符串。例如,位置点位串0100101111000111011110110101011011011001,以5个位为一组切分为01001,01111,00011,10111,10110,10101,10110以及11001,首先将切分的编码转化为十进制得到9,15,3,23,22,21,22,25,然后根据Base32编码表转化为字符串得到9g3rqpqt。其中,Base32编码表如图4所示。
S1014、按照字典序对所述字符串进行排序,将所述字符串的排序作为对应的所述位置点的排序并编号以得到第一数据集。
在一实施例中,在所有位置点转换为字符串后,按照字典序对所有的位置点进行排序,字典序是按字母顺序排列字符串的方法。第一数据集中有多行的数据,每行数据由位置点的编号ID、纬度、经度以及对应的字符串组成。例如,按照字典序对9g3rqpqt和9g3rw04d进行排序,那么9g3rw04d排在9g3rqpqt前面,9g3rw04d对应的位置点排在9g3rqpqt对应的位置点前面,9g3rw04d对应的位置点编号为1,9g3rqpqt对应的位置点编号为2,从而组成第一数据集。例如,1 19.596412-99.219501 9g3rw04d。
S102、根据所述第一数据集中的所述字符串构建扩展字典树。
在一实施例中,字典树(Trie树)是一种哈希树的变种,用于统计,排序和保存大量的字符串,其可利用字符串的公共前缀来减少查询时间与存储空间,最大限度地减少无谓的字符串比较,查询效率高。字典树包括根节点和叶子节点,根节点不包括字符,根节点外每一个节点都包括一个字符;从根节点到某一节点,路径上经过的字符连接起来为该节点对应的字符串;每个节点的所有子节点包括的字符都不相同。具体地,将字符串的每个字符依次插入到字典树的节点中,插入前需要先查找前缀是否存在,若存在则共享公共前缀即可,若不存在则创建对应的节点和边,按前述操作,直到所有的字符串都存储到字典 树中,从而构建字典树。例如,插入9g3rqpqt和9g3rw04d,首先依次插入9g3rw04d的每个字符,然后再插入9g3rqpqt,9g3rqpqt在插入时先遍历字典树,由于9g3r在字典树中已存在,只需在r节点后新增节点q,之后在q节点后面新增p节点,依次新增节点q、t。为了提高空间查询效率,对字典树节点进行扩展以得到扩展字典树(GeoExTrie)。具体地,在字典树的节点中增加包含当前节点前缀的起始ID及其个数,使得对较大范围的空间查询,仅需访问从根到某个内部节点的路径即可,而无需访问到叶节点,从而提高空间范围查询响应速率。例如,在查询的字符串为9g3r,其表示一个较大的空间查询范围,相对于字典树,查询扩展字典树,不需要遍历到叶节点才能获取对应的ID,只需要查询到r节点,根据r节点对应的ID和个数即可获取到该查询域内的所有ID。
在一实施例中,如图5所示,基于Z曲线序预先构建R树该步骤包括以下步骤S103-S104。
S103、根据Z曲线序对预设数据集中的所有位置点进行排序并编号以得到第二数据集,其中,所述第二数据集包括位置点以及编号。
在一实施例中,Z曲线是一种空间填充曲线,Z曲线的生成原理是Geohash算法的理论基础,Geohash本质是利用Z阶曲线进行编码,因此Z曲线的处理方法与Geohash类似。Z曲线在保持位置点空间邻近性的前提下,将二维空间位置点表示为一维位串形式,根据位置点对应的二进制位串对预设数据集中的位置点进行排序,即按照Z曲线序对预设数据集中的位置点进行排序,编号后得到第二数据集;其中,每行数据由编号ID、纬度、经度组成。例如,1 19.596412-99.219501。
在一实施例中,如图6所示,所述步骤S103可包括步骤:S1031-S1033。
S1031、根据预设编码长度通过二分法对预设数据集中所有位置点的经度和纬度进行二进制编码以得到对应的经度位串和纬度位串。
S1032、根据奇数位为纬度、偶数位为经度的规则将所述经度位串和所述纬度位串进行合并以得到对应的位置点位串。
在一实施例中,根据Z曲线对所述预设数据集中的所有位置点进行编码得到对应的位置点位串的过程与根据Geohash算法对预设数据集中的所有位置点进行编码得到对应的字符串的过程基本类似,在此不再赘述,区别在于Geohash算法还需要对得到的位置点位串进行编码以得到字符串。
S1033、根据所述位置点位串的大小对所述位置点位串进行排序,并将所述位置点位串的排序作为对应的所述位置点的排序并编号以得到第二数据集。
在一实施例中,在得到所有位置点的位置点位串后,再比较所有二进制的位置点位串的大小,这里的二进制位置点位串即为Z值,按照二进制从小到大对位置点位串进行排序,将位置点位串的排序作为位置点的排序,并编号以得到第二数据集。例如,位置点位串为1111和1000,那么根据位点编码的大小,1000排在1111前面,1000对应的位置点编号为1,1111对应的位置点编号为2。
S104、根据所述第二数据集中的所述位置点构建R树。
在一实施例中,R树是一棵平衡树,其是B树在k维上的自然扩展,用空间对象的MBR来近似表达空间对象,根据MBR建立R树,可以直接对空间中占据一定范围的空间对象进行索引。因此,采用最小外包矩形(Minimum Bounding Rectangle,MBR)近似表示第二数据集中的位置点(纬度、经度),最小外包矩形指的是恰好框住若干个位置点的区域,第二数据集中的位置点均以MBR进行表示。具体地,采用目标界定方法对囊括第二数据集中所有位置点对应MBR的空间区域根据R树构建规则进行区域划分,如R树高度设置为5,根节点层为第一层,则对囊括所有MBR的空间区域进行4次划分。其中,根节点存储囊括第二数据集中MBR的空间区域,根节点的第一层子节点存储第一次划分后的空间区域,依次类推,直至第4层,第5层存储父节点对应空间区域内的MBR,按上述操作过程,构建R树。
请参阅图7,图7为本申请实施例提供的基于Geohash算法的位置查询方法的示意性流程图。该基于Geohash算法的位置查询方法应用于终端中,由终端作为执行主体执行,通过终端接收用户操作的查询指令后执行。如图所示,该方法包括以下步骤S110-S130。
S110、若接收到查询指令,判断所述查询指令的查询范围距离是否大于预设阈值,其中,所述查询指令包括查询位置点以及查询范围距离;
在一实施例中,查询位置点指的是用户查询时所处的位置点,查询范围距离指的是以查询位置点为圆心,距离查询位置点的一个直径距离。该预设阈值经实验证明得到,实验结果显示,当查询范围小于1000米时,所述扩展字典树查询响应时间较短;当查询范围大于1000米时,所述R树查询响应时间较短,因此,预设阈值具体为1000米。具体地,将查询距离与预设阈值进行对比,当 查询距离大于1000米时采用所述R树进行查询,当查询距离不大于1000米时采用所述扩展字典树查询,以自适应的选择合适的索引结构,加快查询响应速度。
S120、若所述查询指令的查询范围距离不大于预设阈值,则采用基于Geohash算法预先构建的扩展字典树对查询域内的位置点进行查询并返回所查询到的目标位置点。
在一实施例中,采用扩展字典树(GeoExTrie)进行查询,首先,根据Geohash算法将查询位置点编码为选定长度的字符串;然后,获取该查询位置点对应的字符串周围8个区域的字符串(Geohash编码),将该查询位置点对应的字符串及其周围8个区域的字符串作为查询域;检索所述扩展字典树,返回查询域内的位置点;接着,根据经纬度范围过滤返回的位置点以得到候选集;最后对候选集中的位置点进行验证最终得到查询区域范围内的位置点。其中,选定长度指根据Geohash精度表选定与查询范围距离相对应的Geohash编码长度,Geohash编码长度对应的区域范围距离不小于查询范围距离且为最小值。
在一实施例中,如图8所示,所述步骤S120可包括步骤:S121-S124。
S121、根据所述查询范围距离以及Geohash精度表确定所述查询位置点的编码长度,并通过Geohash算法将所述查询位置点编码为所述编码长度的字符串。
在一实施例中,给定查询位置点与查询范围距离,根据Geohash精度表选定与查询范围距离d相对应的Geohash编码长度p,通过Geohash算法将查询位置点q编码为p位长度的字符串;其中,p对应的区域范围距离不小于d且为最小值,例如查询距离d为500米,则Geohash编码长度p为6,P对应的区域范围距离为610,大于查询距离d且为最小,在确定Geohash编码长度之后,则通过Geohash算法对查询位置点进行编码得到对应的字符串,该过程与上述Geohash编码的过程相同,在此不再赘述。
S122、获取所述查询位置点对应的字符串周围八个区域的字符串。
在一实施例中,周围八个区域具体指的是东西南北方区域、东南方区域、东北方区域,西南方区域以及西北方区域。具体地,在得到查询位置点的字符串后,根据查询位置的字符串的纬度位串和经度位串计算周围八个区域的字符串对应的纬度位串和经度位串。
其中,北方区域的字符串对应的纬度位串等于查询位置点的字符串的纬度位串,北方区域的字符串对应的经度位串等于查询位置点的字符串的经度位串加1。
南方区域的字符串对应的纬度位串等于查询位置点的字符串的纬度位串,南方区域的字符串对应的经度位串等于查询位置点的字符串的经度位串减1。
东方区域的字符串对应的纬度位串等于查询位置点的字符串的纬度位串加1,东方区域的字符串对应的经度位串等于查询位置点的字符串的经度位串。
西方区域的字符串对应的纬度位串等于查询位置点的字符串的纬度位串减1,东方区域的字符串对应的经度位串等于查询位置点的字符串的经度位串。
东北方区域的字符串对应的纬度位串等于查询位置点的字符串的纬度位串加1,东北方区域的字符串对应的经度位串等于查询位置点的字符串的经度位串加1。
西北方区域的字符串对应的纬度位串等于查询位置点的字符串的纬度位串减1,西北方区域的字符串对应的经度位串等于查询位置点的字符串的经度位串加1。
东南方区域的字符串对应的纬度位串等于查询位置点的字符串的纬度位串加1,东南方区域的字符串对应的经度位串等于查询位置点的字符串的经度位串减1。
西南方区域的字符串对应的纬度位串等于查询位置点的字符串的纬度位串减1,西南方区域的字符串对应的经度位串等于查询位置点的字符串的经度位串减1。
例如,位置点的字符串为9g3rqp,其对应的纬度位串为100110111101111,经度位串为001110010111000,那么其北方区域的字符串对应的纬度位串则为100110111101111,经度位串则为001110010111000+1=001110010111001。在计算完经度位串和纬度位串后,再将经度位串和纬度位串合并,接着根据base32对合并后的位置点位串进行编码得到字符串,最终得到查询位置点周围的八个区域的字符串。
S123、将所述查询位置点对应的字符串以及所述查询位置点对应的字符串周围八个区域的字符串作为查询域查询所述扩展字典树以得到所述查询域内的位置点。
在一实施例中,根据查询位置点的字符串以及周围八个区域的字符串遍历所述字典树,在所述字典树查找是否具有相同的字符串,若有则返回该字符串对应的位置点编号ID即为查询域内位置点。
S124、对所述查询域内的位置点进行验证以得到目标位置点。
在一实施例中,在得到查询域内的位置点后,则对查询域内的位置点进行验证,验证该查询域内的位置点是否在查询范围距离内。具体地,首先计算出查询位置点的经度范围和纬度范围,然后再根据查询位置点的经度范围和纬度范围来对查询域内的位置点进行过滤得到候选集,最后再对候选集中的位置点进行验证,计算候选集中的位置点到查询位置点的距离,将不大于查询范围距离的所述候选集中的位置点返回。
在一实施例中,如图9所示,所述步骤S124可包括步骤:S1241-S1244。
S1241、根据所述查询位置点以及所述查询范围距离通过预设公式计算所述查询位置点的经度范围和纬度范围。
S1242、根据所述查询位置点的经度范围和纬度范围对所述查询域内的位置点进行过滤得到候选集。
在一实施例中,根据查询位置点以及查询范围距离通过预设公式计算求出经度范围和纬度范围。预设公式如下:
maxLat=lat+range
minLat=lat-range
maxLng=lon+lngR
minLng=lon-lngR
range=180/π*d/6372.797
lngR=range/cos(lat*π/180.0)
其中,lat表示查询位置点的纬度值,lon表示查询位置点的经度值,d是查询范围距离,range和lngR均为变量,(minLat、maxLat)表示纬度范围,(minLng,maxLng)表示经度范围。例如,查询位置点(19.596412-99.219501)和查询距离范围500m,据上述公式可得,经度范围为[19.591917,19.600907],纬度范围为[-99.224272,-99.214730]。之后根据经纬度范围过滤查询结果返回编号ID对应于第一数据集中的位置点,得到位置点候选集。假设查询结果返回的 ID集中,ID为1对应的经纬度为(19.600038-99.22491),19.600038位于[19.591917,19.600907]内,而-99.22491不位于[-99.224272,-99.214730]内,故过滤ID为1的位置点。只有位置点的经度值和纬度值均落入经度范围和纬度范围的才保留该位置点,从而筛选掉不在经纬度范围内的位置点,最终得到候选集。
S1243、计算所述候选集中的位置点到所述查询位置点的距离,并将所述候选集中的位置点到所述查询位置点的距离与所述查询范围距离进行对比。
S1244、若所述候选集中的位置点到所述查询位置点的距离不大于所述查询范围距离,则将所述候选集中的位置点作为目标位置点返回。
在一实施例中,根据预设公式计算候选集中的位置点到查询位置点的距离,其中,预设公式如下:
Figure PCTCN2019118264-appb-000001
其中,A(x 1,y 1)为候选集中的位置点,B(x 2,y 2)为查询位置点,|AB|为候选集中的位置点到查询位置点的距离。例如,(19.59918,-99.21667)为候选集中一个位置点,查询范围距离为500米,计算该位置点到查询位置点(19.596412-99.219501)之间的距离,经计算,若该距离小于500米,则该位置点满足空间范围查询条件,将该位置点作为查询区域范围内的位置点返回。
S130、若所述查询指令的查询范围距离大于预设阈值,则采用所述R树进行查询并返回目标位置点。
在一实施例中,采用R树进行查询,首先,根据查询位置点以及查询范围距离确定查询位置点的纬度范围和经度范围,计算方法与上述步骤相同,在此不在赘述。然后,根据经纬度范围对应的空间区域检索R树,返回该区域内包含的MBR对应的位置点,即为位置点候选集;最后,计算候选集中位置点到查询位置点的距离,返回距离不大于查询范围距离的位置点,即为目标位置点,该验证过程与上述验证过程相同,在此不再赘述。
本申请实施例展示了一种基于Geohash算法的位置查询方法,通过若接收到查询指令,判断所述查询指令的查询范围距离是否大于预设阈值,其中,所述查询指令包括查询位置点以及查询范围距离;若所述查询指令的查询范围距 离不大于预设阈值,则采用基于Geohash算法预先构建的扩展字典树对查询域内的位置点进行查询并返回所查询到的目标位置点;若所述查询指令的查询范围距离大于预设阈值,则采用基于Z曲线序预先构建的R树对查询域内的位置点进行查询并返回所查询到的目标位置点,可实现高效支持任意空间范围查询,自适应地选择合适的索引结构,快速响应查询,提高用户使用体验,系统资源利用率高的效果。
图10是本申请实施例提供的一种基于Geohash算法的位置查询装置200的示意性框图。如图10所示,对应于以上基于Geohash算法的位置查询方法,本申请还提供一种基于Geohash算法的位置查询装置200。该基于Geohash算法的位置查询装置200包括用于执行上述基于Geohash算法的位置查询方法的单元,该装置可以被配置于台式电脑、平板电脑、手提电脑、等终端中。具体地,请参阅图10,该基于Geohash算法的位置查询装置200包括:判断单元210、第一查询单元220以及第二查询单元230。
在一实施例中,如图11所示,所述基于Geohash算法的位置查询装置200还包括:第一数据集单元201以及第一构建单元202。
第一数据集单元201,用于根据Geohash算法对预设数据集中的所有位置点进行编码得到对应的字符串,并根据所述字符串按照字典序对所述位置点进行排序和编号以得到第一数据集,其中,所述第一数据集包括位置点、字符串以及编号。
在一实施例中,如图11所示,所述第一数据集单元201包括:第一二分单元2011、第一合并单元2012、第一编码单元2013以及第一排序单元2014。
第一二分单元2011,用于根据预设编码长度通过二分法对预设数据集中所有位置点的经度和纬度进行二进制编码以得到对应的经度位串和纬度位串。
第一合并单元2012,用于根据奇数位为纬度、偶数位为经度的规则将所述经度位串和所述纬度位串进行合并以得到对应的位置点位串。
第一编码单元2013,用于根据字符编码规则对所述位置点位串进行编码以得到对应的字符串。
第一排序单元2014,用于按照字典序对所述字符串进行排序,将所述字符串的排序作为对应的所述位置点的排序并编号以得到第一数据集。
第一构建单元202,用于根据所述第一数据集中的所述字符串构建扩展字典 树。
在一实施例中,如图12所示,所述基于Geohash算法的位置查询装置200还包括:第二数据集单元203以及第二构建单元204。
第二数据集单元203,用于根据Z曲线序对预设数据集中的所有位置点进行排序并编号以得到第二数据集,其中,所述第二数据集包括位置点以及编号。
在一实施例中,如图12所示,所述第二数据集单元203包括:第二二分单元2031、第二合并单元2032以及第二排序单元2033。
第二二分单元2031,用于根据预设编码长度通过二分法对预设数据集中所有位置点的经度和纬度进行二进制编码以得到对应的经度位串和纬度位串。
第二合并单元2032,用于根据奇数位为纬度、偶数位为经度的规则将所述经度位串和所述纬度位串进行合并以得到对应的位置点位串。
第二排序单元2033,用于根据所述位置点位串的大小对所述位置点位串进行排序,并将所述位置点位串的排序作为对应的所述位置点的排序并编号以得到第二数据集。
第二构建单元204,用于根据所述第二数据集中的所述位置点构建R树。
判断单元210,用于若接收到查询指令,判断所述查询指令的查询范围距离是否大于预设阈值,其中,所述查询指令包括查询位置点以及查询范围距离。
第一查询单元220,用于若所述查询指令的查询范围距离不大于预设阈值,则采用所述扩展字典树进行查询并返回目标位置点。
在一实施例中,如图13所示,所述第一查询单元220包括:第二编码单元221、获取单元222、查询子单元223以及验证单元224。
第二编码单元221,用于根据所述查询范围距离以及Geohash精度表确定所述查询位置点的编码长度,并通过Geohash算法将所述查询位置点编码为所述编码长度的字符串。
获取单元222,用于获取所述查询位置点对应的字符串周围八个区域的字符串。
查询子单元223,用于将所述查询位置点对应的字符串以及所述查询位置点对应的字符串周围八个区域的字符串作为查询域查询所述扩展字典树以得到所述查询域内的位置点。
验证单元224,用于对所述查询域内的位置点进行验证以得到目标位置点。
在一实施例中,如图14所示,所述验证单元224包括:第一计算单元2241、过滤单元2242、第二计算单元2243以及返回单元2244。
第一计算单元2241,用于根据所述查询位置点以及所述查询范围距离通过预设公式计算所述查询位置点的经度范围和纬度范围。
过滤单元2242,用于根据所述查询位置点的经度范围和纬度范围对所述查询域内的位置点进行过滤得到候选集。
第二计算单元2243,用于计算所述候选集中的位置点到所述查询位置点的距离,并将所述候选集中的位置点到所述查询位置点的距离与所述查询范围距离进行对比。
返回单元2244,用于若所述候选集中的位置点到所述查询位置点的距离不大于所述查询范围距离,则将所述候选集中的位置点作为目标位置点返回。
第二查询单元230,用于若所述查询指令的查询范围距离大于预设阈值,则采用所述R树进行查询并返回目标位置点。
需要说明的是,所属领域的技术人员可以清楚地了解到,上述基于Geohash算法的位置查询装置200和各单元的具体实现过程,可以参考前述方法实施例中的相应描述,为了描述的方便和简洁,在此不再赘述。
上述基于Geohash算法的位置查询装置可以实现为一种计算机程序的形式,该计算机程序可以在如图15所示的计算机设备上运行。
请参阅图15,图15是本申请实施例提供的一种计算机设备的示意性框图。该计算机设备500可以是终端,其中,终端可以是智能手机、平板电脑、笔记本电脑、台式电脑、个人数字助理和穿戴式设备等具有通信功能的电子设备。
参阅图15,该计算机设备500包括通过系统总线501连接的处理器502、存储器和网络接口505,其中,存储器可以包括非易失性存储介质503和内存储器504。
该非易失性存储介质503可存储操作系统5031和计算机程序5032。该计算机程序5032包括程序指令,该程序指令被执行时,可使得处理器502执行一种基于Geohash算法的位置查询方法。
该处理器502用于提供计算和控制能力,以支撑整个计算机设备500的运行。
该内存储器504为非易失性存储介质503中的计算机程序5032的运行提供环境,该计算机程序5032被处理器502执行时,可使得处理器502执行一种基于Geohash算法的位置查询方法。
该网络接口505用于与其它设备进行网络通信。本领域技术人员可以理解,图15中示出的结构,仅仅是与本申请方案相关的部分结构的框图,并不构成对本申请方案所应用于其上的计算机设备500的限定,具体的计算机设备500可以包括比图中所示更多或更少的部件,或者组合某些部件,或者具有不同的部件布置。
其中,所述处理器502用于运行存储在存储器中的计算机程序5032,以实现本申请实施例的基于Geohash算法的位置查询方法。
应当理解,在本申请实施例中,处理器502可以是中央处理单元(Central Processing Unit,CPU),该处理器502还可以是其他通用处理器、数字信号处理器(Digital Signal Processor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现成可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。其中,通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。
本领域普通技术人员可以理解的是实现上述实施例的方法中的全部或部分流程,是可以通过计算机程序来指令相关的硬件来完成。该计算机程序包括程序指令,计算机程序可存储于一存储介质中,该存储介质为计算机可读存储介质。该程序指令被该计算机系统中的至少一个处理器执行,以实现上述方法的实施例的流程步骤。
因此,本申请还提供一种存储介质。该存储介质可以为计算机可读存储介质。该存储介质存储有计算机程序,该计算机程序被处理器执行时使处理器执行以上各实施例中所描述的基于Geohash算法的位置查询方法的步骤。
所述存储介质可以是U盘、移动硬盘、只读存储器(Read-Only Memory,ROM)、磁碟或者光盘等各种可以存储程序代码的计算机可读存储介质。
以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到各种等效的修改或替换,这些修改或替换都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以权利要求的保护范围为准。

Claims (20)

  1. 一种基于Geohash算法的位置查询方法,包括:
    若接收到查询指令,判断所述查询指令的查询范围距离是否大于预设阈值,其中,所述查询指令包括查询位置点以及查询范围距离;
    若所述查询指令的查询范围距离不大于预设阈值,则采用基于Geohash算法预先构建的扩展字典树对查询域内的位置点进行查询并返回所查询到的目标位置点;
    若所述查询指令的查询范围距离大于预设阈值,则采用基于Z曲线序预先构建的R树对查询域内的位置点进行查询并返回所查询到的目标位置点。
  2. 根据权利要求1所述的基于Geohash算法的位置查询方法,其中,基于Geohash算法预先构建扩展字典树,包括:
    根据Geohash算法对预设数据集中的所有位置点进行编码得到对应的字符串,并根据所述字符串按照字典序对所述位置点进行排序和编号以得到第一数据集,其中,所述第一数据集包括位置点、字符串以及编号;
    根据所述第一数据集中的所述字符串构建扩展字典树。
  3. 根据权利要求1所述的基于Geohash算法的位置查询方法,其中,基于Z曲线序预先构建R树,包括:
    根据Z曲线序对预设数据集中的所有位置点进行排序并编号以得到第二数据集,其中,所述第二数据集包括位置点以及编号;
    根据所述第二数据集中的所述位置点构建R树。
  4. 根据权利要求2所述的基于Geohash算法的位置查询方法,其中,所述根据Geohash算法对预设数据集中的所有位置点进行编码得到对应的字符串,并根据所述字符串按照字典序对所述位置点进行排序和编号以得到第一数据集,包括:
    根据预设编码长度通过二分法对预设数据集中所有位置点的经度和纬度进行二进制编码以得到对应的经度位串和纬度位串;
    根据奇数位为纬度、偶数位为经度的规则将所述经度位串和所述纬度位串进行合并以得到对应的位置点位串;
    根据字符编码规则对所述位置点位串进行编码以得到对应的字符串;
    按照字典序对所述字符串进行排序,将所述字符串的排序作为对应的所述位置点的排序并编号以得到第一数据集。
  5. 根据权利要求3所述的基于Geohash算法的位置查询方法,其中,所述根据Z曲线序对所述预设数据集中的所有位置点进行排序并编号以得到第二数据集,包括:
    根据预设编码长度通过二分法对预设数据集中所有位置点的经度和纬度进行二进制编码以得到对应的经度位串和纬度位串;
    根据奇数位为纬度、偶数位为经度的规则将所述经度位串和所述纬度位串进行合并以得到对应的位置点位串;
    根据所述位置点位串的大小对所述位置点位串进行排序,并将所述位置点位串的排序作为对应的所述位置点的排序并编号以得到第二数据集。
  6. 根据权利要求1所述的基于Geohash算法的位置查询方法,其中,所述采用基于Geohash算法预先构建的扩展字典树对查询域内的位置点进行查询并返回所查询到的目标位置点,包括:
    根据所述查询范围距离以及Geohash精度表确定所述查询位置点的编码长度,并通过Geohash算法将所述查询位置点编码为所述编码长度的字符串;
    获取所述查询位置点对应的字符串周围八个区域的字符串;
    将所述查询位置点对应的字符串以及所述查询位置点对应的字符串周围八个区域的字符串作为查询域查询所述扩展字典树以得到所述查询域内的位置点;
    对所述查询域内的位置点进行验证以得到目标位置点。
  7. 根据权利要求6所述的基于Geohash算法的位置查询方法,其中,所述对所述查询域内的位置点进行验证以得到目标位置点,包括:
    根据所述查询位置点以及所述查询范围距离通过预设公式计算所述查询位置点的经度范围和纬度范围;
    根据所述查询位置点的经度范围和纬度范围对所述查询域内的位置点进行过滤得到候选集;
    计算所述候选集中的位置点到所述查询位置点的距离,并将所述候选集中的位置点到所述查询位置点的距离与所述查询范围距离进行对比;
    若所述候选集中的位置点到所述查询位置点的距离不大于所述查询范围距离,则将所述候选集中的位置点作为目标位置点返回。
  8. 一种基于Geohash算法的位置查询装置,包括:
    判断单元,用于若接收到查询指令,判断所述查询指令的查询范围距离是否大于预设阈值,其中,所述查询指令包括查询位置点以及查询范围距离;
    第一查询单元,用于若所述查询指令的查询范围距离不大于预设阈值,则采用基于Geohash算法预先构建的扩展字典树对查询域内的位置点进行查询并返回所查询到的目标位置点;
    第二查询单元,用于若所述查询指令的查询范围距离大于预设阈值,则采用基于Z曲线序预先构建的R树对查询域内的位置点进行查询并返回所查询到的目标位置点。
  9. 根据权利要求8所述的基于Geohash算法的位置查询装置,其中,所述基于Geohash算法的位置查询装置还包括:
    第一数据集单元,用于根据Geohash算法对预设数据集中的所有位置点进行编码得到对应的字符串,并根据所述字符串按照字典序对所述位置点进行排序和编号以得到第一数据集,其中,所述第一数据集包括位置点、字符串以及编号;
    第一构建单元,用于根据所述第一数据集中的所述字符串构建扩展字典树。
  10. 根据权利要求8所述的基于Geohash算法的位置查询装置,其中,所述基于Geohash算法的位置查询装置还包括:
    第二数据集单元,用于根据Z曲线序对预设数据集中的所有位置点进行排序并编号以得到第二数据集,其中,所述第二数据集包括位置点以及编号;
    第二构建单元,用于根据所述第二数据集中的所述位置点构建R树。
  11. 一种计算机设备,包括存储器以及与所述存储器相连的处理器;所述存储器用于存储计算机程序;所述处理器用于运行所述存储器中存储的计算机程序,以执行如下步骤:
    若接收到查询指令,判断所述查询指令的查询范围距离是否大于预设阈值,其中,所述查询指令包括查询位置点以及查询范围距离;
    若所述查询指令的查询范围距离不大于预设阈值,则采用基于Geohash算法预先构建的扩展字典树对查询域内的位置点进行查询并返回所查询到的目标位置点;
    若所述查询指令的查询范围距离大于预设阈值,则采用基于Z曲线序预先 构建的R树对查询域内的位置点进行查询并返回所查询到的目标位置点。
  12. 根据权利要求11所述的计算机设备,其中,基于Geohash算法预先构建扩展字典树,包括:
    根据Geohash算法对预设数据集中的所有位置点进行编码得到对应的字符串,并根据所述字符串按照字典序对所述位置点进行排序和编号以得到第一数据集,其中,所述第一数据集包括位置点、字符串以及编号;
    根据所述第一数据集中的所述字符串构建扩展字典树。
  13. 根据权利要求11所述的计算机设备,其中,基于Z曲线序预先构建R树,包括:
    根据Z曲线序对预设数据集中的所有位置点进行排序并编号以得到第二数据集,其中,所述第二数据集包括位置点以及编号;
    根据所述第二数据集中的所述位置点构建R树。
  14. 根据权利要求12所述的计算机设备,其中,所述根据Geohash算法对预设数据集中的所有位置点进行编码得到对应的字符串,并根据所述字符串按照字典序对所述位置点进行排序和编号以得到第一数据集,包括:
    根据预设编码长度通过二分法对预设数据集中所有位置点的经度和纬度进行二进制编码以得到对应的经度位串和纬度位串;
    根据奇数位为纬度、偶数位为经度的规则将所述经度位串和所述纬度位串进行合并以得到对应的位置点位串;
    根据字符编码规则对所述位置点位串进行编码以得到对应的字符串;
    按照字典序对所述字符串进行排序,将所述字符串的排序作为对应的所述位置点的排序并编号以得到第一数据集。
  15. 根据权利要求13所述的计算机设备,其中,所述根据Z曲线序对所述预设数据集中的所有位置点进行排序并编号以得到第二数据集,包括:
    根据预设编码长度通过二分法对预设数据集中所有位置点的经度和纬度进行二进制编码以得到对应的经度位串和纬度位串;
    根据奇数位为纬度、偶数位为经度的规则将所述经度位串和所述纬度位串进行合并以得到对应的位置点位串;
    根据所述位置点位串的大小对所述位置点位串进行排序,并将所述位置点位串的排序作为对应的所述位置点的排序并编号以得到第二数据集。
  16. 根据权利要求11所述的计算机设备,其中,所述采用基于Geohash算法预先构建的扩展字典树对查询域内的位置点进行查询并返回所查询到的目标位置点,包括:
    根据所述查询范围距离以及Geohash精度表确定所述查询位置点的编码长度,并通过Geohash算法将所述查询位置点编码为所述编码长度的字符串;
    获取所述查询位置点对应的字符串周围八个区域的字符串;
    将所述查询位置点对应的字符串以及所述查询位置点对应的字符串周围八个区域的字符串作为查询域查询所述扩展字典树以得到所述查询域内的位置点;
    对所述查询域内的位置点进行验证以得到目标位置点。
  17. 根据权利要求16所述的计算机设备,其中,所述对所述查询域内的位置点进行验证以得到目标位置点,包括:
    根据所述查询位置点以及所述查询范围距离通过预设公式计算所述查询位置点的经度范围和纬度范围;
    根据所述查询位置点的经度范围和纬度范围对所述查询域内的位置点进行过滤得到候选集;
    计算所述候选集中的位置点到所述查询位置点的距离,并将所述候选集中的位置点到所述查询位置点的距离与所述查询范围距离进行对比;
    若所述候选集中的位置点到所述查询位置点的距离不大于所述查询范围距离,则将所述候选集中的位置点作为目标位置点返回。
  18. 一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时使所述处理器执行以下步骤:
    若接收到查询指令,判断所述查询指令的查询范围距离是否大于预设阈值,其中,所述查询指令包括查询位置点以及查询范围距离;
    若所述查询指令的查询范围距离不大于预设阈值,则采用基于Geohash算法预先构建的扩展字典树对查询域内的位置点进行查询并返回所查询到的目标位置点;
    若所述查询指令的查询范围距离大于预设阈值,则采用基于Z曲线序预先构建的R树对查询域内的位置点进行查询并返回所查询到的目标位置点。
  19. 根据权利要求18所述的计算机可读存储介质,其中,基于Geohash算法预先构建扩展字典树的步骤,包括:
    根据Geohash算法对预设数据集中的所有位置点进行编码得到对应的字符串,并根据所述字符串按照字典序对所述位置点进行排序和编号以得到第一数据集,其中,所述第一数据集包括位置点、字符串以及编号;
    根据所述第一数据集中的所述字符串构建扩展字典树。
  20. 根据权利要求18所述的计算机可读存储介质,其中,基于Z曲线序预先构建R树的步骤,包括:
    根据Z曲线序对预设数据集中的所有位置点进行排序并编号以得到第二数据集,其中,所述第二数据集包括位置点以及编号;
    根据所述第二数据集中的所述位置点构建R树。
PCT/CN2019/118264 2019-10-12 2019-11-14 基于Geohash算法的位置查询方法、装置、计算机设备及存储介质 WO2021068346A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910969194.9A CN111078807B (zh) 2019-10-12 2019-10-12 位置查询方法、装置、计算机设备及存储介质
CN201910969194.9 2019-10-12

Publications (1)

Publication Number Publication Date
WO2021068346A1 true WO2021068346A1 (zh) 2021-04-15

Family

ID=70310323

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/118264 WO2021068346A1 (zh) 2019-10-12 2019-11-14 基于Geohash算法的位置查询方法、装置、计算机设备及存储介质

Country Status (2)

Country Link
CN (1) CN111078807B (zh)
WO (1) WO2021068346A1 (zh)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113821539A (zh) * 2021-09-07 2021-12-21 丰图科技(深圳)有限公司 区域查询方法、装置、电子设备和可读存储介质
CN114116948A (zh) * 2021-12-06 2022-03-01 中国人民解放军国防科技大学 地理矢量数据空间缓冲区分析方法、装置、设备及介质
CN114383616A (zh) * 2021-12-29 2022-04-22 中国电信股份有限公司 距离计算方法和相关装置
CN114500872A (zh) * 2021-12-30 2022-05-13 浙江大华技术股份有限公司 摄像机与道路信息的匹配方法、计算机设备和存储介质
CN114925069A (zh) * 2022-05-30 2022-08-19 重庆长安汽车股份有限公司 大数据gps离线解析方法
CN115827814A (zh) * 2023-02-13 2023-03-21 深圳市泰比特科技有限公司 视野区域内车辆点的加载显示方法、系统及相关设备

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113722358B (zh) * 2021-08-20 2023-11-17 河北环鼎石油设备有限责任公司 一种泵出测井方式的大文件回放算法及系统、装置

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150261786A1 (en) * 2014-03-14 2015-09-17 Twitter, Inc. Density-based dynamic geohash
CN107798054A (zh) * 2017-09-04 2018-03-13 昆明理工大学 一种基于Trie的范围查询方法及装置
CN108776666A (zh) * 2018-05-04 2018-11-09 昆明理工大学 一种基于关键词倒排与Trie的空间关键词查询方法及装置

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150261786A1 (en) * 2014-03-14 2015-09-17 Twitter, Inc. Density-based dynamic geohash
CN107798054A (zh) * 2017-09-04 2018-03-13 昆明理工大学 一种基于Trie的范围查询方法及装置
CN108776666A (zh) * 2018-05-04 2018-11-09 昆明理工大学 一种基于关键词倒排与Trie的空间关键词查询方法及装置

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
JIA LIANYIN: "Spatio-Textual Query: Review and Opportunities", INTERNATIONAL JOURNAL OF PERFORMABILITY ENGINEERING, 1 January 2018 (2018-01-01), XP055800494, DOI: 10.23940/ijpe.18.11.p30.28422851 *
JIN AN, CHENG CHENG-QI; SONG SHU-HUA; CHEN BO: "Regional Query of Area Data Based on Geohash", GEOGRAPHY AND GEO-INFORMATION SCIENCE, vol. 29, no. 5, 1 September 2013 (2013-09-01), pages 31 - 35, XP055800496, DOI: 10.7702/dlydlxxkx20130507 *
XIANG LONGGANG, WANG DEHAO; GONG JIANYA: "Organization and Efficient Range Query of Large Trajectory Data Based on Geohash", GEOMATICS AND INFORMATION SCIENCE OF WUHAN UNIVERSITY, vol. 42, no. 1, 1 January 2017 (2017-01-01), pages 21 - 27, XP055800501, DOI: 10.13203/j.whugis20150175 *

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113821539A (zh) * 2021-09-07 2021-12-21 丰图科技(深圳)有限公司 区域查询方法、装置、电子设备和可读存储介质
CN114116948A (zh) * 2021-12-06 2022-03-01 中国人民解放军国防科技大学 地理矢量数据空间缓冲区分析方法、装置、设备及介质
CN114383616A (zh) * 2021-12-29 2022-04-22 中国电信股份有限公司 距离计算方法和相关装置
CN114383616B (zh) * 2021-12-29 2024-04-16 中国电信股份有限公司 距离计算方法和相关装置
CN114500872A (zh) * 2021-12-30 2022-05-13 浙江大华技术股份有限公司 摄像机与道路信息的匹配方法、计算机设备和存储介质
CN114500872B (zh) * 2021-12-30 2024-06-07 浙江大华技术股份有限公司 摄像机与道路信息的匹配方法、计算机设备和存储介质
CN114925069A (zh) * 2022-05-30 2022-08-19 重庆长安汽车股份有限公司 大数据gps离线解析方法
CN115827814A (zh) * 2023-02-13 2023-03-21 深圳市泰比特科技有限公司 视野区域内车辆点的加载显示方法、系统及相关设备
CN115827814B (zh) * 2023-02-13 2023-06-06 深圳市泰比特科技有限公司 视野区域内车辆点的加载显示方法、系统及相关设备

Also Published As

Publication number Publication date
CN111078807B (zh) 2023-10-24
CN111078807A (zh) 2020-04-28

Similar Documents

Publication Publication Date Title
WO2021068346A1 (zh) 基于Geohash算法的位置查询方法、装置、计算机设备及存储介质
WO2021072874A1 (zh) 基于双数组的位置查询方法、装置、计算机设备及存储介质
CN107798054B (zh) 一种基于Trie的范围查询方法及装置
CN110019647B (zh) 一种关键词搜索方法、装置和搜索引擎
CN107766433B (zh) 一种基于Geo-BTree的范围查询方法及装置
CN109101474B (zh) 一种地址聚合的方法、包裹聚合的方法以及设备
CN102609530A (zh) 一种分区域双树结构的空间数据库索引方法
US10275486B2 (en) Multi-system segmented search processing
CN108009265B (zh) 一种云计算环境下的空间数据索引方法
CN106991149B (zh) 一种融合编码和多版本数据的海量空间对象存储方法
CN108197313B (zh) 通过16位Trie树实现空间优化的词典索引方法
CN108460123B (zh) 高维数据检索方法、计算机设备和存储介质
WO2018205151A1 (zh) 数据更新方法和存储装置
CN109815238A (zh) 用严格平衡二叉树实现数据库的动态添加方法及装置
US10747783B2 (en) Database access using a z-curve
WO2021068347A1 (zh) 自适应位置查询方法、装置、计算机设备及存储介质
EP3955256A1 (en) Non-redundant gene clustering method and system, and electronic device
CN108776666A (zh) 一种基于关键词倒排与Trie的空间关键词查询方法及装置
CN112948717B (zh) 一种基于多因素约束的海量空间poi搜索方法及系统
JP2010277329A (ja) 近傍探索装置
CN116301656A (zh) 基于日志结构合并树的数据存储方法、系统及设备
JP4440246B2 (ja) 空間インデックス方法
CN116521733A (zh) 一种数据查询方法及装置
CN102521418A (zh) 用于存储拼音的存储结构及拼音输入方法
CN101467149A (zh) 具有可变压缩的自适应索引

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19948486

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 19948486

Country of ref document: EP

Kind code of ref document: A1