Help on finding nearby points to a target location

112 views
Skip to first unread message

Aman Choudhary

unread,
Jun 10, 2018, 5:07:21 AM6/10/18
to s2geometry-io
Hi,
 I have a use case where I have geo location of users and a point in the city and I need to find users who are within 5kms radius of that point. I could represent locations of user and the point with S2 cell id. But how would  I query that?
Do I need to load data for all the users inmemory to my application and then use library to find my target users. Or can I store data for all the users in a database and make query on S2 cell ids as S2 cell id is using Hilbert curve so we know that geo points who have closer S2 cell ids are closer in distance with each other.
Or is there any other method which I am missing
Thanks for  the help in advance

Jesse Rosenstock

unread,
Jun 12, 2018, 12:39:44 PM6/12/18
to s2geometry-io
There are many different options depending on how many users and qps.

In https://github.com/google/s2geometry/tree/master/doc/examples, point_index.cc is an example of keeping all data in-memory.

term_index.cc shows how to generate location terms for your "user documents".

You could also try a database with geospatial support <https://en.wikipedia.org/wiki/Simple_Features>, or maybe even just store lat/lng in the database, query based on S2Cap(query_loc, 5km).GetRectBound(), then filter again as a post-processing step.

Mars Haggenmacher

unread,
Jan 31, 2019, 10:02:34 PM1/31/19
to s2geometry-io
I think the use case he is trying to solve, which many of us are, is NoSQL geoquerying, which means being able to make a single range operation on a single geospatial index. How can the S2 library be used to do that without storing an entire dataset in the client's memory? In other words, can we give S2 a coordinate (the user's current location, in most cases) and get back a range of S2 cells that are within n-radius of that center cell? That way we can query our own databases with a single range operation, like:

where documentGeoIndex >= someS2CellID && <= someS2CellID
Reply all
Reply to author
Forward
0 new messages