Search code examples
redisgeobounding-box

Query Redis geospatial data with a bounding box?


I am trying to find a way to query geospatial data in Redis with a Bounding Box.

After going through all the documentation on Redis's site the only reference to a bounding box I can find is in the GEORADIUS command's documentation;

Time complexity: O(N+log(M)) where N is the number of elements inside the bounding box of the circular area delimited by center and radius and M is the number of items inside the index.

In other words, it seems like there is already a fundamental bounding box inside Redis, but for some reason it does not appear to be readily available to the user. I find this strange.

I am aware that there are some libraries available, such as geo.lua which increases the capabilities of Redis. I would like to avoid extensions to my Redis database if possible, specially since it appears that the concept of a bounding box is already in the geospatial system for Redis.

I keep seeing references to a bounding box everywhere (eg. Redis release notes) Am I missing something obvious?


Solution

  • Regrettably your research is correct - a bounding box query on a geoset is presently not available in core Redis.

    That being the case, your alternative is to perform a radius search that includes the box, and then filter out results that fall outside the box. Filtering can be done:

    • in the client: least efficient but probably easiest
    • server-side Lua: similar to how geo.lua proposes
    • server-side module: probably the most performant (and of possible use for the community) but also less trivial to implement

    You may also submit a feature request to the Redis repository asking for this functionality to be part of the core and describing the use case - IMO it would be a nice addition.