0

In the case of GeoHash, two points that are close can have totally different hash values, making it impossible to do things like prefix comparison. This is due to the fact that somewhere in the ancestry line, there is a split (in geographical grouping).

How does S2 try to solve that problem for the purpose of querying? I read a bunch of posts on S2 but couldn't understand.

Aung Khant
  • 324
  • 3
  • 14

1 Answers1

0

I would not say S2 solves this problem. Two close points may still have totally different cell ids in S2 too. One can argue S2's Hilbert curve makes it somewhat less common than with Z-curve used by GeoHash, but the root problem remains.

When you use S2 you don't normally use prefix comparison though, you use interval search. Alternatively, you compute a few prefixes possible within a specific radius of a point and search for them. You can do both of these approaches with GeoHash too of course.

S2 solves a different problem with GeoHash, which makes it impractical to use GeoHash for nearby search except in local cases: very different size and geometry of the cells. The GeoHash cells near the poles are much smaller (in real area) than the cells of same level near the equator. Near-polar GeoHash cells are also stretched. S2 cells are more even across the globe.

Michael Entin
  • 7,189
  • 3
  • 21
  • 26
  • Can you elaborate more on your second paragraph? It seems like you were saying prefix comparison, in addition to bit manipulation, can be deployed. Which technique is generally suitable for what conditions etc...? – Aung Khant Nov 05 '21 at 09:09
  • Check how S2CellUnion class works. You normally compute a small set of S2Cells that cover the interesting region, and then search for these cells using S2CellUnion.Intersects – Michael Entin Nov 09 '21 at 23:47