mirror of
https://github.com/fluencelabs/redis
synced 2025-03-18 16:40:50 +00:00
GEOENCODE / GEODECODE commands removed.
Rationale: 1. The commands look like internals exposed without a real strong use case. 2. Whatever there is an use case, the client would implement the commands client side instead of paying RTT just to use a simple to reimplement library. 3. They add complexity to an otherwise quite straightforward API. So for now KILLED ;-)
This commit is contained in:
parent
965abcf10a
commit
b96af595a5
93
src/geo.c
93
src/geo.c
@ -42,8 +42,6 @@ int zslValueLteMax(double value, zrangespec *spec);
|
||||
* - geoadd - add coordinates for value to geoset
|
||||
* - georadius - search radius by coordinates in geoset
|
||||
* - georadiusbymember - search radius based on geoset member position
|
||||
* - geoencode - encode coordinates to a geohash integer
|
||||
* - geodecode - decode geohash integer to representative coordinates
|
||||
* ==================================================================== */
|
||||
|
||||
/* ====================================================================
|
||||
@ -580,97 +578,6 @@ void georadiusByMemberCommand(redisClient *c) {
|
||||
georadiusGeneric(c, RADIUS_MEMBER);
|
||||
}
|
||||
|
||||
/* GEODECODE score */
|
||||
void geodecodeCommand(redisClient *c) {
|
||||
GeoHashBits geohash;
|
||||
if (getLongLongFromObjectOrReply(c, c->argv[1], (long long *)&geohash.bits,
|
||||
NULL) != REDIS_OK)
|
||||
return;
|
||||
|
||||
GeoHashArea area;
|
||||
geohash.step = GEO_STEP_MAX;
|
||||
geohashDecodeWGS84(geohash, &area);
|
||||
|
||||
double lon = (area.longitude.min + area.longitude.max) / 2;
|
||||
double lat = (area.latitude.min + area.latitude.max) / 2;
|
||||
|
||||
/* Returning three nested replies */
|
||||
addReplyMultiBulkLen(c, 3);
|
||||
|
||||
/* First, the minimum corner */
|
||||
addReplyMultiBulkLen(c, 2);
|
||||
addReplyDouble(c, area.longitude.min);
|
||||
addReplyDouble(c, area.latitude.min);
|
||||
|
||||
/* Next, the maximum corner */
|
||||
addReplyMultiBulkLen(c, 2);
|
||||
addReplyDouble(c, area.longitude.max);
|
||||
addReplyDouble(c, area.latitude.max);
|
||||
|
||||
/* Last, the averaged center of this bounding box */
|
||||
addReplyMultiBulkLen(c, 2);
|
||||
addReplyDouble(c, lon);
|
||||
addReplyDouble(c, lat);
|
||||
}
|
||||
|
||||
/* GEOENCODE long lat [radius unit] */
|
||||
void geoencodeCommand(redisClient *c) {
|
||||
double radius_meters = 0;
|
||||
if (c->argc == 5) {
|
||||
if ((radius_meters = extractDistanceOrReply(c, c->argv + 3, NULL)) < 0)
|
||||
return;
|
||||
} else if (c->argc == 4 || c->argc > 5) {
|
||||
addReplyError(c, "syntax error, try: GEOENCODE x y [radius unit]");
|
||||
return;
|
||||
}
|
||||
|
||||
double xy[2];
|
||||
if (extractLongLatOrReply(c, c->argv + 1, xy) == REDIS_ERR) return;
|
||||
|
||||
/* Encode long/lat into our geohash */
|
||||
GeoHashBits geohash;
|
||||
uint8_t step = geohashEstimateStepsByRadius(radius_meters,0);
|
||||
geohashEncodeWGS84(xy[0], xy[1], step, &geohash);
|
||||
|
||||
/* Align the hash to a valid 52-bit integer based on step size */
|
||||
GeoHashFix52Bits bits = geohashAlign52Bits(geohash);
|
||||
|
||||
/* Decode the hash so we can return its bounding box */
|
||||
GeoHashArea area;
|
||||
geohashDecodeWGS84(geohash, &area);
|
||||
|
||||
double lon = (area.longitude.min + area.longitude.max) / 2;
|
||||
double lat = (area.latitude.min + area.latitude.max) / 2;
|
||||
|
||||
/* Return four nested multibulk replies. */
|
||||
addReplyMultiBulkLen(c, 5);
|
||||
|
||||
/* Return the binary geohash we calculated as 52-bit integer */
|
||||
addReplyLongLong(c, bits);
|
||||
|
||||
/* Return the minimum corner */
|
||||
addReplyMultiBulkLen(c, 2);
|
||||
addReplyDouble(c, area.longitude.min);
|
||||
addReplyDouble(c, area.latitude.min);
|
||||
|
||||
/* Return the maximum corner */
|
||||
addReplyMultiBulkLen(c, 2);
|
||||
addReplyDouble(c, area.longitude.max);
|
||||
addReplyDouble(c, area.latitude.max);
|
||||
|
||||
/* Return the averaged center */
|
||||
addReplyMultiBulkLen(c, 2);
|
||||
addReplyDouble(c, lon);
|
||||
addReplyDouble(c, lat);
|
||||
|
||||
/* Return the two scores to query to get the range from the sorted set. */
|
||||
GeoHashFix52Bits min, max;
|
||||
scoresOfGeoHashBox(geohash,&min,&max);
|
||||
addReplyMultiBulkLen(c, 2);
|
||||
addReplyDouble(c, min);
|
||||
addReplyDouble(c, max);
|
||||
}
|
||||
|
||||
/* GEOHASH key ele1 ele2 ... eleN
|
||||
*
|
||||
* Returns an array with an 11 characters geohash representation of the
|
||||
|
@ -285,8 +285,6 @@ struct redisCommand redisCommandTable[] = {
|
||||
{"geoadd",geoaddCommand,-5,"wm",0,NULL,1,1,1,0,0},
|
||||
{"georadius",georadiusCommand,-6,"r",0,NULL,1,1,1,0,0},
|
||||
{"georadiusbymember",georadiusByMemberCommand,-5,"r",0,NULL,1,1,1,0,0},
|
||||
{"geoencode",geoencodeCommand,-3,"r",0,NULL,0,0,0,0,0},
|
||||
{"geodecode",geodecodeCommand,2,"r",0,NULL,0,0,0,0,0},
|
||||
{"geohash",geohashCommand,-2,"r",0,NULL,0,0,0,0,0},
|
||||
{"geopos",geoposCommand,-2,"r",0,NULL,0,0,0,0,0},
|
||||
{"geodist",geodistCommand,-4,"r",0,NULL,0,0,0,0,0},
|
||||
|
@ -72,19 +72,6 @@ start_server {tags {"geo"}} {
|
||||
r georadiusbymember nyc "wtc one" 7 km withdist
|
||||
} {{{wtc one} 0.0000} {{union square} 3.2544} {{central park n/q/r} 6.7000} {4545 6.1975} {{lic market} 6.8969}}
|
||||
|
||||
test {GEOENCODE simple} {
|
||||
r geoencode 1.8063239 41.2358883
|
||||
} {3471579339700058 {1.8063229322433472 41.235888125243704}\
|
||||
{1.806328296661377 41.235890659964866}\
|
||||
{1.8063256144523621 41.235889392604285}\
|
||||
{3471579339700058 3471579339700059}}
|
||||
|
||||
test {GEODECODE simple} {
|
||||
r geodecode 3471579339700058
|
||||
} {{1.8063229322433472 41.235888125243704}\
|
||||
{1.806328296661377 41.235890659964866}\
|
||||
{1.8063256144523621 41.235889392604285}}
|
||||
|
||||
test {GEOHASH is able to return geohash strings} {
|
||||
# Example from Wikipedia.
|
||||
r del points
|
||||
|
Loading…
x
Reference in New Issue
Block a user