Skip to content

Latest commit

 

History

History
118 lines (78 loc) · 5.28 KB

File metadata and controls

118 lines (78 loc) · 5.28 KB

Google S2

S2 is a library for spherical geometry that aims to have the same robustness, flexibility, and performance as the very best planar geometry libraries.

Why S2

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?

How S2 works

Three dimensional space to two

Given the world

spatial_index_s2_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.

spatial_index_s2_3

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.

Two dimensional space to one

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.

spatial_index_s2_level_0

Indexing

Fill space with Hilbert curve in middle levels.

spatial_index_s2_world_hilbert_curve


spatial_index_s2_simple_hilbert_curve

Deep dive

More info

Doc

Demo

Code

Applications & Examples

Articles