diff --git a/src/geo.c b/src/geo.c index 35931f4f5dac2db0921ab27c284e8db545b064df..63500bed7fffa15e7c3b23e211bb18ff3e32a7bb 100644 --- a/src/geo.c +++ b/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 diff --git a/src/redis.c b/src/redis.c index cb5c73771123eb6f3173c92425b4f3b5d2f25beb..0202649243ead303116b27f2858b7e25edd2d6ea 100644 --- a/src/redis.c +++ b/src/redis.c @@ -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}, diff --git a/tests/unit/geo.tcl b/tests/unit/geo.tcl index cf6d8c614ace7792d089bcb82d943bda58a53582..1c6b90b635d3f29cb2a2343871de1e98b56379d8 100644 --- a/tests/unit/geo.tcl +++ b/tests/unit/geo.tcl @@ -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