S2 is a library for spherical geometry that aims to have the same robustness, flexibility, and performance as the very best planar geometry libraries.
The main reason for using Google's S2 library is for its support for spatial
indexing. As you put more and more geospatial data in a map, your ability to
query it in a timely and effective manner reduces dramatically. This is a problem
for the likes of Uber, Foursquare and Yelp who deal with colossal amounts of
spatial data.
Now the reason this is cool is that it means you can plot map points on this
curve and when you "stretch" out the curve into a long string and add an index
to each entry, all those points that were close together on the map remain
close together in terms of their index position.
This is great news for searching, because it's a lot easier to find points
that are near to each other on a map when you can access them via their
indexes and they are still close together. It means you don't have to scan
the whole list of points to find ones that are geographically close, but
just a few either side of where your starting position is.
Reference from Quora - Why do we need to use Google S2 geometry library when we already have Google Maps?
Given the world
We first surround the sphere with a cube and project it onto all six of its faces, slightly adjusting the projection on the move to remove distortion. This is level 0.
We could imagine using a box to wrap the world, in the center of the world there is a glowing light bulb, we could project the surface of world to each face of the box.
Then we can divide each of the six faces of the cube into four equal parts - this is level 1. And each of the resulting four parts can be divided into four equal parts - level 2. And so on to level 30.
Fill space with Hilbert curve in middle levels.
- Overview
- S2 main page
- S2 Overview
- S2 Cells★★
- S2 Covering Example
- Geometry on the Sphere: Google's S2 Library - Intro slides from Google