现在做地图匹配,大都都是对一个城市进行分区,查找道路的时候,先找到gps点是属于哪个区域,然后再进行匹配,这种方式在地图比较小的情况下使用。而最近我们做的地图分区之后,大概有1200万的区,其中70%都是没有数据,造成了空间的浪费,同时查找的效率相应也比较低。
而geohash 则是用来解决这个问题的,对于给定的经纬度,可以计算出一个唯一hashkey ,并且可以通过hashkey 来得到点与块之前的从属关系,所以点可以快速找到他所在的区域,节省的查找时间,但是需要计算hashkey 的时间复杂度要尽量低。这个还没有测试 ,对于他是否能节省空间复杂度,我持疑问态度。
参考文献2 虽然是python的库,但是他的源文件是用c实现的,所以将里面的实现文件拿出来就可以用了 ,将http://code.google.com/p/python-geohash/source/browse/trunk/src/ 中文件拷贝到工程下,就直接用了,
#include "geohash.h"
void test()
{
char r[20];
char dest[202];
double lat,lon;
int res;
double x = 23.128330456157695;
double y = 113.25698244571686;
if((res=geohash_encode(x, y, r, 13))==GEOHASH_OK){
printf("%s\n",r);
}else{
printf("error with %d\n",res);
}
if((res=geohash_decode(r,13,&lat,&lon))==GEOHASH_OK){
printf("%.12lf %.12lf\n",lat,lon);
}else{
printf("error with %d\n",res);
}
int num = 1;
int re = geo_neighbors(r,dest,200,&num);
printf("%s\n",dest);
}
参考:
1 :http://tech.idv2.com/2011/07/05/geohash-intro/
2: http://code.google.com/p/python-geohash/
原始博客地址: http://www.fuxiang90.com/2012/10/geohash-%E5%80%92%E8%85%BE/