Geometry on the Sphere:
Google's S2 Library
Octavian Procopiuc
oprocopiuc@gmail
Library Overview
S2 Cell Hierarchy
S2 Cell Hierarchy - Construction
Overview:
Step 1:
p=(lat,lng) => (x,y,z)
p
S2 Cell Hierarchy - Construction
S2 Cell Hierarchy - Construction
An Aside - Projection Trade-offs
| Area Ratio | Cell -> Point | Point -> Cell |
Linear | 5.20 | 0.087 | 0.085 |
Tangent | 1.41 | 0.299 | 0.258 |
Quadratic | 2.08 | 0.096 | 0.108 |
microseconds
S2 Cell Hierarchy - Construction
Story so far:
Discretize (s,t)
Quad-tree cell: most significant bits of i and j
one of 6 faces
S2 Cell Hierarchy - Construction
Last step:
(face,i,j)=> S2CellId
[ID is a 64-bit integer]
Enumerate cells along a Hilbert space-filling curve
one of 6 faces
S2 Cell Hierarchy - Construction
Last step:
(face,i,j)=> S2CellId
[ID is a 64-bit integer]
Enumerate cells along a Hilbert space-filling curve
one of 6 faces
S2 Cell Hierarchy - Construction
S2 Cell ID of a leaf cell (level 30):
| | | | | | | | | | | | | | | | | | | |
face
(in [0,5])
64 bits
position along the Hilbert curve on the
[0,230-1] x [0,230-1] grid (60 bits)
1
S2 Cell Hierarchy - Construction
S2 Cell ID of a level-2 cell:
| | | | | | | | | | | | | | | | | | | |
face
(in [0,5])
64 bits
position along the Hilbert curve on the
[0,22-1] x [0,22-1] grid (4 bits)
0
1
0
0
0
0
0
0
0
0
0
0
An S2 Cell
Id: 0x89ace41000000000 (0b1000100110101100111001000001000...), Level: 12
S2 Cells - Stats
Level | Min Area | Max Area |
0 | 85,011,012 km2 | 85,011,012 km2 |
1 | 21,252,753 km2 | 21,252,753 km2 |
12 | 3.31 km2 | 6.38 km2 |
30 | 0.48 cm2 | 0.93 cm2 |
smallest cell
Every cm2 on Earth can be represented using a 64-bit integer.
Approximating Regions Using S2 Cells
Given a region, find a (small) set of cells that cover it.
Parameters:
Max # cells | Median ratio (covering area / region area) | Worst ratio |
4 | 3.31 | 15.83 |
8 | 1.98 | 4.03 |
20 | 1.42 | 1.94 |
100 | 1.11 | 1.19 |
default
What Else Is In the Library
Other Similar Libraries