【问题标题】:What's the difference between "area" and "BoundingBox" from Redis's source codeRedis源码中的“area”和“BoundingBox”有什么区别
【发布时间】:2016-09-13 02:06:46
【问题描述】:

http://download.redis.io/redis-stable/deps/geohash-int/geohash_helper.c 从上面的 URL,我们知道有两个概念,一个是 geohashBoundingBox,另一个是 area,我的问题是它们之间有什么区别,为什么我们都需要它们? 还有为什么句“geohashGetCoordRange(&long_range, &lat_range);”被调用两次?

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;

}

【问题讨论】:

    标签: redis geolocation geometry geocoding geospatial


    【解决方案1】:

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

    对于您的第二个问题,大概是因为变量long_range 和lat_range 是通过引用传递的,所以有可能

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

    修改它们的值,因此函数geohashGetCoordRange 会在不同的值上再次调用。

    【讨论】:

      猜你喜欢
      • 2013-10-02
      • 2021-09-09
      • 2015-05-30
      • 1970-01-01
      • 2011-09-20
      • 1970-01-01
      • 2020-08-01
      • 1970-01-01
      • 2012-12-30
      相关资源
      最近更新 更多