requirements : Find restaurants within 1000 meters of the target
Solution: Index storage for all restaurants (point objects) in the city, speeding up the search speed
Premise background: The POI space distribution is uneven, the city center is relatively concentrated, the suburbs are very few
Solution:
1, using the index, the data structure suitable for indexing is "Hash" and "Tree"
2. Possible indexing schemes include: B-Tree, grid Index, Quadtree index, R-Tree index, Geohash
3. B-Tree is used for one-dimensional data "single field", Spatial objects (points, lines, polygons) are multidimensional data
Universal two-dimensional data solution (point, Line, polygon)
1. Grid Index
(1) Index implementation: using hash data structure implementation, the unit grid corresponds to a bucket in the HashMap, the grid associated objects are stored in the corresponding bucket of the linked list
(2) Limitations: Grid indexes are highly efficient when the object space is evenly distributed
If the spatial objects are unevenly distributed, they will eventually result in a large number of blank meshes, wasting storage space
Grid size is not OK, too large index efficiency is low, too small to form a lot of blank space
2, ordinary Quadtree index
(1) Index implementation: A four-pronged tree is constructed by recursively dividing the space into four halves. Data is hooked up through a leaf node, and only the leaf points store data, and the root and intermediate nodes do not store data
(2) Limitations:
If the spatial objects are not evenly distributed, then the final structure is a deep-seated unbalanced tree, resulting in a decrease in query efficiency.
Duplicate storage of the same object in different leaf nodes
(3) Four Fork Tree Index improvement
Store geographic entity information in the smallest rectangular node that completely contains it, with each geographic entity stored only once in the tree, avoiding wasted storage space
(4) Four-fork tree has high efficiency when the object space is evenly distributed
3. R-Tree Index
is a B-tree in the high latitude space expansion, is a balance tree. R-Tree uses the concept of space segmentation, specifically using the "Minimum outsourcing rectangle", starting from the leaf node with a rectangle to frame the space, the more the node upward, the larger the box space, in order to split the space.
thinking: The four-tree index and R-tree ideas are reversed. One is recursively dividing the space from top to bottom, and the other is recursively dividing it from the bottom up
Solutions for converting two-dimensional data to one-dimensional data geohash (for Point objects)
(1) Index implementation: According to the longitude and latitude of the point object respectively, "interval division" to "the degree of compliance with certain precision", respectively coded, then merged, and finally BASE32 encoding to get a comparable string encoding
For example, WX4G0EC1, whose prefix wx4g0e represents a larger range including encoded WX4G0EC1. This feature can be used to search nearby locations. The Geohash (for example, WX4G0EC1) is calculated based on the user's current coordinates, and then the query is taken by its prefix (SELECT * from places where Geohash like ' wx4g0e% '), all nearby locations can be queried
(2) The Geohash code represents a rectangular region, not a specific point; all points of interest in the rectangular region have the same encoding
Geo Fence
Geo-fencing (geo-fencing) is an application of lbs, which is to surround a virtual geographic boundary with a virtual fence that can receive automatic notifications and warnings when a cell phone enters, leaves a particular geographic area, or is active in that area.
Implementation idea: First set up the R-tree index on the geo-fence (polygon) so that the outsourced rectangle covering the target location can be quickly found (and then to the polygon fence), and then determine whether the point is inside the polygon based on the Ray method
Reference: http://blog.csdn.net/zhouxuguang236/article/details/12312099
http://blog.jobbole.com/80633/
Http://www.cnblogs.com/LBSer/p/3403933.html