WO2021072874A1 - 基于双数组的位置查询方法、装置、计算机设备及存储介质 - Google Patents
基于双数组的位置查询方法、装置、计算机设备及存储介质 Download PDFInfo
- Publication number
- WO2021072874A1 WO2021072874A1 PCT/CN2019/118308 CN2019118308W WO2021072874A1 WO 2021072874 A1 WO2021072874 A1 WO 2021072874A1 CN 2019118308 W CN2019118308 W CN 2019118308W WO 2021072874 A1 WO2021072874 A1 WO 2021072874A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- query
- location point
- character
- dictionary tree
- array
- Prior art date
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/95—Retrieval from the web
- G06F16/953—Querying, e.g. by the use of web search engines
- G06F16/9537—Spatial or temporal dependent retrieval, e.g. spatiotemporal queries
Definitions
- This application relates to the field of computer data processing, and in particular to a method, device, computer equipment, and computer-readable storage medium based on double arrays for location query.
- the dictionary tree (Trie) compresses the common prefix of the string into a path in the dictionary tree (Trie) to achieve efficient query of the prefix part, so geohash and Trie are usually combined to support spatial query.
- the disadvantage is that when querying for any spatial range, it is necessary to access leaf nodes to obtain records that meet the query conditions, which greatly reduces retrieval efficiency and poor user experience.
- building a complete Trie leads to a large amount of storage space.
- the embodiments of the present application provide a location query method, device, computer equipment, and storage medium based on a double array, aiming to solve the problems of low location query accuracy and slow recognition speed.
- an embodiment of the present application provides a location query method based on a double array, which includes: encoding all location points in a preset data set according to a geohash algorithm to obtain a character string corresponding to the location point, wherein: The location points include longitude and latitude; all the location points in the preset data set and the character strings corresponding to the location points are sorted and numbered in lexicographical order to obtain a target data set, and constructed according to the target data set Extended dictionary tree; convert the extended dictionary tree into a double-array dictionary tree; if a query instruction is received, query the double-array dictionary tree according to the query instruction to obtain a position point in the query domain, wherein the query instruction includes Query the location point and the query distance range; verify the location point in the query domain to obtain the target location point.
- an embodiment of the present application provides a location query device based on a double array, which includes: an encoding unit for encoding all location points in a preset data set according to the geohash algorithm to obtain the location corresponding to the location point A character string, wherein the position point includes longitude and latitude; a construction unit for sorting and numbering all the position points in the preset data set and the character strings corresponding to the position points in lexicographical order to obtain target data Set, and construct an extended dictionary tree according to the target data set; a conversion unit, for converting the extended dictionary tree into a double array dictionary tree; a query unit, for if a query instruction is received, query the database according to the query instruction
- the double array dictionary tree is used to obtain the location point in the query domain, wherein the query instruction includes the query location point and the query distance range; the verification unit is used to verify the location point in the query domain to obtain the target location point.
- 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 perform the following steps: encode all the position points in the preset data set according to the geohash algorithm to obtain the character string corresponding to the position point, wherein the position point includes longitude and latitude; All the position points in the preset data set and the character strings corresponding to the position points are sorted and numbered to obtain a target data set, and an extended dictionary tree is constructed according to the target data set; the extended dictionary tree is converted into a double array dictionary If a query instruction is received, query the double-array dictionary tree according to the query instruction to obtain a location point in the query domain, wherein the query instruction includes a query location point and a query distance range; for the location in the query domain Point to verify to get the target location point.
- 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:
- the geohash algorithm encodes all location points in the preset data set to obtain the character string corresponding to the location point, where the location point includes longitude and latitude; lexicographically, all the location points in the preset data set and The character strings corresponding to the position points are sorted and numbered to obtain a target data set, and an extended dictionary tree is constructed according to the target data set; the extended dictionary tree is converted into a double array dictionary tree; if a query instruction is received, according to The query instruction queries the double array dictionary tree to obtain a location point in a query domain, wherein the query instruction includes a query location point and a query distance range; the location point in the query domain is verified to obtain a target location point.
- FIG. 1 is a schematic flowchart of a location query method based on double arrays according to an embodiment of the application
- FIG. 2 is a schematic diagram of another flow chart of a location query method based on double arrays according to an embodiment of the application;
- FIG. 3 is a geohash accuracy table provided by an embodiment of this application.
- FIG. 4 is a base32 encoding rule table provided by an embodiment of this application.
- Fig. 5 is a preset data set provided by an embodiment of the application.
- Fig. 6 is a target data set provided by an embodiment of the application.
- FIG. 7 is an extended dictionary tree provided by an embodiment of this application.
- FIG. 8 is a schematic diagram of another flow chart of a location query method based on a double array provided by an embodiment of the application.
- FIG. 9 is another extended dictionary tree provided by an embodiment of this application.
- FIG. 10 is a double-array dictionary tree provided by an embodiment of this application.
- FIG. 11 is a schematic diagram of another flow chart of a location query method based on double arrays according to an embodiment of the application.
- FIG. 12 is a schematic diagram of another flow chart of a location query method based on double arrays according to an embodiment of the application.
- FIG. 13 is a schematic block diagram of a location query device based on double arrays according to an embodiment of the application.
- FIG. 14 is another schematic block diagram of a location query device based on double arrays according to an embodiment of the application.
- FIG. 15 is another schematic block diagram of a location query device based on double arrays according to an embodiment of the application.
- FIG. 16 is another schematic block diagram of a location query device based on double arrays according to an embodiment of the application.
- FIG. 17 is another schematic block diagram of a location query device based on double arrays according to an embodiment of the application.
- FIG. 18 is a schematic block diagram of a computer device provided by an embodiment of this application.
- FIG. 1 is a schematic flowchart of a location query method based on a double array provided by an embodiment of the application.
- the location query method based on the double array provided by the embodiment of the present application can be applied to a terminal, which includes but is not limited to a desktop computer, a tablet computer, and a laptop computer.
- the method for querying a position based on a double array includes steps S110-S150.
- S110 Encode all position points in the preset data set according to the geohash algorithm to obtain a character string corresponding to the position point, where the position point includes longitude and latitude.
- all the position points in the preset data set are encoded according to the geohash algorithm to obtain the character string corresponding to the position point, and the latitude and longitude of the position point may be binary-encoded by the dichotomy, until the number of bits of the encoding The number of digits in the preset latitude bit string and the preset longitude bit string is reached; the longitude bit string and the latitude bit string are combined by the bit interleaving method to obtain the position point bit string; and then the encoding process is performed according to the position point bit string to The character string corresponding to the position point is obtained.
- the geohash algorithm is a geocoding algorithm, through which the geohash algorithm can map multi-dimensional spatial targets into one-dimensional targets, and then realize location query based on one-dimensional index structure.
- the preset data set is a set composed of multiple location points, and the location points are composed of longitude and latitude.
- step S110 includes but is not limited to steps S111-S113.
- S111 Binary encoding the longitude and latitude of all the position points in the preset data set according to the preset encoding length through the dichotomy to obtain the longitude bit string and the latitude bit string.
- the preset code length is the geohash code length of the location point, and the preset code length is determined according to the geohash accuracy table according to the actual situation. For example, when the preset code length is 8, it represents an area of about 20 meters in size, which can meet the minimum query requirements under normal circumstances. Therefore, this solution specifies the preset code length as 8, and the number of bits in the position string obtained is 40. The preset number of latitude string is 20, and the preset number of longitude string is 20.
- 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. For example, given a location point (19.596412-99.219501), 19.596412 is in the right interval and coded as 1, then [0,90] is divided into [0,45) and [45,90], 19.596412 is in the left interval and coded as 0, and so on until the length of the latitude bit string is 20, and the final latitude bit string is 10011011110111101101. In the same way, the obtained longitude bit string is 00111001011100011010.
- S112 Combine 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 position point string.
- 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, the combined position point string 0100101111000111011110110101011011001.
- S113 Encode the position point string according to the character encoding rule to obtain a character string corresponding to the position point.
- the character encoding rule may be a Base32 encoding rule.
- the Base32 encoding rule is a data encoding mechanism used to encode binary data into a string.
- the encoding rule is: given a binary data arbitrarily, it is divided into a group of 5 bits, and the division is Each group is encoded to get 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.
- S120 Sort and number all the position points in the preset data set and the character strings corresponding to the position points in lexicographic order to obtain a target data set, and construct an extended dictionary tree according to the target data set.
- lexicographic order is a method of arranging strings in alphabetical order, that is, sorting the strings according to the lexicographic order to obtain the serial number of each string, and assigning the serial number to the position corresponding to the string point.
- the target data set includes one or more rows of data, and each row of data consists of the number, latitude, longitude, and corresponding character strings of the location point. For example, to sort 9g3rqpqt and 9g3rw04d in lexicographical order, then 9g3rw04d is 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 target data set.
- the preset data set is a collection of 10 location points, and the location points are composed of longitude and latitude.
- the geohash algorithm all the position points in the preset data set are encoded to obtain the character string corresponding to the position point, and then all the position points in the preset data set and the character string corresponding to the position point are performed lexicographically. Sort and number to get the target data set.
- the obtained target data set includes 10 rows of data, and each row of data is composed of the position number, latitude, longitude, and corresponding character strings.
- the dictionary tree (Trie tree) is a variant of the hash tree, used to count, sort, and store a large number of strings. It can use the common prefix of the string to reduce query time and storage space to maximize Reduce unnecessary string comparison, 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.
- FIG. 7 is an extended dictionary tree provided by an embodiment of this application.
- Constructing the extended dictionary tree according to the target data set is specifically: inserting each character of the string into the node of the dictionary tree in turn, before inserting, it is necessary to find whether the prefix exists, if it exists, share the common prefix, if it does not exist Then create the corresponding nodes and edges, and follow the aforementioned operations until all the strings are stored in the dictionary tree, thereby constructing the dictionary tree.
- 9g3rqpqt and 9g3rw04d first insert each character of 9g3rw04d in turn, and then insert 9g3rqpqt, 9g3rqpqt first traverses the dictionary tree when inserting, because 9g3r already exists in the dictionary tree, just add node q after the r node. After that, a p node is added after the q node, and the nodes q and t are added in sequence.
- the dictionary tree node is expanded to obtain an expanded dictionary tree.
- the starting number and the number of the prefix of the current node 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 number. Only the r node needs to be queried. The number and number corresponding to the r node can get all the numbers in the query domain.
- the double-array dictionary tree includes a BASE array and a TAIL array.
- Step S130 includes but is not limited to steps S131-S132.
- S131 Acquire the number of prefixes corresponding to each character in the character string in sequence according to the character sequence of the character string.
- FIG. 9 is another extended dictionary tree provided by an embodiment of this application.
- the number of prefixes corresponding to each character in the character string is sequentially obtained according to the character sequence of the character string, so as to find a prefix part that can distinguish the current character string from other character strings.
- the expression form of the double-array dictionary tree is: it is composed of two equal-length one-dimensional integer arrays BASE array and CHECK array, and a character array TAIL array storing suffixes.
- the BASE array stores the base value and the starting ID and the number of the state transition
- the CHECK array stores the check value to detect the correctness of the state transition.
- CODE[c] represents the numerical code of the character c.
- the code values corresponding to the characters "0", “1", “2”!z” correspond to 1, 2 respectively , 3 «31.
- BASE[i] and CHECK[i] are all 0 indicating that the position is empty, and the BASE value is a negative number, it is a terminating state, and the absolute value indicates the beginning of the suffix part of the string stored in the TAIL array position.
- the prefix part corresponding to the current character can distinguish the current character string from other character strings.
- the number of prefixes corresponding to the character "2" in the character string “2jt” shown in Figure 9 is equal to one, and it is determined that the character "2" can be distinguished from other character strings, and the prefix part corresponding to the character “2" "2” is stored in the BASE array of the double array dictionary tree.
- the suffix part "jt" corresponding to the character "2" in the character string "2jt” is stored in the TAIL array of the double array dictionary tree.
- the double-array dictionary tree converted from the extended dictionary tree shown in Fig. 9 is shown in Fig. 10.
- Fig. 10 the double-array dictionary tree converted from the extended dictionary tree shown in Fig. 9 is shown in Fig. 10.
- S140 If a query instruction is received, query the double-array dictionary tree according to the query instruction to obtain a location point in the query domain, where the query instruction includes a query location point and a query distance range.
- step S140 includes but is not limited to steps S141-S143.
- S141 Determine the code 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 character string of the code length through a geohash algorithm.
- 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 encoded into p-bit characters through the geohash algorithm String; where the area range distance corresponding to p is not less than d and the minimum value, for example, the query distance d is 500 meters, then 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 encoded by the geohash algorithm to obtain the corresponding character string. This process is the same as the geohash encoding process described above, and will not be repeated here.
- S142 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 one.
- 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
- S143 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 double array dictionary tree to obtain a location point in the query domain.
- the double-array dictionary tree is traversed according to the character string at the query location and the character strings in the eight surrounding areas, the double-array dictionary tree is searched for the same character string, and if there is, the character is returned
- the position point ID corresponding to the string is the position point in the query domain.
- the string corresponding to the query field is "4q”
- jump to BASE[6] according to the formula BASE[1]+5 6
- S150 Verify the location point in the query domain to obtain a target location point.
- step S150 includes but is not limited to steps S151-S154.
- S151 Calculate the longitude range and 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].
- S152 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 query result is filtered according to the range of latitude and longitude, and the returned number ID corresponds to the location point in the target data set to obtain the location point candidate set.
- the latitude and longitude corresponding to ID 1 is (19.600038-99.22491)
- 19.600038 in the query location point (19.596412-99.219501) is located in [19.591917,19.600907]
- the -99.22491 is not located in [-99.224272,-99.214730], so the location with ID 1 is filtered. 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.
- S153 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 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, and the query range distance is 500 meters. Calculate the distance between the location point and the query location point (19.596412-99.219501). After calculation, if If the distance is less than 500 meters, the location point meets the spatial range query condition, and the location point is returned as a location point within the query area.
- FIG. 13 is a schematic block diagram of a position query device 100 based on a double array provided by an embodiment of the present application. As shown in FIG. 13, corresponding to the position query method based on the double array, the present application also provides a position query device 100 based on the double array.
- the dual array-based location query device 100 includes a unit for executing the above-mentioned dual array-based location query method.
- the device 100 can be configured in a desktop computer, a tablet computer, a laptop computer, and other terminals.
- the device 100 includes an encoding unit 110, a construction unit 120, a conversion unit 130, a query unit 140 and a verification unit 150.
- the encoding unit 110 is configured to encode all location points in the preset data set according to the geohash algorithm to obtain a character string corresponding to the location point, where the location point includes longitude and latitude.
- the encoding unit 110 includes a first generating unit 111, a combining unit 112 and a second generating unit 113.
- the first generating unit 111 is configured to perform binary encoding on the longitude and latitude of all the position points in the preset data set by the dichotomy according to the preset encoding length to obtain the longitude bit string and the latitude bit string.
- the merging unit 112 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 position point string.
- the second generating unit 113 is configured to encode the position point string according to the character encoding rule to obtain the character string corresponding to the position point.
- the constructing unit 120 is configured to sort and number all the position points in the preset data set and the character strings corresponding to the position points in lexicographic order to obtain a target data set, and construct an extended dictionary tree according to the target data set .
- the conversion unit 130 is configured to convert the extended dictionary tree into a double-array dictionary tree.
- the conversion unit 130 includes a first acquisition unit 131 and a storage unit 132.
- the first obtaining unit 131 is configured to sequentially obtain the number of prefixes corresponding to each character in the character string according to the character sequence of the character string.
- the storage unit 132 is configured to, if the number of prefixes corresponding to the characters in the character string is equal to one, store the prefix part corresponding to the character in the BASE array of the double array dictionary tree, and store the suffix part corresponding to the character Stored in the TAIL array of the double array dictionary tree.
- the query unit 140 is configured to query the double array dictionary tree according to the query instruction to obtain a location point in the query domain if a query instruction is received, wherein the query instruction includes a query location point and a query distance range.
- the query unit 140 includes a determination unit 141, a second acquisition unit 142, and a third generation unit 143.
- the determining unit 141 is configured to determine the code 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 character string of the code length through the geohash algorithm.
- the second acquiring unit 142 is configured to acquire character strings in eight areas around the character string corresponding to the query location point.
- the third generating unit 143 is configured to use the character string corresponding to the query location point and the character strings in the eight regions around the character string corresponding to the query location point as query fields to query the double array dictionary tree to obtain the query The location point within the domain.
- the verification unit 150 is configured to verify the location point in the query domain to obtain the target location point.
- the verification unit 150 includes a calculation unit 151, a filtering unit 152, a comparison unit 153 and a returning unit 154.
- the calculation unit 151 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 152 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 comparison unit 153 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 154 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 above-mentioned apparatus 100 may be implemented in the form of a computer program, and the computer program may be run on a computer device as shown in FIG. 18.
- FIG. 18 is a schematic block diagram of a computer device according to an embodiment of the present application.
- the computer device 500 may be in a server.
- the server may be an independent server or a server cluster composed of multiple servers.
- the computer device 500 includes a processor 520, a memory, and a network interface 550 connected through a system bus 510, where the memory may include a non-volatile storage medium 530 and an internal memory 540.
- the non-volatile storage medium 530 can store an operating system 531 and a computer program 532.
- the processor 520 can execute a position query method based on a double array.
- the processor 520 is used to provide calculation and control capabilities, and support the operation of the entire computer device 500.
- the internal memory 540 provides an environment for running a computer program in a non-volatile storage medium.
- the processor 520 can make the processor 520 execute a position query method based on a double array.
- the network interface 550 is used for network communication with other devices.
- the schematic block diagram of the computer device 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 It may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.
- the processor 520 is configured to run the program code stored in the memory to implement the position query method based on the double array in the embodiment of the present application.
- the processor 520 may be a central processing unit (Central Processing Unit, CPU), and the processor 520 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 schematic block diagram of the computer device 500 does not constitute a limitation on the computer device 500, and may include more or less components than shown, or a combination of certain components, or different component arrangements.
- a computer-readable storage medium stores a computer program.
- the processor executes the The steps of the double array position query method.
- the computer-readable storage medium may be a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a magnetic disk, or an optical disk, etc., which can store program codes.
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)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
一种基于双数组的位置查询方法、装置、计算机设备及存储介质,应用于数据处理中的数据查询领域。该方法包括:根据geohash算法对预设数据集中的所有位置点进行编码以得到位置点对应的字符串(S110);按照字典序对预设数据集中的所有位置点以及位置点对应的字符串进行排序和编号以得到目标数据集,并根据目标数据集构建扩展字典树(S120);将扩展字典树转换为双数组字典树(S130);若接收到查询指令,根据查询指令查询双数组字典树以获取查询域内的位置点(S140);对查询域内的位置点进行验证以得到目标位置点(S150)。
Description
本申请要求于2019年10月14日提交中国专利局、申请号为201910974408.1、申请名称为“位置查询方法、装置、计算机设备及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
本申请涉及计算机数据处理领域,尤其涉及一种基于双数组的位置查询方法、装置、计算机设备及计算机可读存储介质。
近年来,随着智能手机、平板电脑等移动设备的普及,基于桌面的互联网时代已转向移动互联网时代。与此同时,随着定位技术的发展,如:GPS、3G、4G、WiFi等,导致产生了大量具有位置属性的数据,且数据量急剧增长。如何快速返回所需信息是空间文本查询领域一个核心的科研课题,鉴于geohash可将空间查询问题转化为字符串前缀匹配问题,geohash编码表示一区域,区域越小,前缀越长。字典树(Trie)将字符串的公共前缀压缩为字典树(Trie)中一条路径,以实现对前缀部分的高效查询,故通常融合geohash与Trie以支持空间查询。不足的是,面向任意空间范围查询时,均需访问到叶子节点以获取满足查询条件的记录,很大程度降低了检索效率,用户体验差。此外,构建完全Trie导致占用大量存储空间。
发明内容
本申请实施例提供了一种基于双数组的位置查询方法、装置、计算机设备及存储介质,旨在解决位置查询准确度低、识别速度慢等问题。
第一方面,本申请实施例提供了一种基于双数组的位置查询方法,其包括:根据geohash算法对预设数据集中的所有位置点进行编码以得到所述位置点对应的字符串,其中,所述位置点包括经度和纬度;按照字典序对所述预设数据 集中的所有位置点以及所述位置点对应的字符串进行排序和编号以得到目标数据集,并根据所述目标数据集构建扩展字典树;将所述扩展字典树转换为双数组字典树;若接收到查询指令,根据所述查询指令查询所述双数组字典树以获取查询域内的位置点,其中,所述查询指令包括查询位置点以及查询距离范围;对所述查询域内的位置点进行验证以得到目标位置点。
第二方面,本申请实施例提供了一种基于双数组的位置查询装置,其包括:编码单元,用于根据geohash算法对预设数据集中的所有位置点进行编码以得到所述位置点对应的字符串,其中,所述位置点包括经度和纬度;构建单元,用于按照字典序对所述预设数据集中的所有位置点以及所述位置点对应的字符串进行排序和编号以得到目标数据集,并根据所述目标数据集构建扩展字典树;转换单元,用于将所述扩展字典树转换为双数组字典树;查询单元,用于若接收到查询指令,根据所述查询指令查询所述双数组字典树以获取查询域内的位置点,其中,所述查询指令包括查询位置点以及查询距离范围;验证单元,用于对所述查询域内的位置点进行验证以得到目标位置点。
第三方面,本申请实施例还提供了一种计算机设备,其包括存储器以及与所述存储器相连的处理器;所述存储器用于存储计算机程序;所述处理器用于运行所述存储器中存储的计算机程序,以执行如下步骤:根据geohash算法对预设数据集中的所有位置点进行编码以得到所述位置点对应的字符串,其中,所述位置点包括经度和纬度;按照字典序对所述预设数据集中的所有位置点以及所述位置点对应的字符串进行排序和编号以得到目标数据集,并根据所述目标数据集构建扩展字典树;将所述扩展字典树转换为双数组字典树;若接收到查询指令,根据所述查询指令查询所述双数组字典树以获取查询域内的位置点,其中,所述查询指令包括查询位置点以及查询距离范围;对所述查询域内的位置点进行验证以得到目标位置点。
第四方面,本申请实施例还提供了一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时使所述处理器执行以下步骤:根据geohash算法对预设数据集中的所有位置点进行编码以得到所述位置点对应的字符串,其中,所述位置点包括经度和纬度;按照字典序对所述预设数据集中的所有位置点以及所述位置点对应的字符串进行排序和编号以得到目标数据集,并根据所述目标数据集构建扩展字典树;将所述扩展字 典树转换为双数组字典树;若接收到查询指令,根据所述查询指令查询所述双数组字典树以获取查询域内的位置点,其中,所述查询指令包括查询位置点以及查询距离范围;对所述查询域内的位置点进行验证以得到目标位置点。
为了更清楚地说明本申请实施例技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1为本申请一实施例提供的一种基于双数组的位置查询方法的流程示意图;
图2为本申请一实施例提供的一种基于双数组的位置查询方法的另一流程示意图;
图3为本申请一实施例提供的一种geohash精度表;
图4为本申请一实施例提供的base32编码规则表;
图5为本申请一实施例提供的预设数据集;
图6为本申请一实施例提供的目标数据集;
图7为本申请一实施例所提供的扩展字典树;
图8为本申请一实施例提供的一种基于双数组的位置查询方法的另一流程示意图;
图9为本申请一实施例所提供的另一扩展字典树;
图10为本申请一实施例所提供的双数组字典树;
图11为本申请一实施例提供的一种基于双数组的位置查询方法的另一流程示意图;
图12为本申请一实施例提供的一种基于双数组的位置查询方法的另一流程示意图;
图13为本申请一实施例提供的一种基于双数组的位置查询装置的示意性框图;
图14为本申请一实施例提供的一种基于双数组的位置查询装置的另一示意性框图;
图15为本申请一实施例提供的一种基于双数组的位置查询装置的另一示意性框图;
图16为本申请一实施例提供的一种基于双数组的位置查询装置的另一示意性框图;
图17为本申请一实施例提供的一种基于双数组的位置查询装置的另一示意性框图;
图18为本申请一实施例提供的一种计算机设备的示意性框图。
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
应当理解,当在本说明书和所附权利要求书中使用时,术语“包括”和“包含”指示所描述特征、整体、步骤、操作、元素和/或组件的存在,但并不排除一个或一个以上其它特征、整体、步骤、操作、元素、组件和/或其集合的存在或添加。
还应当理解,在此本申请说明书中所使用的术语仅仅是出于描述特定实施例的目的而并不意在限制本申请。如在本申请说明书和所附权利要求书中所使用的那样,除非上下文清楚地指明其它情况,否则单数形式的“一”、“一个”及“该”意在包括复数形式。
请参照图1,其为本申请一实施例提供的一种基于双数组的位置查询方法的流程示意图。本申请实施例所提供的基于双数组的位置查询方法可应用于终端中,所述终端包括但不限于台式电脑、平板电脑、手提电脑。如图1所示,该基于双数组的位置查询方法包括步骤S110-S150。
S110,根据geohash算法对预设数据集中的所有位置点进行编码以得到所述位置点对应的字符串,其中,所述位置点包括经度和纬度。
具体地,所述根据geohash算法对预设数据集中的所有位置点进行编码以得到所述位置点对应的字符串,可通过二分法对位置点的纬度和经度进行二进制编码,直到编码的位数达到预设纬度位串和预设经度位串的位数为止;再通过 位交错方法合并经度位串和纬度位串从而得到位置点位串;进而根据所述位置点位串进行编码处理,以得出所述位置点对应的字符串。
其中,geohash算法是一种地理编码算法,通过geohash算法可实现将多维的空间目标映射成一维目标,进而基于一维索引结构实现位置查询。预设数据集为由多个位置点组成的集合,位置点由经度和纬度组成。
在一些实施例中,如图2所示,步骤S110包括但不限于步骤S111-S113。
S111,根据预设编码长度通过二分法对预设数据集中所有位置点的经度和纬度进行二进制编码以得到经度位串和纬度位串。
具体实施中,请参照图3,其为本申请实施例提供的一种geohash精度表。其中,预设编码长度为位置点的geohash编码长度,预设编码长度依据geohash精度表根据实际情况而定。例如,预设编码长度为8时,表示大小为20米左右的区域范围,通常情况下能满足最小查询需求,故而本方案将预设编码长度指定为8,得到的位置点位串位数为40,其中预设纬度位串位数为20,预设经度位串位数为20。
具体地,地球的纬度区间为[-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。
S112,根据奇数位为纬度、偶数位为经度的规则将所述经度位串和纬度位串进行合并以得到位置点位串。
在一实施例中,在得到经度位串和纬度位串后,将经度位串和纬度位串进行合并以得到位置点位串,从而将二维位置点映射为一维位串。具体地,根据奇数位为纬度、偶数位为经度的规则,对经度位串和纬度位串进行合并。例如,纬度位串为10011011110111101101,经度位串为00111001011100011010,根据 偶数位为经度,则位置点位串的第一位取经度位串的第一位数字0,根据奇数位为纬度,则位置点位串的第二位取纬度位串的第一位数字1;位置点位串的第三位取经度位串的第二位数字0,位置点位串的第四位取纬度位串的第二位数字0;以此类推,合并后的位置点位串0100101111000111011110110101011011011001。
S113,根据字符编码规则对所述位置点位串进行编码以得到所述位置点对应的字符串。
具体实施中,请参照图4,其为本申请一实施例提供的base32编码规则表。本申请实施例中,字符编码规则可以是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。
S120,按照字典序对所述预设数据集中的所有位置点以及所述位置点对应的字符串进行排序和编号以得到目标数据集,并根据所述目标数据集构建扩展字典树。
具体地,在所述预设数据集中的所有位置点转换为字符串后,按照字典序对所有的位置点进行排序,以得到目标数据集。其中,每一个位置点对应唯一的字符串,在对所述预设数据集中的所有位置点以及所述位置点对应的字符串进行排序和编号时,所述位置点的编号与所述位置点对应的字符串的编号相同。本申请实施例中,字典序是按字母顺序排列字符串的方法,即根据字典序对字符串进行排序,以得出每个字符串的编号,并将该编号赋予与该字符串对应的位置点。
所述目标数据集包括一行或者多行的数据,每行数据由位置点的编号、纬度、经度以及对应的字符串组成。例如,按照字典序对9g3rqpqt和9g3rw04d进行排序,那么9g3rw04d排在9g3rqpqt前面,9g3rw04d对应的位置点排在9g3rqpqt对应的位置点前面,9g3rw04d对应的位置点编号为1,9g3rqpqt对应的位置点编 号为2,从而组成目标数据集。
例如,如图5所示,其为本申请一实施例提供的预设数据集。预设数据集为由10个位置点组成的集合,位置点由经度和纬度组成。根据geohash算法对预设数据集中的所有位置点进行编码以得到所述位置点对应的字符串,进而按照字典序对所述预设数据集中的所有位置点以及所述位置点对应的字符串进行排序和编号以得到目标数据集。
如图6所示,其为本申请一实施例提供的目标数据集。所得到的目标数据集包括10行数据,每行数据由位置点的编号、纬度、经度以及对应的字符串组成。
具体实施中,字典树(Trie树)是一种哈希树的变种,用于统计、排序和保存大量的字符串,其可利用字符串的公共前缀来减少查询时间与存储空间,最大限度地减少无谓的字符串比较,查询效率高。字典树包括根节点和叶子节点,根节点不包括字符,根节点外每一个节点都包括一个字符;从根节点到某一节点,路径上经过的字符连接起来为该节点对应的字符串;每个节点的所有子节点包括的字符都不相同。
具体地,请参照图7,其为本申请一实施例所提供的扩展字典树。根据所述目标数据集构建扩展字典树具体为:将字符串的每个字符依次***到字典树的节点中,***前需要先查找前缀是否存在,若存在则共享公共前缀即可,若不存在则创建对应的节点和边,按前述操作,直到所有的字符串都存储到字典树中,从而构建字典树。例如,***9g3rqpqt和9g3rw04d,首先依次***9g3rw04d的每个字符,然后再***9g3rqpqt,9g3rqpqt在***时先遍历字典树,由于9g3r在字典树中已存在,只需在r节点后新增节点q,之后在q节点后面新增p节点,依次新增节点q、t。
具体实施中,为了提高空间查询效率,对字典树节点进行扩展以得到扩展字典树。具体地,在字典树的节点中增加包含当前节点前缀的起始编号及其个数,使得对较大范围的空间查询,仅需访问从根到某个内部节点的路径即可,而无需访问到叶节点,从而提高空间范围查询响应速率。例如,在查询的字符串为9g3r,其表示一个较大的空间查询范围,相对于字典树,查询扩展字典树,不需要遍历到叶节点才能获取对应的编号,只需要查询到r节点,根据r节点对应的编号和个数即可获取到该查询域内的所有编号。
S130,将所述扩展字典树转换为双数组字典树。
在一些实施例中,如图8所示,所述双数组字典树包括BASE数组以及TAIL数组。步骤S130包括但不限于步骤S131-S132。
S131,根据所述字符串的字符顺序依次获取所述字符串中每个字符对应的前缀个数。
为便于阐述,请参照图9,其为本申请一实施例所提供的另一扩展字典树。根据所述字符串的字符顺序依次获取所述字符串中每个字符对应的前缀个数,以寻找出可区分将当前字符串与其它字符串的前缀部分。
S132,若所述字符串中字符对应的前缀个数等于一,将所述字符对应的前缀部分储存至所述双数组字典树的BASE数组,以及将所述字符对应的后缀部分储存至所述双数组字典树的TAIL数组。
具体地,双数组字典树表现形式为:由两个等长的一维整数数组BASE数组和CHECK数组,以及存储后缀的字符数组TAIL数组组成。其中BASE数组存储状态转移的基值与起始ID及其个数,CHECK数组存储校验值,用于检测状态转移的正确性。在构建双数组时,输入一个字符c,从状态s转移到状态t需要满足如下两个关系式:
BASE[s]+CODE[c]=t
CHECK[t]=s
其中,CODE[c]表示字符c的数值编码,对Base32编码规则中对应的字符而言,字符“0”,“1”,“2”……“z”对应的编码值分别对应1,2,3……31。对数组下标i,BASE[i]和CHECK[i]均为0表明该位置为空,BASE值为负数时为可终止状态,绝对值表示字符串的后缀部分存储在TAIL数组中的起始位置。
若所述字符串中每个字符对应的前缀个数等于一,则确定当前字符所对应的前缀部分可区分将当前字符串与其它字符串。例如,图9所示的字符串“2jt”中的字符“2”对应的前缀个数等于一,则确定字符“2”可以和其他字符串相区分,进而字符“2”所对应的前缀部分“2”储存至所述双数组字典树的BASE数组。同时,将字符串“2jt”中的字符“2”对应的后缀部分“jt”储存至所述双数组字典树的TAIL数组。
根据上述关系式,图9所示出的扩展字典树所转换得出的双数组字典树具 体如图10所示。实施本申请实施例,通过将扩展字典树转换为双数组字典树,可实现在保持空间查询效率的前提下,减少构建完全Trie的存储空间开销。
S140,若接收到查询指令,根据所述查询指令查询所述双数组字典树以获取查询域内的位置点,其中,所述查询指令包括查询位置点以及查询距离范围。
在一些实施例中,如图11所示,步骤S140包括但不限于步骤S141-S143。
S141,根据所述查询范围距离以及geohash精度表确定所述查询位置点的编码长度,并通过geohash算法将所述查询位置点编码为所述编码长度的字符串。
在一实施例中,给定查询位置点与查询范围距离,根据geohash精度表选定与查询范围距离d相对应的geohash编码长度p,通过geohash算法将查询位置点q编码为p位长度的字符串;其中,p对应的区域范围距离不小于d且为最小值,例如查询距离d为500米,则geohash编码长度p为6,P对应的区域范围距离为610,大于查询距离d且为最小,在确定geohash编码长度之后,则通过geohash算法对查询位置点进行编码得到对应的字符串,该过程与上述geohash编码的过程相同,在此不再赘述。
S142,获取所述查询位置点对应的字符串周围八个区域的字符串。
在一实施例中,周围八个区域具体指的是东西南北方区域、东南方区域、东北方区域,西南方区域以及西北方区域。具体地,在得到查询位置点的字符串后,根据查询位置的字符串的纬度位串和经度位串计算周围八个区域的字符串对应的纬度位串和经度位串。
其中,北方区域的字符串对应的纬度位串等于查询位置点的字符串的纬度位串,北方区域的字符串对应的经度位串等于查询位置点的字符串的经度位串加1。
南方区域的字符串对应的纬度位串等于查询位置点的字符串的纬度位串,南方区域的字符串对应的经度位串等于查询位置点的字符串的经度位串减1。
东方区域的字符串对应的纬度位串等于查询位置点的字符串的纬度位串加1,东方区域的字符串对应的经度位串等于查询位置点的字符串的经度位串。
西方区域的字符串对应的纬度位串等于查询位置点的字符串的纬度位串减1,东方区域的字符串对应的经度位串等于查询位置点的字符串的经度位串。
东北方区域的字符串对应的纬度位串等于查询位置点的字符串的纬度位串加1,东北方区域的字符串对应的经度位串等于查询位置点的字符串的经度位串 加1。
西北方区域的字符串对应的纬度位串等于查询位置点的字符串的纬度位串减1,西北方区域的字符串对应的经度位串等于查询位置点的字符串的经度位串加1。
东南方区域的字符串对应的纬度位串等于查询位置点的字符串的纬度位串加1,东南方区域的字符串对应的经度位串等于查询位置点的字符串的经度位串减1。
西南方区域的字符串对应的纬度位串等于查询位置点的字符串的纬度位串减1,西南方区域的字符串对应的经度位串等于查询位置点的字符串的经度位串减1。
例如,位置点的字符串为9g3rqp,其对应的纬度位串为100110111101111,经度位串为001110010111000,那么其北方区域的字符串对应的纬度位串则为100110111101111,经度位串则为001110010111000+1=001110010111001。在计算完经度位串和纬度位串后,再将经度位串和纬度位串合并,接着根据base32对合并后的位置点位串进行编码得到字符串,最终得到查询位置点周围的八个区域的字符串。
S143,将所述查询位置点对应的字符串以及所述查询位置点对应的字符串周围八个区域的字符串作为查询域查询所述双数组字典树以得到所述查询域内的位置点。
在一实施例中,根据查询位置点的字符串以及周围八个区域的字符串遍历所述双数组字典树,在所述双数组字典树查找是否具有相同的字符串,若有则返回该字符串对应的位置点编号ID即为查询域内位置点。
具体地,基于双数组字典树进行位置点查询的过程为:根据查询域对应的字符串,依据公式BASE[s]+c=t进行查询,若t为负数或查询字符串已跳转至最后一个字符,则返回对应的起始ID及其个数,即为该查询域内对应的位置点,反之,迭代前述步骤。例如:查询域对应的字符串为“4q”,根据公式BASE[1]+5=6跳转至BASE[6],之后根据BASE[6]+23=29跳转至BASE[29],因已跳转至查询域对应字符串最后一个字符,[2,2]对应位置点编号为2、3,即为该查询域内对应的位置点。
S150,对所述查询域内的位置点进行验证以得到目标位置点。
在一些实施例中,如图12所示,步骤S150包括但不限于步骤S151-S154。
S151,根据所述查询位置点以及所述查询范围距离通过预设公式计算所述查询位置点的经度范围和纬度范围。
在一实施例中,根据查询位置点以及查询范围距离通过预设公式计算求出经度范围和纬度范围。预设公式如下:
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]。
S152,根据所述查询位置点的经度范围和纬度范围对所述查询域内的位置点进行过滤得到候选集。
具体实施中,根据经纬度范围过滤查询结果返回编号ID对应于目标数据集中的位置点,得到位置点候选集。假设查询结果返回的ID集中,ID为1对应的经纬度为(19.600038-99.22491),查询位置点(19.596412-99.219501)中的19.600038位于[19.591917,19.600907]内,而查询位置点(19.596412-99.219501)中的-99.22491不位于[-99.224272,-99.214730]内,故过滤ID为1的位置点。只有位置点的经度值和纬度值均落入经度范围和纬度范围的才保留该位置点,从而筛选掉不在经纬度范围内的位置点,最终得到候选集。
S153,计算所述候选集中的位置点到所述查询位置点的距离,并将所述候选集中的位置点到所述查询位置点的距离与所述查询范围距离进行对比。
在一实施例中,根据预设公式计算候选集中的位置点到查询位置点的距离, 其中,预设公式如下:
其中,A(x
1,y
1)为候选集中的位置点,B(x
2,y
2)为查询位置点,|AB|为候选集中的位置点到查询位置点的距离。
S154,若所述候选集中的位置点到所述查询位置点的距离不大于所述查询范围距离,则将所述候选集中的位置点作为目标位置点返回。
在一实施例中,例如,(19.59918,-99.21667)为候选集中一个位置点,查询范围距离为500米,计算该位置点到查询位置点(19.596412-99.219501)之间的距离,经计算,若该距离小于500米,则该位置点满足空间范围查询条件,将该位置点作为查询区域范围内的位置点返回。
图13是本申请实施例提供的一种基于双数组的位置查询装置100的示意性框图。如图13所示,对应于以上基于双数组的位置查询方法,本申请还提供一种基于双数组的位置查询装置100。该基于双数组的位置查询装置100包括用于执行上述基于双数组的位置查询方法的单元,该装置100可以被配置于台式电脑、平板电脑、手提电脑、等终端中。具体地,请参阅图13,所述装置100包括编码单元110、构建单元120、转换单元130、查询单元140以及验证单元150。
编码单元110,用于根据geohash算法对预设数据集中的所有位置点进行编码以得到所述位置点对应的字符串,其中,所述位置点包括经度和纬度。
在一些实施例中,如图14所示,所述编码单元110包括第一生成单元111、合并单元112以及第二生成单元113。
第一生成单元111,用于根据预设编码长度通过二分法对预设数据集中所有位置点的经度和纬度进行二进制编码以得到经度位串和纬度位串。合并单元112,用于根据奇数位为纬度、偶数位为经度的规则将所述经度位串和纬度位串进行合并以得到位置点位串。第二生成单元113,用于根据字符编码规则对所述位置点位串进行编码以得到所述位置点对应的字符串。构建单元120,用于按照字典序对所述预设数据集中的所有位置点以及所述位置点对应的字符串进行排序和编号以得到目标数据集,并根据所述目标数据集构建扩展字典树。转换单元130,用于将所述扩展字典树转换为双数组字典树。
在一些实施例中,如图15所示,所述转换单元130包括第一获取单元131 以及储存单元132。
第一获取单元131,用于根据所述字符串的字符顺序依次获取所述字符串中每个字符对应的前缀个数。储存单元132,用于若所述字符串中字符对应的前缀个数等于一,将所述字符对应的前缀部分储存至所述双数组字典树的BASE数组,以及将所述字符对应的后缀部分储存至所述双数组字典树的TAIL数组。查询单元140,用于若接收到查询指令,根据所述查询指令查询所述双数组字典树以获取查询域内的位置点,其中,所述查询指令包括查询位置点以及查询距离范围。
在一些实施例中,如图16所示,所述查询单元140包括确定单元141、第二获取单元142以及第三生成单元143。
确定单元141,用于根据所述查询范围距离以及geohash精度表确定所述查询位置点的编码长度,并通过geohash算法将所述查询位置点编码为所述编码长度的字符串。第二获取单元142,用于获取所述查询位置点对应的字符串周围八个区域的字符串。第三生成单元143,用于将所述查询位置点对应的字符串以及所述查询位置点对应的字符串周围八个区域的字符串作为查询域查询所述双数组字典树以得到所述查询域内的位置点。验证单元150,用于对所述查询域内的位置点进行验证以得到目标位置点。
在一些实施例中,如图17所示,所述验证单元150包括计算单元151、过滤单元152、对比单元153以及返回单元154。
计算单元151,用于根据所述查询位置点以及所述查询范围距离通过预设公式计算所述查询位置点的经度范围和纬度范围。过滤单元152,用于根据所述查询位置点的经度范围和纬度范围对所述查询域内的位置点进行过滤得到候选集。对比单元153,用于计算所述候选集中的位置点到所述查询位置点的距离,并将所述候选集中的位置点到所述查询位置点的距离与所述查询范围距离进行对比。
返回单元154,用于若所述候选集中的位置点到所述查询位置点的距离不大于所述查询范围距离,则将所述候选集中的位置点作为目标位置点返回。
需要说明的是,所属领域的技术人员可以清楚地了解到,上述基于双数组的位置查询装置100和各单元的具体实现过程,可以参考前述方法实施例中的相应描述,为了描述的方便和简洁,在此不再赘述。
上述装置100可以实现为一种计算机程序的形式,计算机程序可以在如图 18所示的计算机设备上运行。
请参阅图18,图18是本申请实施例提供的一种计算机设备的示意性框图。该计算机设备500可以是服务器中。其中,所述服务器可以是独立的服务器,也可以是多个服务器组成的服务器集群。
该计算机设备500包括通过***总线510连接的处理器520、存储器和网络接口550,其中,存储器可以包括非易失性存储介质530和内存储器540。
该非易失性存储介质530可存储操作***531和计算机程序532。该计算机程序532被执行时,可使得处理器520执行一种基于双数组的位置查询方法。
该处理器520用于提供计算和控制能力,支撑整个计算机设备500的运行。
该内存储器540为非易失性存储介质中的计算机程序的运行提供环境,该计算机程序被处理器520执行时,可使得处理器520执行一种基于双数组的位置查询方法。
该网络接口550用于与其它设备进行网络通信。本领域技术人员可以理解,该计算机设备的示意性框图仅仅是与本申请方案相关的部分结构的框图,并不构成对本申请方案所应用于其上的计算机设备500的限定,具体的计算机设备500可以包括比图中所示更多或更少的部件,或者组合某些部件,或者具有不同的部件布置。
其中,所述处理器520用于运行存储在存储器中的程序代码,以实现本申请实施例的基于双数组的位置查询方法。
应当理解,在本申请实施例中,处理器520可以是中央处理单元(Central Processing Unit,CPU),该处理器520还可以是其他通用处理器、数字信号处理器(Digital Signal Processor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现成可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。其中,通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。
本领域技术人员可以理解,该计算机设备500的示意性框图并不构成对计算机设备500的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置。
在本申请的另一实施例中提供一种计算机可读存储介质,该计算机可读存 储介质存储有计算机程序,其中计算机程序被处理器执行时使处理器执行以上各实施例中所描述的基于双数组的位置查询方法的步骤。
该计算机可读存储介质可以是U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、磁碟或者光盘等各种可以存储程序代码的介质。
以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到各种等效的修改或替换,这些修改或替换都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以权利要求的保护范围为准。
Claims (20)
- 一种基于双数组的位置查询方法,包括:根据geohash算法对预设数据集中的所有位置点进行编码以得到所述位置点对应的字符串,其中,所述位置点包括经度和纬度;按照字典序对所述预设数据集中的所有位置点以及所述位置点对应的字符串进行排序和编号以得到目标数据集,并根据所述目标数据集构建扩展字典树;将所述扩展字典树转换为双数组字典树;若接收到查询指令,根据所述查询指令查询所述双数组字典树以获取查询域内的位置点,其中,所述查询指令包括查询位置点以及查询距离范围;对所述查询域内的位置点进行验证以得到目标位置点。
- 如权利要求1所述的方法,其中,所述根据geohash算法对预设数据集中的所有位置点进行编码以得到所述位置点对应的字符串,包括:根据预设编码长度通过二分法对预设数据集中所有位置点的经度和纬度进行二进制编码以得到经度位串和纬度位串;根据奇数位为纬度、偶数位为经度的规则将所述经度位串和纬度位串进行合并以得到位置点位串;根据字符编码规则对所述位置点位串进行编码以得到所述位置点对应的字符串。
- 如权利要求1所述的方法,其中,所述双数组字典树包括BASE数组以及TAIL数组;所述将所述扩展字典树转换为双数组字典树,包括:根据所述字符串的字符顺序依次获取所述字符串中每个字符对应的前缀个数;若所述字符串中字符对应的前缀个数等于一,将所述字符对应的前缀部分储存至所述双数组字典树的BASE数组,以及将所述字符对应的后缀部分储存至所述双数组字典树的TAIL数组。
- 如权利要求1所述的方法,其中,所述根据所述查询指令查询所述双数组字典树以获取查询域内的位置点,包括:根据所述查询范围距离以及geohash精度表确定所述查询位置点的编码长度,并通过geohash算法将所述查询位置点编码为所述编码长度的字符串;获取所述查询位置点对应的字符串周围八个区域的字符串;将所述查询位置点对应的字符串以及所述查询位置点对应的字符串周围八个区域的字符串作为查询域查询所述双数组字典树以得到所述查询域内的位置点。
- 如权利要求1所述的方法,其中,所述对所述查询域内的位置点进行验证以得到目标位置点,包括:根据所述查询位置点以及所述查询范围距离通过预设公式计算所述查询位置点的经度范围和纬度范围;根据所述查询位置点的经度范围和纬度范围对所述查询域内的位置点进行过滤得到候选集;计算所述候选集中的位置点到所述查询位置点的距离,并将所述候选集中的位置点到所述查询位置点的距离与所述查询范围距离进行对比;若所述候选集中的位置点到所述查询位置点的距离不大于所述查询范围距离,则将所述候选集中的位置点作为目标位置点返回。
- 如权利要求2所述的方法,其中,所述字符编码规则为Base32编码规则。
- 如权利要求1所述的方法,其中,所述构建扩展字典树包括:在字典树的节点中增加包含当前节点前缀的起始编号及其个数以得到扩展字典树。
- 一种基于双数组的位置查询装置,包括:编码单元,用于根据geohash算法对预设数据集中的所有位置点进行编码以得到所述位置点对应的字符串,其中,所述位置点包括经度和纬度;构建单元,用于按照字典序对所述预设数据集中的所有位置点以及所述位置点对应的字符串进行排序和编号以得到目标数据集,并根据所述目标数据集构建扩展字典树;转换单元,用于将所述扩展字典树转换为双数组字典树;查询单元,用于若接收到查询指令,根据所述查询指令查询所述双数组字典树以获取查询域内的位置点,其中,所述查询指令包括查询位置点以及查询距离范围;验证单元,用于对所述查询域内的位置点进行验证以得到目标位置点。
- 如权利要求8所述的装置,其中,所述编码单元包括:第一生成单元,用于根据预设编码长度通过二分法对预设数据集中所有位置点的经度和纬度进行二进制编码以得到经度位串和纬度位串;合并单元,用于根据奇数位为纬度、偶数位为经度的规则将所述经度位串和纬度位串进行合并以得到位置点位串;第二生成单元,用于根据字符编码规则对所述位置点位串进行编码以得到所述位置点对应的字符串。
- 如权利要求8所述的装置,其中,所述转换单元包括:第一获取单元,用于根据所述字符串的字符顺序依次获取所述字符串中每个字符对应的前缀个数;储存单元,用于若所述字符串中字符对应的前缀个数等于一,将所述字符对应的前缀部分储存至所述双数组字典树的BASE数组,以及将所述字符对应的后缀部分储存至所述双数组字典树的TAIL数组。
- 一种计算机设备,包括存储器以及与所述存储器相连的处理器;所述存储器用于存储计算机程序;所述处理器用于运行所述存储器中存储的计算机程序,以执行如下步骤:根据geohash算法对预设数据集中的所有位置点进行编码以得到所述位置点对应的字符串,其中,所述位置点包括经度和纬度;按照字典序对所述预设数据集中的所有位置点以及所述位置点对应的字符串进行排序和编号以得到目标数据集,并根据所述目标数据集构建扩展字典树;将所述扩展字典树转换为双数组字典树;若接收到查询指令,根据所述查询指令查询所述双数组字典树以获取查询域内的位置点,其中,所述查询指令包括查询位置点以及查询距离范围;对所述查询域内的位置点进行验证以得到目标位置点。
- 根据权利要求11所述的计算机设备,其中,所述根据geohash算法对预设数据集中的所有位置点进行编码以得到所述位置点对应的字符串,包括:根据预设编码长度通过二分法对预设数据集中所有位置点的经度和纬度进行二进制编码以得到经度位串和纬度位串;根据奇数位为纬度、偶数位为经度的规则将所述经度位串和纬度位串进行合并以得到位置点位串;根据字符编码规则对所述位置点位串进行编码以得到所述位置点对应的字 符串。
- 根据权利要求11所述的计算机设备,其中,所述双数组字典树包括BASE数组以及TAIL数组;所述将所述扩展字典树转换为双数组字典树,包括:根据所述字符串的字符顺序依次获取所述字符串中每个字符对应的前缀个数;若所述字符串中字符对应的前缀个数等于一,将所述字符对应的前缀部分储存至所述双数组字典树的BASE数组,以及将所述字符对应的后缀部分储存至所述双数组字典树的TAIL数组。
- 根据权利要求11所述的计算机设备,其中,所述根据所述查询指令查询所述双数组字典树以获取查询域内的位置点,包括:根据所述查询范围距离以及geohash精度表确定所述查询位置点的编码长度,并通过geohash算法将所述查询位置点编码为所述编码长度的字符串;获取所述查询位置点对应的字符串周围八个区域的字符串;将所述查询位置点对应的字符串以及所述查询位置点对应的字符串周围八个区域的字符串作为查询域查询所述双数组字典树以得到所述查询域内的位置点。
- 根据权利要求11所述的计算机设备,其中,所述对所述查询域内的位置点进行验证以得到目标位置点,包括:根据所述查询位置点以及所述查询范围距离通过预设公式计算所述查询位置点的经度范围和纬度范围;根据所述查询位置点的经度范围和纬度范围对所述查询域内的位置点进行过滤得到候选集;计算所述候选集中的位置点到所述查询位置点的距离,并将所述候选集中的位置点到所述查询位置点的距离与所述查询范围距离进行对比;若所述候选集中的位置点到所述查询位置点的距离不大于所述查询范围距离,则将所述候选集中的位置点作为目标位置点返回。
- 根据权利要求12所述的计算机设备,其中,所述字符编码规则为Base32编码规则。
- 根据权利要求11所述的计算机设备,其中,所述构建扩展字典树包括:在字典树的节点中增加包含当前节点前缀的起始编号及其个数以得到扩展 字典树。
- 一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时使所述处理器执行以下步骤:根据geohash算法对预设数据集中的所有位置点进行编码以得到所述位置点对应的字符串,其中,所述位置点包括经度和纬度;按照字典序对所述预设数据集中的所有位置点以及所述位置点对应的字符串进行排序和编号以得到目标数据集,并根据所述目标数据集构建扩展字典树;将所述扩展字典树转换为双数组字典树;若接收到查询指令,根据所述查询指令查询所述双数组字典树以获取查询域内的位置点,其中,所述查询指令包括查询位置点以及查询距离范围;对所述查询域内的位置点进行验证以得到目标位置点。
- 根据权利要求18所述的计算机可读存储介质,其中,所述根据geohash算法对预设数据集中的所有位置点进行编码以得到所述位置点对应的字符串的步骤,包括:根据预设编码长度通过二分法对预设数据集中所有位置点的经度和纬度进行二进制编码以得到经度位串和纬度位串;根据奇数位为纬度、偶数位为经度的规则将所述经度位串和纬度位串进行合并以得到位置点位串;根据字符编码规则对所述位置点位串进行编码以得到所述位置点对应的字符串。
- 根据权利要求18所述的计算机可读存储介质,其中,所述双数组字典树包括BASE数组以及TAIL数组;所述将所述扩展字典树转换为双数组字典树的步骤,包括:根据所述字符串的字符顺序依次获取所述字符串中每个字符对应的前缀个数;若所述字符串中字符对应的前缀个数等于一,将所述字符对应的前缀部分储存至所述双数组字典树的BASE数组,以及将所述字符对应的后缀部分储存至所述双数组字典树的TAIL数组。
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910974408.1 | 2019-10-14 | ||
CN201910974408.1A CN111026978A (zh) | 2019-10-14 | 2019-10-14 | 位置查询方法、装置、计算机设备及存储介质 |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2021072874A1 true WO2021072874A1 (zh) | 2021-04-22 |
Family
ID=70204816
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2019/118308 WO2021072874A1 (zh) | 2019-10-14 | 2019-11-14 | 基于双数组的位置查询方法、装置、计算机设备及存储介质 |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN111026978A (zh) |
WO (1) | WO2021072874A1 (zh) |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113821539A (zh) * | 2021-09-07 | 2021-12-21 | 丰图科技(深圳)有限公司 | 区域查询方法、装置、电子设备和可读存储介质 |
CN115454993A (zh) * | 2022-07-27 | 2022-12-09 | 北京优诺信创科技有限公司 | 一种具备时空信息的空间电磁环境特征数据处理方法 |
CN116610769A (zh) * | 2023-07-19 | 2023-08-18 | 北京惠每云科技有限公司 | 一种基于双数组trie树的医疗数据空间分配方法和装置 |
Families Citing this family (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112050820B (zh) * | 2020-09-02 | 2024-05-07 | 平安科技(深圳)有限公司 | 道路匹配方法、装置、电子设备及可读存储介质 |
CN112969140B (zh) * | 2021-02-26 | 2022-08-09 | 中国能源建设集团江苏省电力设计院有限公司 | 一种gnss观测网自动组网方法及*** |
CN115936331B (zh) * | 2022-11-01 | 2023-10-27 | 中科雨辰科技有限公司 | 一种基于距离获取目标任务对象的数据处理*** |
CN115827814B (zh) * | 2023-02-13 | 2023-06-06 | 深圳市泰比特科技有限公司 | 视野区域内车辆点的加载显示方法、***及相关设备 |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107239549A (zh) * | 2017-06-07 | 2017-10-10 | 传神语联网网络科技股份有限公司 | 数据库术语检索的方法、装置及终端 |
CN108509505A (zh) * | 2018-03-05 | 2018-09-07 | 昆明理工大学 | 一种基于分区双数组Trie的字符串检索方法及装置 |
CN108776666A (zh) * | 2018-05-04 | 2018-11-09 | 昆明理工大学 | 一种基于关键词倒排与Trie的空间关键词查询方法及装置 |
CN108846013A (zh) * | 2018-05-04 | 2018-11-20 | 昆明理工大学 | 一种基于geohash与Patricia Trie的空间关键词查询方法及装置 |
Family Cites Families (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US10885072B2 (en) * | 2016-10-25 | 2021-01-05 | International Business Machines Corporation | Spatial computing for location-based services |
CN107798054B (zh) * | 2017-09-04 | 2021-06-18 | 昆明理工大学 | 一种基于Trie的范围查询方法及装置 |
-
2019
- 2019-10-14 CN CN201910974408.1A patent/CN111026978A/zh active Pending
- 2019-11-14 WO PCT/CN2019/118308 patent/WO2021072874A1/zh active Application Filing
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107239549A (zh) * | 2017-06-07 | 2017-10-10 | 传神语联网网络科技股份有限公司 | 数据库术语检索的方法、装置及终端 |
CN108509505A (zh) * | 2018-03-05 | 2018-09-07 | 昆明理工大学 | 一种基于分区双数组Trie的字符串检索方法及装置 |
CN108776666A (zh) * | 2018-05-04 | 2018-11-09 | 昆明理工大学 | 一种基于关键词倒排与Trie的空间关键词查询方法及装置 |
CN108846013A (zh) * | 2018-05-04 | 2018-11-20 | 昆明理工大学 | 一种基于geohash与Patricia Trie的空间关键词查询方法及装置 |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113821539A (zh) * | 2021-09-07 | 2021-12-21 | 丰图科技(深圳)有限公司 | 区域查询方法、装置、电子设备和可读存储介质 |
CN115454993A (zh) * | 2022-07-27 | 2022-12-09 | 北京优诺信创科技有限公司 | 一种具备时空信息的空间电磁环境特征数据处理方法 |
CN116610769A (zh) * | 2023-07-19 | 2023-08-18 | 北京惠每云科技有限公司 | 一种基于双数组trie树的医疗数据空间分配方法和装置 |
CN116610769B (zh) * | 2023-07-19 | 2023-10-10 | 北京惠每云科技有限公司 | 一种基于双数组trie树的医疗数据空间分配方法和装置 |
Also Published As
Publication number | Publication date |
---|---|
CN111026978A (zh) | 2020-04-17 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
WO2021072874A1 (zh) | 基于双数组的位置查询方法、装置、计算机设备及存储介质 | |
WO2021068346A1 (zh) | 基于Geohash算法的位置查询方法、装置、计算机设备及存储介质 | |
CN107798054B (zh) | 一种基于Trie的范围查询方法及装置 | |
Zhang et al. | Bed-tree: an all-purpose index structure for string similarity search based on edit distance | |
CN107766433B (zh) | 一种基于Geo-BTree的范围查询方法及装置 | |
EP3072076B1 (en) | A method of generating a reference index data structure and method for finding a position of a data pattern in a reference data structure | |
WO2018000709A1 (zh) | 时间信息编码方法、编码值检索方法、解码方法与装置 | |
CN110765773A (zh) | 地址数据获取方法以及装置 | |
CN110990520B (zh) | 一种地址编码方法、装置、电子设备和存储介质 | |
WO2021189977A1 (zh) | 地址编码方法、装置、计算机设备及计算机可读存储介质 | |
US10095808B2 (en) | Approximate string matching optimization for a database | |
Lin | Binary search algorithm | |
US11468096B2 (en) | Database access using a z-curve | |
US9886785B2 (en) | Indexing and querying spatial graphs | |
CN106991149B (zh) | 一种融合编码和多版本数据的海量空间对象存储方法 | |
CN114817651B (zh) | 数据存储方法、数据查询方法、装置和设备 | |
WO2021068347A1 (zh) | 自适应位置查询方法、装置、计算机设备及存储介质 | |
Wang et al. | Rencoder: A space-time efficient range filter with local encoder | |
US11449628B2 (en) | System and method for data security grading | |
CN108345607B (zh) | 搜索方法和装置 | |
CN111402958B (zh) | 一种建立基因比对表的方法、***、设备及介质 | |
CN116521733A (zh) | 一种数据查询方法及装置 | |
CN116501781B (zh) | 一种增强前缀树的数据快速统计方法 | |
CN117312471B (zh) | 海量位置点的海陆属性判断方法及装置 | |
CN114579573B (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: 19949186 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: 19949186 Country of ref document: EP Kind code of ref document: A1 |