mongoDB geohash index - use prefix base 2bit spilted 2D-阿里云开发者社区

开发者社区> 云计算> 正文
登录阅读全文

mongoDB geohash index - use prefix base 2bit spilted 2D

简介:
使用2个比特位, 表示一个坐标的4个象限(例如00, 01, 10, 11). 一个2维坐标会落在其中的一个象限, 对这个象限继续划分成4个象限, 这个坐标又会落在一个象限, 继续分割提高精度. 
相近的两个2D点, 应该会有很多prefix重叠部分, prefix重叠越多, 越相近.

http://docs.mongodb.org/manual/core/geospatial-indexes/#geospatial-indexes-geohash

Calculation of Geohash Values for 2d Indexes

When you create a geospatial index on legacy coordinate pairs, MongoDB computes geohash values for the coordinate pairs within the specified location range and then indexes the geohash values.

To calculate a geohash value, recursively divide a two-dimensional map into quadrants. Then assign each quadrant a two-bit value. For example, a two-bit representation of four quadrants would be:

01  11

00  10

These two-bit values (00, 01, 10, and 11) represent each of the quadrants and all points within each quadrant. For a geohash with two bits of resolution, all points in the bottom left quadrant would have a geohash of 00. The top left quadrant would have the geohash of 01. The bottom right and top right would have a geohash of 10 and 11, respectively.

To provide additional precision, continue dividing each quadrant into sub-quadrants. Each sub-quadrant would have the geohash value of the containing quadrant concatenated with the value of the sub-quadrant. The geohash for the upper-right quadrant is 11, and the geohash for the sub-quadrants would be (clockwise from the top left): 1101, 1111, 1110, and 1100, respectively.

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享:
云计算
使用钉钉扫一扫加入圈子
+ 订阅

时时分享云计算技术内容,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。

其他文章
最新文章