0

Let's say I have a list of restaurants and I have the location of a customer that's looking for restaurants that are nearby. How could I use S2?

From my understanding without S2, I would maintain my own Quad Tree that has all the restaurants and then I would take the latitude and longitude of my customer and query my Quad Tree to find the node and neighbor Quad Tree nodes.

How would S2 fit into this picture? Would it replace the need for me to maintain my own Quad Tree?

My understanding of S2 is that under the hood there's Quad Trees and Hilber space-filling curves which given a latitude and longitude can provide a 64 bit cell ID that identifies the node in the Quad Tree that the latitude and longitude belong to.

Dipen
  • 536
  • 2
  • 5
  • 13

2 Answers2

1

The way you normally do it in S2 is through existing S2 API classes, e.g. here I would use S2ClosestPointQuery.

Internally the query class builds an internal index (in this case - using S2 cells of the restaurants), and when you want to find all points nearby a customer it computes the range of cells on S2's Hilbert curve that are within the given distance from the search location (in this case - customer location), and looks for those cells in the index.

Michael Entin
  • 7,189
  • 3
  • 21
  • 26
  • Interesting, so would Google or whoever is offering the S2 library store the Quad Tree on their end? Would they charge money? – Dipen Oct 04 '21 at 01:44
  • S2 library is supplied as source code, you just include it in your app. There is no service to sign up or pay for here, if I understand you correctly. Just make sure you are Ok with it's (ver flexible) Apache 2.0 open source license. – Michael Entin Oct 04 '21 at 02:59
  • Ok that makes sense. I’m just curious, if I’m Yelp and I have hundreds of thousands of locations to store, does S2 partition data? I’m wondering how scaling S2 would work. – Dipen Oct 04 '21 at 05:22
0

This article from Tinder is exactly what I was looking for.

https://medium.com/tinder-engineering/geosharded-recommendations-part-1-sharding-approach-d5d54e0ec77a

If you’re building a service that needs requires partitioning geo data, you would use S2 to give you a number encoding of specific locations or a range of number encodings for a specfic radius. You would maintain the partioning scheme yourself.

Dipen
  • 536
  • 2
  • 5
  • 13