“区域”与“区域”之间的区别是什么?和“BoundingBox”来自Redis的源代码 [英] What's the difference between "area" and "BoundingBox" from Redis's source code

查看:141
本文介绍了“区域”与“区域”之间的区别是什么?和“BoundingBox”来自Redis的源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://download.redis.io/redis- stable / deps / geohash-int / geohash_helper.c
从上面的URL中,我们知道有两个概念,一个是geohashBoundingBox,另一个是区域,我的问题是它们之间的区别,以及为什么我们需要他们两个吗?
也为什么这样说句子geohashGetCoordRange(& long_range,& lat_range);被调用两次?



  GeoHashRadius geohashGetAreasByRadius(双经度,双纬度,双radius_meters){
GeoHashRange long_range,lat_range ;
GeoHashRadius radius = {{0}};
GeoHashBits hash = {0};
GeoHashNeighbors neighbors = {{0}};
GeoHashArea area = {{0}};
double min_lon,max_lon,min_lat,max_lat;
双边界[4];
int步骤;

geohashBoundingBox(longitude,latitude,radius_meters,bounds);
min_lon = bounds [0];
min_lat = bounds [1];
max_lon = bounds [2];
max_lat = bounds [3];

steps = geohashEstimateStepsByRadius(radius_meters,latitude);

geohashGetCoordRange(& long_range,& lat_range);
geohashEncode(& long_range,& lat_range,longitude,latitude,steps,& hash);
geohashNeighbors(& hash,& neighbors);
geohashGetCoordRange(& long_range,& lat_range);
geohashDecode(long_range,lat_range,hash,& area);

if(area.latitude.min< min_lat){
GZERO(neighbors.south);
GZERO(neighbors.south_west);
GZERO(neighbors.south_east);
}
if(area.latitude.max> max_lat){
GZERO(neighbors.north);
GZERO(neighbors.north_east);
GZERO(neighbors.north_west);
}
if(area.longitude.min< min_lon){
GZERO(neighbors.west);
GZERO(neighbors.south_west);
GZERO(neighbors.north_west);
}
if(area.longitude.max> max_lon){
GZERO(neighbors.east);
GZERO(neighbors.south_east);
GZERO(neighbors.north_east);
}
radius.hash = hash;
radius.neighbors = neighbors;
radius.area =面积;
回报半径;

}

解决方案 div>

一个粘合盒通常是包含一个物体的最小矩形框。我不能说在redis中GeoHashArea的确切功能,但是因为你暗示它们有相似的目的,如果它们都代表一个地理区域,那么GeoHashArea肯定是一个区域的更详细的多边形表示而不是简单的矩形像geohashBoundingBox。



对于第二个问题,可能是因为变量 long_range lat_range 通过引用传递,有可能是

  geohashEncode(& long_range,& lat_range,经度,纬度,步数和散列); 

会修改它们的值,所以函数 geohashGetCoordRange 再次调用不同的值。


http://download.redis.io/redis-stable/deps/geohash-int/geohash_helper.c From the URL above, we know there are two conceptions , one is geohashBoundingBox ,and another is area,My questions is what's the difference between them and why we need them both? Also why sentence "geohashGetCoordRange(&long_range, &lat_range);" is called two times?

GeoHashRadius geohashGetAreasByRadius(double longitude, double latitude,    double radius_meters) {
GeoHashRange long_range, lat_range;
GeoHashRadius radius = { { 0 } };
GeoHashBits hash = { 0 };
GeoHashNeighbors neighbors = { { 0 } };
GeoHashArea area = { { 0 } };
double min_lon, max_lon, min_lat, max_lat;
double bounds[4];
int steps;

geohashBoundingBox(longitude, latitude, radius_meters, bounds);
min_lon = bounds[0];
min_lat = bounds[1];
max_lon = bounds[2];
max_lat = bounds[3];

steps = geohashEstimateStepsByRadius(radius_meters,latitude);

geohashGetCoordRange(&long_range, &lat_range);
geohashEncode(&long_range, &lat_range, longitude, latitude, steps, &hash);
geohashNeighbors(&hash, &neighbors);
geohashGetCoordRange(&long_range, &lat_range);
geohashDecode(long_range, lat_range, hash, &area);

if (area.latitude.min < min_lat) {
    GZERO(neighbors.south);
    GZERO(neighbors.south_west);
    GZERO(neighbors.south_east);
}
if (area.latitude.max > max_lat) {
    GZERO(neighbors.north);
    GZERO(neighbors.north_east);
    GZERO(neighbors.north_west);
}
if (area.longitude.min < min_lon) {
    GZERO(neighbors.west);
    GZERO(neighbors.south_west);
    GZERO(neighbors.north_west);
}
if (area.longitude.max > max_lon) {
    GZERO(neighbors.east);
    GZERO(neighbors.south_east);
    GZERO(neighbors.north_east);
}
radius.hash = hash;
radius.neighbors = neighbors;
radius.area = area;
return radius;

}

解决方案

A bonding box in general is the smallest rectangular box that will contain an object. I can't speak to the exact function of GeoHashArea in redis, but since you imply that they have a similar purpose, if they both represent a geographic area then GeoHashArea will most certainly be a more detailed polygonal representation of an area than a simple rectangle like geohashBoundingBox.

For your second question, presumably, since the variables long_range and lat_range are passed by reference, there's a chance that

geohashEncode(&long_range, &lat_range, longitude, latitude, steps, &hash);

modifies their value and so the function geohashGetCoordRange is called again on the different values.

这篇关于“区域”与“区域”之间的区别是什么?和“BoundingBox”来自Redis的源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆