huron
huron

Reputation: 782

Redis: How to get points in a given rectangle using geohash API?

example: Given 3 points (1,1),(2,2),(5,5) and a rectangle (0,0)(3,3), get 2 points (1,1) and (2,2).

It's easy to get points in a circle using georadius, but it seems that there is not a convenient way to get points in a rectangle.

Upvotes: 0

Views: 1492

Answers (2)

Olivier CARRON
Olivier CARRON

Reputation: 21

I stumbled upon this question while exploring redis geospatial capabilities.

You can use the GEOSEARCH command to search points within a bounding box.

And I also found a well-written article explaining how to load a custom lua script to query points within a polygon.

Upvotes: 1

for_stack
for_stack

Reputation: 22926

There's no built-in way to do that.

However, you can do a spatial search with a circle that can cover the whole rectangle. For each retrieved point, check if it's inside the rectangle.

Upvotes: 1

Related Questions