cesium-native  0.41.0
CesiumGeospatial::S2CellID Class Reference

A 64-bit unsigned integer that uniquely identifies a cell in the S2 cell decomposition. More...

#include <CesiumGeospatial/S2CellID.h>

Public Member Functions

 S2CellID (uint64_t id)
 Constructs a new S2 cell ID. More...
 
bool isValid () const
 Determines if this cell ID is valid. More...
 
uint64_t getID () const
 Gets the ID of the cell. More...
 
std::string toToken () const
 Converts the cell ID to a hexadecimal token.
 
int32_t getLevel () const
 Gets the level of the cell from the cell ID. More...
 
uint8_t getFace () const
 Gets the face id (0...5) for this S2 cell.
 
Cartographic getCenter () const
 Gets the longitude/latitude position at the center of this cell. More...
 
std::array< Cartographic, 4 > getVertices () const
 Gets the vertices at the corners of the cell. More...
 
S2CellID getParent () const
 Gets the parent cell of this cell. More...
 
S2CellID getChild (size_t index) const
 Gets a child cell of this cell. More...
 
GlobeRectangle computeBoundingRectangle () const
 Computes the globe rectangle that bounds this cell. More...
 

Static Public Member Functions

static S2CellID fromToken (const std::string_view &token)
 
static S2CellID fromFaceLevelPosition (uint8_t face, uint32_t level, uint64_t position)
 Creates a cell given its face (range 0..5), level, and Hilbert curve cell index within that face and level. More...
 
static S2CellID fromQuadtreeTileID (uint8_t face, const CesiumGeometry::QuadtreeTileID &quadtreeTileID)
 Create an S2 id from a face and a quadtree tile id. More...
 

Detailed Description

A 64-bit unsigned integer that uniquely identifies a cell in the S2 cell decomposition.

It has the following format:

id = [face][face_pos]

face: a 3-bit number (range 0..5) encoding the cube face.

face_pos: a 61-bit number encoding the position of the center of this cell along the Hilbert curve over this face (see the Wiki pages for details).

Sequentially increasing cell ids follow a continuous space-filling curve over the entire sphere. They have the following properties:

  • The id of a cell at level k consists of a 3-bit face number followed by k bit pairs that recursively select one of the four children of each cell. The next bit is always 1, and all other bits are 0. Therefore, the level of a cell is determined by the position of its lowest-numbered bit that is turned on (for a cell at level k, this position is 2 * (kMaxLevel - k).)
  • The id of a parent cell is at the midpoint of the range of ids spanned by its children (or by its descendants at any level).

This class is adapted from S2CellId in https://github.com/google/s2geometry.

Definition at line 47 of file S2CellID.h.

Constructor & Destructor Documentation

◆ S2CellID()

CesiumGeospatial::S2CellID::S2CellID ( uint64_t  id)

Constructs a new S2 cell ID.

The cell ID value is not validated. Use isValid to check the validity after constructions.

Parameters
idThe 64-bit cell ID value.

Member Function Documentation

◆ computeBoundingRectangle()

GlobeRectangle CesiumGeospatial::S2CellID::computeBoundingRectangle ( ) const

Computes the globe rectangle that bounds this cell.

Returns
The globe rectangle.

◆ fromFaceLevelPosition()

static S2CellID CesiumGeospatial::S2CellID::fromFaceLevelPosition ( uint8_t  face,
uint32_t  level,
uint64_t  position 
)
static

Creates a cell given its face (range 0..5), level, and Hilbert curve cell index within that face and level.

Parameters
faceThe face index.
levelThe level within the face.
positionThe Hilbert-order index of the cell within the face and level.
Returns
The cell.

◆ fromQuadtreeTileID()

static S2CellID CesiumGeospatial::S2CellID::fromQuadtreeTileID ( uint8_t  face,
const CesiumGeometry::QuadtreeTileID quadtreeTileID 
)
static

Create an S2 id from a face and a quadtree tile id.

Parameters
faceThe S2 face (0...5) that this tile is on.
quadtreeTileIDThe quadtree tile id for this tile, within the given face.

◆ fromToken()

static S2CellID CesiumGeospatial::S2CellID::fromToken ( const std::string_view &  token)
static

Creates a new S2Cell from a token. A token is a hexadecimal representation of the 64-bit S2CellID.

Parameters
tokenThe token for the S2 Cell.
Returns
A new S2CellID.

◆ getCenter()

Cartographic CesiumGeospatial::S2CellID::getCenter ( ) const

Gets the longitude/latitude position at the center of this cell.

The height is always 0.0.

Returns
The center.

◆ getChild()

S2CellID CesiumGeospatial::S2CellID::getChild ( size_t  index) const

Gets a child cell of this cell.

If the index is less than 0 or greater than 3, or if this is a leaf cell, the behavior is unspecified.

Parameters
indexThe index in the range 0 to 3.
Returns
The child cell.

◆ getID()

uint64_t CesiumGeospatial::S2CellID::getID ( ) const
inline

Gets the ID of the cell.

Returns
The ID.

Definition at line 104 of file S2CellID.h.

◆ getLevel()

int32_t CesiumGeospatial::S2CellID::getLevel ( ) const

Gets the level of the cell from the cell ID.

Returns
The cell ID, where 0 is the root.

◆ getParent()

S2CellID CesiumGeospatial::S2CellID::getParent ( ) const

Gets the parent cell of this cell.

If this is a root cell, the behavior is unspecified.

◆ getVertices()

std::array<Cartographic, 4> CesiumGeospatial::S2CellID::getVertices ( ) const

Gets the vertices at the corners of the cell.

The height values are always 0.0.

Note that all positions inside the S2 Cell are not guaranteed to fall inside the rectangle formed by these vertices.

Returns
Four vertices specifying the corners of this cell.

◆ isValid()

bool CesiumGeospatial::S2CellID::isValid ( ) const

Determines if this cell ID is valid.

Returns
true if the the cell ID refers to a valid cell; otherwise, false.

The documentation for this class was generated from the following file: