S2 Quadtree Representation

S2 Geometry — The New Boss in Location Tracking.

Daval Pargal
2 min readSep 3, 2018

--

Until now our location metrics were based on map projections, which are simply functions that map points on the Earth’s surface to points on a planar map. Map projections create misleading and a little distorted result due to the fact that the shape of the Earth is not very close to the shape of a plane.

For example, The commonly used Mercator projection considers Earth projected on a cylindrical surface which cut opens as a rectangle. Due to such an assumption it is not completely accurate and cannot define a map location for the north pole and south pole.

Hence, no planar projection does a good job of representing the entire surface of the Earth.

Mercator Projection

S2 tries to tackle these problems by working exclusively with spherical projections. Spherical projections map points on the Earth’s surface to a mathematical sphere. This too create distortions because the Earth is not quite spherical but closer to an ellipsoid. Still it is more of like a sphere than a planar surface.

Why not Ellipsoid projections?

Ellipsoid projections are mathematically tough to understand and model. Operations on such a projection are still orders of magnitude slower than operations on a spherical projections (which are pretty easier and straightforward to implement).

How S2 Works?

The S2 Geometry starts by projecting the points/regions of Earth into a cube, and each face of the cube has a quad-tree where the sphere point is projected into.

Projection of Earth on a face of cube with Quad-Trees

Each face projections can be broken into 4 segments and these 4 segments can be further segregated to another 4 blocks. The more depth we create in the quad-tree more uniqueness starts to come to each point on the Earth surface (belonging to a particular small box inside the quad-tree). Each small box area in the projection is termed as a cell and has a unique identification number to identify the region of earth it covers.

How to Represent an S2 id using Quad Trees

Start using this less appreciated library and have a more detailed look at its usage here.

--

--