Methods, apparatus, equipment and media for geofencing geohash blocks
By determining the minimum bounding rectangle of the geofence and dynamically adjusting the number of bits in the geohash algorithm, and combining ray casting to detect the association between geohash blocks and geofences, the problem of low computational efficiency in geofence determination is solved, and efficient and accurate geohash block conversion and event monitoring are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-06
- Publication Date
- 2026-03-06
AI Technical Summary
Existing technologies suffer from low computational efficiency and excessive computing power consumption when determining whether a device's latitude and longitude coordinates are within a geofence, especially when processing large-scale trajectory data.
By determining the minimum bounding rectangle of the geofence, the number of bits in the geohash algorithm is dynamically adjusted, and the ray casting method is used to detect the association between the geohash block to which the target point coordinates belong and the geofence. Geohash blocks associated with the geofence are filtered out one by one, and the results are recorded and output.
It improves the accuracy and computational efficiency of converting geofences into geohash blocks, reduces the consumption of computing power, and enhances the accuracy and computational efficiency of geofence event monitoring.
Smart Images

Figure CN116684818B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of geographic information system technology, and in particular to a method for converting geofences into geohash blocks, an apparatus for converting geofences into geohash blocks, an electronic device, and a computer-readable storage medium. Background Technology
[0002] Geo-fencing technology is a new application of LBS (Location Based Services), which uses a virtual fence to demarcate a virtual geographic boundary. When a user enters or leaves a specific geographic area with their mobile phone, or is active within that area, the phone can receive automatic notifications and warnings.
[0003] With the development of big data technology, the trajectory data of devices nowadays usually has the characteristics of large historical base, large increment, and large growth rate. Therefore, determining whether the latitude and longitude coordinates of a device are within the geofence often involves massive data calculations.
[0004] Given that bitwise operations are far more efficient than floating-point operations when processing data, and that the geohash algorithm can encode two-dimensional latitude and longitude data into a single string, if geofences are first reduced to geohash and then the data that might be within the geofence is filtered out by comparing whether the geohash strings are the same, and then the latitude and longitude coordinates of the device are determined based on the filtered data, the computational efficiency can be greatly improved and the computational power consumption can be reduced. Therefore, how to accurately convert geofences into corresponding geohash blocks is particularly important for the accuracy of geofence event monitoring.
[0005] The above content is only used to help understand the technical solution of this application and does not represent an admission that the above content is prior art. Summary of the Invention
[0006] The main objective of this application is to provide a method, apparatus, electronic device, and computer-readable storage medium for converting geofences into geohash blocks, with the aim of accurately converting geofences into corresponding geohash blocks.
[0007] To achieve the above objectives, this application provides a method for geofencing geohash blocks, comprising the following steps:
[0008] Determine the minimum outer rectangle of the geofence;
[0009] The number of bits in the geohash algorithm is determined based on the diagonal length of the minimum outer rectangle.
[0010] Based on the number of bits, determine the longitude difference between the center points of two adjacent geohash blocks in the latitude direction, and determine the latitude difference between the center points of two adjacent geohash blocks in the longitude direction;
[0011] Obtain the coordinates of the target point associated with the minimum bounding rectangle, and use the ray casting method to detect whether the geohash block to which the target point coordinates belong is associated with the geofence, wherein the geohash block associated with the geofence is recorded;
[0012] Check whether the coordinates of the target points associated with the minimum bounding rectangle have been obtained;
[0013] If the acquisition is not completed, then after updating and acquiring the target point coordinates based on the longitude difference and / or the latitude difference, return to the step of using the ray method to detect whether the geohash block to which the target point coordinates belong is associated with the geofence.
[0014] If the data acquisition is complete, output all geohash blocks associated with the geofence.
[0015] Optionally, the step of using ray casting to detect whether the geohash block to which the target point coordinates belong is associated with the geofence includes:
[0016] Based on the longitude difference and the latitude difference, determine the coordinates of each corner of the geohash block to which the target point's coordinates belong;
[0017] Based on the ray casting method and the coordinates of each corner of the geohash block, it is determined whether the geohash block is associated with the geofence.
[0018] Optionally, the geohash block may be associated with the geofence in any of the following ways:
[0019] The geohash block is located within the geofence;
[0020] The geohash block intersects with the geofence;
[0021] The geofence is located within the geohash block.
[0022] Optionally, the method for geofencing geohash blocks further includes:
[0023] The longitude difference is added to the longitude of the target point coordinates, and / or the latitude difference is added to the latitude of the target point coordinates, to update the target point coordinates.
[0024] Optionally, the formulas for calculating the longitude difference and the latitude difference are as follows:
[0025] X = 360 / {2^ceiling(L*5 / 2)};
[0026] Y = 180 / {2^floor(L*5 / 2)};
[0027] Wherein, X is the longitude difference, Y is the latitude difference, and L is the number of digits.
[0028] Optionally, the step of determining the number of bits in the geohash algorithm based on the diagonal length of the minimum outer rectangle includes:
[0029] Determine the preset distance range to which the diagonal length of the minimum outer rectangle belongs;
[0030] The number of bits associated with the preset distance interval is used as the number of bits in the geohash algorithm.
[0031] Optionally, after the step of outputting all geohash blocks associated with the geofence if all acquisitions have been completed, the method further includes:
[0032] Based on all geohash blocks associated with the geofence, the geohash values corresponding to the trajectory data of the target device are filtered.
[0033] The ray casting method is used to determine whether the filtered geohash values are located within the geofence.
[0034] To achieve the above objectives, this application also provides an apparatus for geofence conversion of geohash blocks, comprising:
[0035] The detection module is used to determine the minimum outer rectangle of the geofence;
[0036] The processing module is used to determine the number of bits in the geohash algorithm based on the diagonal length of the minimum outer rectangle;
[0037] The calculation module is used to determine the longitude difference between the center points of two adjacent geohash blocks in the latitude direction based on the number of bits, and to determine the latitude difference between the center points of two adjacent geohash blocks in the longitude direction.
[0038] The selection module is used to obtain the coordinates of the target point associated with the minimum bounding rectangle, and to use the ray method to detect whether the geohash block to which the target point coordinates belong is associated with the geofence, wherein the geohash block associated with the geofence is recorded.
[0039] The judgment module is used to detect whether the coordinates of the target points associated with the minimum outer rectangle have been obtained.
[0040] The update module is used to update and obtain the target point coordinates based on the longitude difference and / or the latitude difference if the acquisition is not completed, and then return to execute the step of using the ray method to detect whether the geohash block to which the target point coordinates belong is associated with the geofence.
[0041] The output module is used to output all geohash blocks associated with the geofence if the acquisition is complete.
[0042] To achieve the above objectives, this application also provides an electronic device, the electronic device comprising: a memory, a processor, and a geofence conversion geohash block program stored in the memory and executable on the processor, wherein when the geofence conversion geohash block program is executed by the processor, it implements the steps of the geofence conversion geohash block method described above.
[0043] To achieve the above objectives, this application also provides a computer-readable storage medium storing a program for geofence-to-geohash block conversion, wherein when the program for geofence-to-geohash block conversion is executed by a processor, it implements the steps of the method for geofence-to-geohash block conversion as described above.
[0044] The method, apparatus, electronic device, and computer-readable storage medium for converting geofences into geohash blocks provided in this application dynamically adjust the bit depth of the geohash algorithm based on the approximate extent of the geofence, ensuring that the accuracy of the subsequently generated geohash blocks matches the specific geofence. Furthermore, by sequentially filtering out geohash blocks associated with the smallest bounding rectangle of the geofence, and then using ray casting to detect whether the filtered geohash blocks are simultaneously associated with the geofence, and recording the geohash blocks associated with the geofence as the output, the geofence can be accurately converted into the corresponding geohash blocks. Attached Figure Description
[0045] Figure 1 This is a schematic diagram illustrating the steps of a geofence conversion geohash block method in one embodiment of this application;
[0046] Figure 2 This is a schematic diagram of a device for converting geofences into geohash blocks in one embodiment of this application;
[0047] Figure 3This is a schematic block diagram of the internal structure of an electronic device according to an embodiment of this application.
[0048] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0049] The embodiments of this application are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and intended to explain this application, and should not be construed as limiting this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0050] Furthermore, descriptions using terms such as "first" and "second" in this application are for descriptive purposes only (e.g., to distinguish identical or similar elements) and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated. Therefore, features defined with "first" or "second" may explicitly or implicitly include at least one of those features. Additionally, technical solutions from different embodiments can be combined with each other, but this must be based on the ability of those skilled in the art to implement them. If a combination of technical solutions is contradictory or impossible to implement, such a combination should be considered nonexistent and not within the scope of protection claimed in this application.
[0051] Reference Figure 1 In one embodiment, the method for geofencing geohash blocks includes:
[0052] Step S10: Determine the minimum outer rectangle of the geofence;
[0053] Step S20: Determine the number of bits in the geohash algorithm based on the diagonal length of the minimum outer rectangle;
[0054] Step S30: Determine the longitude difference between the center points of two adjacent geohash blocks in the latitude direction based on the number of digits, and determine the latitude difference between the center points of two adjacent geohash blocks in the longitude direction.
[0055] Step S40: Obtain the coordinates of the target point associated with the minimum bounding rectangle, and use the ray casting method to detect whether the geohash block to which the target point coordinates belong is associated with the geofence, wherein the geohash block associated with the geofence is recorded.
[0056] Step S50: Detect whether the coordinates of the target points associated with the minimum outer rectangle have been obtained;
[0057] Step S60: If the acquisition is not completed, update and acquire the target point coordinates based on the longitude difference and / or the latitude difference, and then return to the step of using the ray method to detect whether the geohash block to which the target point coordinates belong is associated with the geofence.
[0058] Step S70: If the acquisition is complete, output all geohash blocks associated with the geofence.
[0059] In this embodiment, the execution terminal can be an electronic device or a geofence conversion geohash block device.
[0060] As described in step S10, relevant engineers can pre-create corresponding geofences according to specific design requirements. These geofences can be polygonal or circular.
[0061] Optionally, if the geofence is a polygon, the minimum outer rectangle of the geofence can be determined based on the maximum longitude, maximum latitude, minimum longitude, and minimum latitude of the geofence boundary; if the geofence is a circle, the minimum outer rectangle of the circle can be determined directly based on the circle's radius.
[0062] It should be noted that the minimum bounding rectangle refers to the maximum range of several two-dimensional shapes (such as points, lines, and polygons) represented by two-dimensional coordinates. That is, the rectangle whose lower boundary is defined by the maximum and minimum x-coordinates, maximum and minimum y-coordinates of each vertex of a given two-dimensional shape.
[0063] As described in step S20, after determining the minimum outer rectangle of the geofence, the diagonal length of the minimum outer rectangle can be calculated using the lengths of its adjacent sides and the Pythagorean theorem. Of course, if the geofence is circular, the diagonal length of the minimum outer rectangle can be directly calculated using its radius.
[0064] Optionally, once the diagonal length of the minimum bounding rectangle is obtained, the number of bits in the geohash algorithm required to generate the geohash block can be calculated based on the diagonal length (equivalent to the precision of the geohash block calculation, because the larger the number of bits in the geohash algorithm, the higher the precision of the geohash block).
[0065] It should be noted that the geohash algorithm is an algorithm that encodes latitude and longitude, transforms two-dimensional coordinates into one-dimensional coordinates, and partitions address locations. The smallest partition unit of the geohash algorithm represents a geohash block, and the higher the precision of the geohash block, the smaller the area covered by a single geohash block.
[0066] Optionally, the step of determining the number of bits in the geohash algorithm based on the diagonal length of the minimum outer rectangle includes:
[0067] Determine the preset distance range to which the diagonal length of the minimum outer rectangle belongs;
[0068] The number of bits associated with the preset distance interval is used as the number of bits in the geohash algorithm.
[0069] Optionally, the terminal can pre-divide different number of digits into corresponding preset distance intervals; and the preset distance interval for larger digits is smaller than that for smaller digits.
[0070] Optionally, the number of bits in the geohash algorithm can be obtained by first determining the preset distance interval to which the diagonal length of the smallest outer rectangle belongs, and then obtaining the number of bits associated with the preset distance interval to which the diagonal length belongs.
[0071] Optionally, the following is a pseudocode example of the specific algorithm for determining the number of digits (R unit: meters):
[0072] if (R <= 19 * 2) return 9;
[0073] else if (R <= 76 * 2) return 8;
[0074] else if (R <= 610 * 2) return 7;
[0075] else if (R <= 2400 * 2) return 6;
[0076] else if (R <= 20000 * 2) return 5;
[0077] else if (R <= 78000 * 2) return 4;
[0078] else if (R <= 630000 * 2) return 3;
[0079] else if (R <= 2500000 * 2) return 2;
[0080] else return 1.
[0081] Where R is the diagonal length, the returned number is the number of digits determined.
[0082] In this way, the accuracy of geohash can be dynamically adjusted according to the approximate range of the geofence (and the smaller the geofence area is, the higher the accuracy of the geohash used). This makes the application scope of this embodiment wider and more flexible (it can be applied to geofence monitoring schemes of different shapes and sizes, and the accuracy of geohash can be accurately adapted to the range of the geofence).
[0083] As described in step S30, after obtaining the number of bits in the geohash algorithm, the precision of the geohash block can be determined accordingly (which also determines the size of the area covered by a single geohash block). Furthermore, the difference in longitude between the center points of two adjacent geohash blocks in the latitude direction (i.e., the east-west direction of the Earth) and the difference in latitude between the center points of two adjacent geohash blocks in the meridian direction (i.e., the north-south direction of the Earth) can be calculated based on the number of bits in the geohash algorithm.
[0084] Optionally, the formulas for calculating the longitude difference and the latitude difference are as follows:
[0085] X = 360 / {2^ceiling(L*5 / 2)};
[0086] Y = 180 / {2^floor(L*5 / 2)};
[0087] Wherein, X is the longitude difference, Y is the latitude difference, and L is the number of digits; and as those skilled in the art will know, ceiling() is the floor function and floor() is the floor function.
[0088] Of course, in some other alternative solutions, after obtaining the number of bits in the geohash algorithm, the size of the area covered by a single geohash block can be determined. By selecting two adjacent geohash blocks in the latitude direction and obtaining the latitude and longitude coordinates of the center points of these two geohash blocks, the longitude difference can be calculated using the longitude coordinates of these two center points; and by selecting two adjacent geohash blocks in the longitude direction and obtaining the latitude and longitude coordinates of the center points of these two geohash blocks, the latitude difference can be calculated using the latitude coordinates of these two center points.
[0089] As described in step S40, the target point coordinates are marked as P. n =(x, y), where n is the number of times the target point coordinates are obtained, and the distance between two adjacent target point coordinates in the latitude direction is the longitude difference; the distance between two adjacent target point coordinates in the longitude direction is the latitude difference.
[0090] Optionally, the coordinates of the target point obtained first can be any of the coordinates of the four corners of the smallest outer rectangle. The following example illustrates how the coordinates of the lower left corner of the rectangle can be obtained first as the coordinates of the target point.
[0091] The coordinates of the lower left corner of the minimum bounding rectangle are composed of the minimum longitude (lng1) and minimum latitude (lat1) of the minimum bounding rectangle (or geofence), denoted as P1=(lng1,lat1).
[0092] Optionally, the step of using ray casting to detect whether the geohash block to which the target point coordinates belong is associated with the geofence includes:
[0093] Based on the longitude difference and the latitude difference, determine the coordinates of each corner of the geohash block to which the target point's coordinates belong;
[0094] Based on the ray casting method and the coordinates of each corner of the geohash block, it is determined whether the geohash block is associated with the geofence.
[0095] When determining the geohash block to which the target point coordinates belong, the target point coordinates are used as the center point coordinates of the geohash block to which the target point coordinates belong. Based on the target point coordinates and the longitude difference and latitude difference, the coordinates of the four corners of the corresponding geohash block can be calculated (which gives the area range of the corresponding geohash block, equivalent to identifying the geohash block to which the target point coordinates belong).
[0096] The coordinates of the four corners of the geohash block are (xX / 2, yY / 2), (xX / 2, y+Y / 2), (x+X / 2, y+Y / 2), and (x+X / 2, y+Y / 2).
[0097] Where x is the longitude of the target point coordinates, y is the latitude of the target point coordinates, X is the difference in longitude, and Y is the difference in latitude; for example, if P1=( lng1, lat1), then the coordinates of the four corners of the geohash block to which the target point coordinates belong are respectively: (lng1-X / 2, lat1-Y / 2), (lng1-X / 2, lat1+Y / 2), (lng1+X / 2, lat1+Y / 2), (lng1+X / 2, lat1+Y / 2).
[0098] Optionally, after determining the geohash block to which the target point coordinates belong, the ray casting method can be further used to detect whether the geohash block to which the target point coordinates belong is associated with the geofence. The association between the geohash block and the geofence includes any of the following:
[0099] The geohash block is located within the geofence;
[0100] The geohash block intersects with the geofence;
[0101] The geofence is located within the geohash block.
[0102] Optional, specific testing steps are shown below:
[0103] Step 1: Use the ray casting method to determine whether the coordinates of the four corners of the geohash block are within the geofence; if they are, then determine that the geohash block is located within the geofence (that is, determine that the geohash block to which the target point coordinates belong is associated with the geofence, and add the geohash block to the result array to record the geohash block), and end the detection step; if not, continue to step 2.
[0104] Step 2: Determine the four edges of the geohash block using the coordinates of its four corners, and further use ray casting to detect whether the four edges of the geohash block intersect with the boundary of the geofence. If the geofence is circular, the intersection of the geohash block and the geofence can be detected by determining whether the minimum distance from the center of the circle to the normal direction of the four edges of the geohash block is less than or equal to the radius of the circle (if so, the edges intersect; otherwise, they do not).
[0105] If a geohash block is detected to intersect with a geofence, the detection step ends (and it is determined that the geohash block to which the target point coordinates belong is associated with the geofence, and the geohash block is added to the result array to record the geohash block); otherwise, step three continues.
[0106] Step 3: Use the ray casting method to determine whether the coordinates of the four corners of the smallest bounding rectangle are in the geohash block; if so, determine that the geofence is located in the geohash block (that is, determine that the geohash block to which the target point coordinates belong is associated with the geofence, and add the geohash block to the result array to record the geohash block), and end the detection step.
[0107] It should be noted that the ray method commonly uses the horizontal scan line method or the vertical line method to determine whether a point is within a region. The ray method used in this embodiment can be the conventional ray method used to determine the relative positional relationship between two regions. Therefore, the specific usage and principle of the ray method will not be elaborated here.
[0108] It should be understood that the execution order of the above detection steps one to three is only exemplary and can be rearranged according to actual needs, such as first detecting whether the geofence is located in the geohash block, and then detecting whether the geohash block intersects with the geofence, etc.
[0109] As described in step S50, after determining whether the geohash block to which the currently acquired target point coordinates belong is associated with the geofence, it is possible to further detect whether the target point coordinates associated with the minimum bounding rectangle have been acquired.
[0110] Optionally, the total area of the geohash blocks to which all the obtained target point coordinates belong can be checked to see if it covers the area corresponding to the minimum outer rectangle. This is used to determine whether all the target point coordinates associated with the minimum outer rectangle have been obtained. If the total area of the geohash blocks can cover the area corresponding to the minimum outer rectangle, then it is determined that all target point coordinates have been obtained; otherwise, it is determined that the target point coordinates have not been obtained.
[0111] If, in step S40, it is detected that the geofence is located in the geohash block to which the target point coordinates belong, it can be directly determined that all target point coordinates have been obtained, and the process can proceed to step S70.
[0112] As described in step S60, if the target point coordinates are not fully acquired, the target point coordinates can be updated based on the longitude difference and / or latitude difference.
[0113] Optionally, the longitude difference is added to the longitude of the target point coordinates, and / or the latitude difference is added to the latitude of the target point coordinates to update the target point coordinates.
[0114] Optionally, taking the first obtained target point coordinates as the lower left corner coordinate P1 of the smallest bounding rectangle, after checking whether the geohash block to which P1 belongs is associated with the geofence, if it is detected that the target point coordinates have not been fully obtained, the target point coordinates are updated based on P1 in the following way:
[0115] You can start from P1 and update the coordinates of the target point one by one along the latitude and longitude lines (and the distance between the coordinates of two adjacent target points along the latitude line is the longitude difference). For example, when P1=(lng1, lat1), the coordinates of the second target point obtained are P2=(lng1+X, lat1).
[0116] Furthermore, when obtaining the updated target point coordinates, the region of the geohash block to which the new target point coordinates belong is determined, and it is checked whether the minimum longitude of the geohash block to which the new target point coordinates belong is greater than the maximum longitude of the minimum bounding rectangle (or geofence).
[0117] If the minimum longitude of the geohash block is not greater than the maximum longitude of the minimum bounding rectangle, then the target point coordinates are available, and the process returns to the step of using ray casting to detect whether the geohash block to which the target point coordinates belong is associated with the geofence. Furthermore, when it is necessary to update the target point coordinates in the future, the next target point coordinate can still be obtained from the current latitude direction until all target point coordinates in the current latitude direction have been obtained. If the minimum longitude of the geohash block is greater than the maximum longitude of the minimum bounding rectangle, then the geohash block to which the target point coordinates belong is not associated with the geofence, and there is no need to use ray casting for further judgment.
[0118] Furthermore, if the minimum longitude of the geohash block to which the new target point coordinates belong is detected to be greater than the maximum longitude of the minimum bounding rectangle, it indicates that the target point coordinates in the current latitude direction (such as the lat1 direction) have been obtained, and the system can switch to the next latitude direction (if the current latitude direction is the lat1 direction, then the next latitude direction is the lat1+Y direction, and the first target point coordinates in the lat1+Y direction are (lng1, lat1+Y)). After determining the area range of the geohash block to which the new target point coordinates belong, the system checks whether the minimum latitude of the geohash block to which the new target point coordinates belong is greater than the maximum latitude of the minimum bounding rectangle (or geofence).
[0119] If the minimum latitude of the detected geohash block is not greater than the maximum latitude of the minimum bounding rectangle, it indicates that the target point coordinates are available, and the process returns to the step of using ray casting to detect whether the geohash block to which the target point coordinates belong is associated with the geofence. Furthermore, when new target point coordinates are needed in the future, the next target point coordinates can still be obtained from the current latitude direction until all target point coordinates in the current latitude direction have been obtained. If the minimum latitude of the geohash block is greater than the maximum latitude of the minimum bounding rectangle, it indicates that the geohash block to which the target point coordinates belong is not associated with the geofence, and no further judgment using ray casting is required.
[0120] Furthermore, if the minimum longitude of the geohash block to which the new target point coordinates belong is detected is greater than the maximum longitude of the minimum outer rectangle, it can be directly determined that all target point coordinates have been obtained.
[0121] Of course, the above-mentioned examples of obtaining target point coordinates are essentially equivalent to obtaining the target point coordinates associated with the smallest outer rectangle row by row and column by column. If those skilled in the art can achieve the same result as the above-mentioned method by making simple transformations (such as changing the row-by-row format to the column-by-row format; or changing the target point coordinates obtained in the first instance to the coordinates of the upper right corner of the smallest outer rectangle, and then subtracting the longitude difference from the longitude of the target point coordinates and / or subtracting the latitude difference from the latitude of the target point coordinates to update the target point coordinates), they should fall within the scope of protection of this embodiment.
[0122] As described in step S70, if the coordinates of all target points associated with the smallest outer rectangle have been obtained, and it has been determined whether the geohash block to which the obtained target point coordinates belong is associated with the geofence, then the result set of all geohash blocks associated with the geofence that were previously recorded will be output, so that the geohash block corresponding to the geofence can be obtained.
[0123] In one embodiment, the number of bits in the geohash algorithm is dynamically adjusted according to the approximate range of the geofence, so that the accuracy of the subsequently generated geohash blocks can be adapted to the specific geofence. After filtering out the geohash blocks associated with the smallest bounding rectangle of the geofence one by one, the ray casting method is used to detect whether the filtered geohash blocks are also associated with the geofence. The geohash blocks associated with the geofence are recorded as the output result, thus realizing the accurate conversion of the geofence into the corresponding geohash block.
[0124] In one embodiment, based on the above embodiment, after the step of outputting all geohash blocks associated with the geofence if the acquisition has been completed, the method further includes:
[0125] Based on all geohash blocks associated with the geofence, the geohash values corresponding to the trajectory data of the target device are filtered.
[0126] The ray casting method is used to determine whether the filtered geohash values are located within the geofence.
[0127] In this embodiment, after obtaining the result set of geohash blocks corresponding to the geofence, the geohash values corresponding to the trajectory data of the target device can be filtered based on all geohash blocks associated with the geofence.
[0128] The trajectory data of the target device can be pre-collected, and before filtering, the values of each trajectory data can be converted into geohash values accordingly.
[0129] Optionally, during the process of filtering geohash values corresponding to trajectory data, each geohash value is checked to see if it belongs to all geohash values covered by all geohash blocks associated with the geofence, and geohash values corresponding to trajectory data that belong to the geohash value range covered by all geohash blocks associated with the geofence are retained to obtain the filtering results.
[0130] Furthermore, the ray casting method can be used to detect whether the geohash value in the filtering results is located within the geofence, and retain the geohash value corresponding to the trajectory data located within the geofence as the output result. In this way, the trajectory data corresponding to these output geohash values can be determined to have occurred within the geofence.
[0131] It should be noted that the trajectory data currently collected is often in floating-point format. This means that when using the ray casting method to determine whether the latitude and longitude coordinates of a target device are within a geofence, the calculation process usually involves a large number of floating-point operations. With the development of big data technology, the trajectory data of devices nowadays is characterized by a large historical base, large increments, and large growth rates. This means that using the ray casting method to determine whether a device is within a geofence requires performing a huge number of floating-point operations, which is not only inefficient but also consumes a lot of computing power.
[0132] Given that bitwise operations are far more efficient than floating-point operations when processing data, and that the geohash algorithm can encode two-dimensional latitude and longitude data into a string, we can first reduce the geofence to the corresponding geohash blocks, and then filter out trajectory data that may be within the geofence by comparing whether the geohash values are the same. Finally, we can use the ray casting method to calculate and filter out the trajectory data that is actually located within the geofence, which can greatly improve the computational efficiency and reduce the consumption of computing power.
[0133] Moreover, based on the method of the above embodiments, geofences can be accurately converted into corresponding geohash blocks. When using geohash blocks obtained in this way to filter trajectory data, the accuracy of trajectory data filtering can be improved accordingly. Furthermore, when using the accurately filtered trajectory data to perform geofence event monitoring and judgment in the future, the accuracy of the judgment can also be improved.
[0134] Reference Figure 2 This application also provides a device Z10 for geofence conversion of geohash blocks, comprising:
[0135] The detection module Z11 is used to determine the minimum outer rectangle of the geofence;
[0136] Processing module Z12 is used to determine the number of bits in the geohash algorithm based on the diagonal length of the minimum outer rectangle;
[0137] The calculation module Z13 is used to determine the longitude difference between the center points of two adjacent geohash blocks in the latitude direction based on the number of bits, and to determine the latitude difference between the center points of two adjacent geohash blocks in the longitude direction.
[0138] The selection module Z14 is used to obtain the coordinates of the target point associated with the minimum bounding rectangle, and to use the ray method to detect whether the geohash block to which the target point coordinates belong is associated with the geofence, wherein the geohash block associated with the geofence is recorded.
[0139] The judgment module Z15 is used to detect whether the coordinates of the target points associated with the minimum outer rectangle have been obtained.
[0140] The update module Z16 is used to update and obtain the target point coordinates based on the longitude difference and / or the latitude difference if the acquisition is not completed, and then return to execute the step of using the ray method to detect whether the geohash block to which the target point coordinates belong is associated with the geofence.
[0141] Output module Z17 is used to output all geohash blocks associated with the geofence if the acquisition is complete.
[0142] Optionally, the device for converting geofences into geohash blocks can be a virtual control device or a physical device.
[0143] Reference Figure 3 This application also provides an electronic device whose internal structure can be as follows: Figure 3As shown, the electronic device includes a processor, memory, communication interface, and database connected via a system bus. The processor provides computing and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The database stores programs for geofencing geohash block conversion. The communication interface is used for data communication with external terminals. The input device receives signals from external devices. When the computer program is executed by the processor, it implements a geofencing geohash block conversion method as described in the above embodiment.
[0144] Those skilled in the art will understand that Figure 3 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the electronic device to which the present application is applied.
[0145] Furthermore, this application also proposes a computer-readable storage medium comprising a program for geofence-to-geohash block conversion, wherein the program, when executed by a processor, implements the steps of the geofence-to-geohash block conversion method as described in the above embodiments. It is understood that the computer-readable storage medium in this embodiment may be a volatile readable storage medium or a non-volatile readable storage medium.
[0146] In summary, the method, apparatus, electronic device, and computer-readable storage medium for converting geofences into geohash blocks provided in this application embodiment dynamically adjust the bit depth of the geohash algorithm based on the approximate range of the geofence, ensuring that the accuracy of the subsequently generated geohash blocks is adapted to the specific geofence. Furthermore, by sequentially filtering out geohash blocks associated with the smallest bounding rectangle of the geofence, and then using ray casting to detect whether the filtered geohash blocks are simultaneously associated with the geofence, and recording the geohash blocks associated with the geofence as the output, the geofence can be accurately converted into the corresponding geohash blocks.
[0147] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in this application and in the embodiments can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual-speed SDRAM (SSRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0148] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, apparatus, article, or method that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, apparatus, article, or method. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, apparatus, article, or method that includes that element.
[0149] The above description is only a preferred embodiment of this application and does not limit the patent scope of this application. Any equivalent structural or procedural changes made based on the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.
Claims
1. A method of geofence conversion geohash tiles, characterized in that, The method comprises the following steps: determining a minimum bounding rectangle of a geo-fence; determining the number of bits of a geohash algorithm according to the length of the diagonal of the minimum bounding rectangle; determining the longitude difference between the center points of two adjacent geohash blocks in the latitude direction and the latitude difference between the center points of two adjacent geohash blocks in the longitude direction based on the number of bits; obtaining the target point coordinates associated with the minimum bounding rectangle, and detecting whether the geohash block to which the target point coordinates belong is associated with the geo-fence by using a ray method, wherein the geohash blocks associated with the geo-fence are recorded; detecting whether the target point coordinates associated with the minimum bounding rectangle have been obtained; if not, after updating and obtaining the target point coordinates according to the longitude difference and / or the latitude difference, returning to the step of detecting whether the geohash block to which the target point coordinates belong is associated with the geo-fence by using the ray method; if yes, outputting all geohash blocks associated with the geo-fence.
2. The method of claim 1, wherein, The step of detecting whether the geohash block to which the target point coordinates belong is associated with the geo-fence by using the ray method comprises the following steps: determining the edge corner coordinates of the geohash block to which the target point coordinates belong according to the longitude difference and the latitude difference; detecting whether the geohash block is associated with the geo-fence based on the ray method and the edge corner coordinates of the geohash block.
3. The method of converting geohash tiles for geofencing of claim 1 or 2, wherein, The association of the geohash block with the geo-fence includes any one of the following: the geohash block is located in the geo-fence; the geohash block intersects with the geo-fence; the geo-fence is located in the geohash block.
4. The method of claim 1, wherein, The method further comprises the following steps: adding the longitude of the target point coordinates to the longitude difference, and / or adding the latitude of the target point coordinates to the latitude difference, to update the target point coordinates.
5. The method of claim 1, wherein, The calculation formulae of the longitude difference and the latitude difference are as follows: X=360 / {2^ceiling(L*5 / 2)}; Y=180 / {2^floor(L*5 / 2)}; wherein X is the longitude difference, Y is the latitude difference, and L is the number of bits.
6. The method of converting geohash tiles for geofencing of claim 1, wherein, The step of determining the number of bits of the geohash algorithm according to the length of the diagonal of the minimum bounding rectangle comprises the following steps: determining the preset distance interval to which the length of the diagonal of the minimum bounding rectangle belongs; obtaining the number of bits associated with the preset distance interval as the number of bits of the geohash algorithm.
7. The method of claim 1, wherein, After the step of outputting all geohash blocks associated with the geo-fence, the method further comprises the following steps: screening the geohash values corresponding to the trajectory data of a target device based on all geohash blocks associated with the geo-fence; judging whether the screened geohash values are located within the geo-fence by using the ray method.
8. An apparatus for geofence conversion geohash tiles, the apparatus comprising: The device comprises a detection module configured to determine a minimum bounding rectangle of a geo-fence. determining a number of bits of a geohash algorithm according to a length of a diagonal line of the minimum bounding rectangle; determining a longitude difference between center points of two geohash blocks adjacent in a latitude direction and determining a latitude difference between center points of two geohash blocks adjacent in a longitude direction based on the number of bits; detecting whether a geohash block to which a target point coordinate associated with the minimum bounding rectangle belongs is associated with the geo-fence by using a ray method, wherein geohash blocks associated with the geo-fence are recorded; detecting whether the target point coordinate associated with the minimum bounding rectangle is acquired completely; updating and acquiring the target point coordinate according to the longitude difference and / or the latitude difference, and returning to the step of detecting whether the geohash block to which the target point coordinate belongs is associated with the geo-fence by using the ray method if the target point coordinate is not acquired completely; outputting all geohash blocks associated with the geo-fence if the target point coordinate is acquired completely.
9. An electronic device, comprising: The electronic device includes a memory, a processor, and a program for converting a geo-fence into a geohash block stored on the memory and executable on the processor, and the program for converting a geo-fence into a geohash block, when executed by the processor, implements the steps of the method for converting a geo-fence into a geohash block according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a program for converting a geo-fence into a geohash block, and the program for converting a geo-fence into a geohash block, when executed by a processor, implements the steps of the method for converting a geo-fence into a geohash block according to any one of claims 1 to 7.
Citation Information
Patent Citations
Electronic fence loading method and device, equipment and storage medium
CN112333635A
Dynamic geohash-based geofencing
US20150264523A1