olp-cpp-sdk  1.22.0
Public Types | Public Member Functions | Static Public Member Functions | List of all members
olp::geo::TileKey Class Reference

Addresses a tile in a quadtree. More...

#include <TileKey.h>

Public Types

enum  { LevelCount = 32 }
 
enum  { MaxLevel = LevelCount - 1 }
 
enum class  TileKeyQuadrant : uint8_t {
  SW , SE , NW , NE ,
  Invalid
}
 The main direction used to find a child node or the relationship to the parent. More...
 

Public Member Functions

constexpr TileKey ()
 Creates an invalid tile key.
 
constexpr TileKey (const TileKey &)=default
 The default copy constructor.
 
TileKeyoperator= (const TileKey &)=default
 The default copy operator.
 
constexpr bool IsValid () const
 Checks whether the tile key is valid.
 
constexpr bool operator== (const TileKey &other) const
 Checks whether the tile keys are equal. More...
 
constexpr bool operator!= (const TileKey &other) const
 Checks whether the tile keys are not equal. More...
 
constexpr bool operator< (const TileKey &other) const
 Implements the following order on tile keys so they can be used in maps: first level, row, and then column. More...
 
std::string ToQuadKey () const
 Creates a quad string from a tile key to later use it in REST API calls. More...
 
std::string ToHereTile () const
 Creates a HERE tile code string from a tile key to later use it in REST API calls. More...
 
std::uint64_t ToQuadKey64 () const
 Creates a 64-bit Morton code from a tile key. More...
 
constexpr std::uint32_t Level () const
 Gets the tile level. More...
 
constexpr std::uint32_t Row () const
 Gets the tile row. More...
 
constexpr std::uint32_t RowCount () const
 Gets the number of available rows at the tile level. More...
 
constexpr std::uint32_t Column () const
 Gets the tile column. More...
 
constexpr std::uint32_t ColumnCount () const
 Gets the number of available columns at the tile level. More...
 
TileKey Parent () const
 Gets the key of the parent tile. More...
 
bool IsChildOf (const TileKey &tile_key) const
 Checks whether the current tile is a child of another tile. More...
 
bool IsParentOf (const TileKey &tile_key) const
 Checks whether the current tile is a parent of another tile. More...
 
TileKey ChangedLevelBy (int delta) const
 Gets a new tile key at a level that differs from this tile level by delta. More...
 
TileKey ChangedLevelTo (std::uint32_t level) const
 Gets a new tile key at the requested level. More...
 
std::uint64_t GetSubkey64 (int delta) const
 Gets a subquadkey that is a relative of its parent. More...
 
TileKey AddedSubkey64 (std::uint64_t sub_quad_key) const
 Gets the absolute quadkey that is constructed from its subquadkey. More...
 
TileKey AddedSubkey (const std::string &sub_quad_key) const
 Gets the absolute quadkey that is constructed from its subquadkey. More...
 
TileKey AddedSubHereTile (const std::string &sub_here_tile) const
 Gets the absolute quadkey that is constructed from its HERE child tile key. More...
 
constexpr bool HasNextRow () const
 Checks whether there is the next row at this level. More...
 
TileKey NextRow () const
 Gets the key of the tile that has the same level and column numbers but belongs to the next row. More...
 
constexpr bool HasNextColumn () const
 Checks whether there is the next column at this level. More...
 
TileKey NextColumn () const
 Gets the key of the tile that has the same level and row numbers but belongs to the next column. More...
 
constexpr bool HasPreviousRow () const
 Checks whether there is the previous row at this level. More...
 
TileKey PreviousRow () const
 Gets the key of the tile that has the same level and column numbers but belongs to the previous row. More...
 
constexpr bool HasPreviousColumn () const
 Checks whether there is the previous column at this level. More...
 
TileKey PreviousColumn () const
 Gets the key of the tile that has the same level and row numbers but belongs to the previous column. More...
 
TileKey GetChild (std::uint8_t index) const
 Gets the child of the current tile by its index. More...
 
TileKey GetChild (TileKeyQuadrant direction) const
 Gets the child of the current tile using a direction. More...
 
TileKeyQuadrant RelationshipToParent () const
 Computes the direction of the relationship to the parent. More...
 

Static Public Member Functions

static TileKey FromQuadKey (const std::string &quad_key)
 Creates a tile key from a quad string. More...
 
static TileKey FromHereTile (const std::string &key)
 Creates a tile key from a HERE tile code string. More...
 
static TileKey FromQuadKey64 (std::uint64_t quad_key)
 Creates a tile key from a 64-bit Morton code. More...
 
static TileKey FromRowColumnLevel (std::uint32_t row, std::uint32_t column, std::uint32_t level)
 Creates a tile key. More...
 

Detailed Description

Addresses a tile in a quadtree.

Each tile key is defined by a row, a column, and a level. The tree has a root at level 0 with one single tile. At every level, each tile is divided into four child tiles (hence the name quadtree).

Within a level, each tile has its unique row and column numbers. The number of rows and columns in each level is 2 to the power of the level. It means that on level 0, there is only one tile in one row and one column. At level 1, there are four tiles in two rows and two columns. At level 2, there are 16 tiles in four rows and four columns. And so on.

To create a tile key, use FromRowColumnLevel().

For vertical navigation within the tree, use the following functions: Parent(), ChangedLevelBy(), and ChangedLevelTo(). To navigate within a level, use the HasNextRow(), NextRow(), HasNextColumn(), and NextColumn() functions. To get the number of available rows and columns on the tile level, use RowCount() and ColumnCount().

You can also create tile keys from and converted them into various alternative formats:

Member Enumeration Documentation

◆ TileKeyQuadrant

enum olp::geo::TileKey::TileKeyQuadrant : uint8_t
strong

The main direction used to find a child node or the relationship to the parent.

Corresponds directly to the index in the GetChild function.

Member Function Documentation

◆ AddedSubHereTile()

TileKey olp::geo::TileKey::AddedSubHereTile ( const std::string &  sub_here_tile) const

Gets the absolute quadkey that is constructed from its HERE child tile key.

Parameters
sub_here_tileThe HERE child tile key.
Returns
The absolute tile key in the quadtree.

◆ AddedSubkey()

TileKey olp::geo::TileKey::AddedSubkey ( const std::string &  sub_quad_key) const

Gets the absolute quadkey that is constructed from its subquadkey.

It is the reverse function of GetSubkey(). It returns the absolute quadkey in the tree based on the subquadkey.

Parameters
sub_quad_keyThe subquadkey generated with ToSubQuadKey().
Returns
The absolute quadkey in the quadtree.

◆ AddedSubkey64()

TileKey olp::geo::TileKey::AddedSubkey64 ( std::uint64_t  sub_quad_key) const

Gets the absolute quadkey that is constructed from its subquadkey.

It is the reverse function of GetSubkey(). It returns the absolute quadkey in the tree based on the subquadkey.

Parameters
sub_quad_keyThe subquadkey generated with ToSubQuadKey().
Returns
The absolute quadkey in the quadtree.

◆ ChangedLevelBy()

TileKey olp::geo::TileKey::ChangedLevelBy ( int  delta) const

Gets a new tile key at a level that differs from this tile level by delta.

Equivalent to changedLevelTo(Level() + delta)

Parameters
deltaThe numeric difference between the current level and the requested level.
Returns
The tile key at the level that differs from this tile level by delta.

◆ ChangedLevelTo()

TileKey olp::geo::TileKey::ChangedLevelTo ( std::uint32_t  level) const

Gets a new tile key at the requested level.

Parameters
levelThe requested level.
Returns
If the requested level is smaller than the tile level, the key of the tile ancestor is returned. If the requested level is larger than the tile level, the returned value is the key of the first child or grandchild, which is the child with the lowest row and column number. If the requested level equals the level of this tile, the tile key itself is returned.

◆ Column()

constexpr std::uint32_t olp::geo::TileKey::Column ( ) const
inlineconstexpr

Gets the tile column.

To get the number of available columns on a tile level, use ColumnCount().

Returns
The tile column.

◆ ColumnCount()

constexpr std::uint32_t olp::geo::TileKey::ColumnCount ( ) const
inlineconstexpr

Gets the number of available columns at the tile level.

It is 2 to the power of the level.

Returns
The number of available columns.

◆ FromHereTile()

static TileKey olp::geo::TileKey::FromHereTile ( const std::string &  key)
static

Creates a tile key from a HERE tile code string.

To convert the tile key back into the string, use ToHereTile().

◆ FromQuadKey()

static TileKey olp::geo::TileKey::FromQuadKey ( const std::string &  quad_key)
static

Creates a tile key from a quad string.

To convert the tile key back into the quad string, use ToQuadKey().

◆ FromQuadKey64()

static TileKey olp::geo::TileKey::FromQuadKey64 ( std::uint64_t  quad_key)
static

Creates a tile key from a 64-bit Morton code.

To convert a tile key back into a 64-bit Morton code, use ToQuadKey64().

◆ FromRowColumnLevel()

static TileKey olp::geo::TileKey::FromRowColumnLevel ( std::uint32_t  row,
std::uint32_t  column,
std::uint32_t  level 
)
static

Creates a tile key.

Parameters
rowThe requested row. Must be less than 2 to the power of the level.
columnThe requested column. Must be less than 2 to the power of the level.
levelThe requested level.

◆ GetChild() [1/2]

TileKey olp::geo::TileKey::GetChild ( std::uint8_t  index) const

Gets the child of the current tile by its index.

Parameters
indexThe child index from the [0, 3] range.
Returns
The child of the current child.

◆ GetChild() [2/2]

TileKey olp::geo::TileKey::GetChild ( TileKeyQuadrant  direction) const

Gets the child of the current tile using a direction.

Parameters
directionThe direction to get the child tile.
Returns
The child of the current tile.

◆ GetSubkey64()

std::uint64_t olp::geo::TileKey::GetSubkey64 ( int  delta) const

Gets a subquadkey that is a relative of its parent.

Use this function to generate subkeys that are relatives of a parent that is delta levels up in the subtree.

You can also use this function to create shortened keys for quads on lower levels if the parent is known.

Note
The subquadkeys fit in a 16-bit unsigned integer if the delta is smaller than 8. If the delta is smaller than 16, the subquadkey fits into a 32-bit unsigned integer.
Parameters
deltaThe number of levels that are relatives of the parent quadkey. Must be greater or equal to 0 and smaller than 32.
Returns
The quadkey relative of its parent that is delta levels up the tree.

◆ HasNextColumn()

constexpr bool olp::geo::TileKey::HasNextColumn ( ) const
inlineconstexpr

Checks whether there is the next column at this level.

Returns
True if there is the next column; false otherwise.

◆ HasNextRow()

constexpr bool olp::geo::TileKey::HasNextRow ( ) const
inlineconstexpr

Checks whether there is the next row at this level.

Returns
True if there is the next row; false otherwise.

◆ HasPreviousColumn()

constexpr bool olp::geo::TileKey::HasPreviousColumn ( ) const
inlineconstexpr

Checks whether there is the previous column at this level.

Returns
True if there is the previous column; false otherwise.

◆ HasPreviousRow()

constexpr bool olp::geo::TileKey::HasPreviousRow ( ) const
inlineconstexpr

Checks whether there is the previous row at this level.

Returns
True if there is the previous row; false otherwise.

◆ IsChildOf()

bool olp::geo::TileKey::IsChildOf ( const TileKey tile_key) const

Checks whether the current tile is a child of another tile.

Parameters
[in]tile_keyThe key of the possible parent tile.
Returns
A value indicating whether the current tile is a child of the specified tile.

◆ IsParentOf()

bool olp::geo::TileKey::IsParentOf ( const TileKey tile_key) const

Checks whether the current tile is a parent of another tile.

Parameters
[in]tile_keyThe key of the child tile.
Returns
A value indicating whether the current tile is a parent of the specified tile.

◆ Level()

constexpr std::uint32_t olp::geo::TileKey::Level ( ) const
inlineconstexpr

Gets the tile level.

Returns
The tile level.

◆ NextColumn()

TileKey olp::geo::TileKey::NextColumn ( ) const

Gets the key of the tile that has the same level and row numbers but belongs to the next column.

Returns
The tile key with the column number increased by one.

◆ NextRow()

TileKey olp::geo::TileKey::NextRow ( ) const

Gets the key of the tile that has the same level and column numbers but belongs to the next row.

Returns
The tile key with the row number increased by one.

◆ operator!=()

constexpr bool olp::geo::TileKey::operator!= ( const TileKey other) const
inlineconstexpr

Checks whether the tile keys are not equal.

Parameters
otherThe other tile key.

◆ operator<()

constexpr bool olp::geo::TileKey::operator< ( const TileKey other) const
inlineconstexpr

Implements the following order on tile keys so they can be used in maps: first level, row, and then column.

If you need more locality, use the 64-bit Morton encoding instead (ToQuadKey64()).

◆ operator==()

constexpr bool olp::geo::TileKey::operator== ( const TileKey other) const
inlineconstexpr

Checks whether the tile keys are equal.

Parameters
otherThe other tile key.

◆ Parent()

TileKey olp::geo::TileKey::Parent ( ) const

Gets the key of the parent tile.

If the tile is the root tile, an invalid tile key is returned.

Returns
The key of the parent tile.

◆ PreviousColumn()

TileKey olp::geo::TileKey::PreviousColumn ( ) const

Gets the key of the tile that has the same level and row numbers but belongs to the previous column.

Returns
The tile key with the column number decreased by one.

◆ PreviousRow()

TileKey olp::geo::TileKey::PreviousRow ( ) const

Gets the key of the tile that has the same level and column numbers but belongs to the previous row.

Returns
The tile key with the row number decreased by one.

◆ RelationshipToParent()

TileKeyQuadrant olp::geo::TileKey::RelationshipToParent ( ) const

Computes the direction of the relationship to the parent.

Returns
Invalid if the tile key represents the root.

◆ Row()

constexpr std::uint32_t olp::geo::TileKey::Row ( ) const
inlineconstexpr

Gets the tile row.

To get the number of rows at a level, use RowCount().

Returns
The tile row.

◆ RowCount()

constexpr std::uint32_t olp::geo::TileKey::RowCount ( ) const
inlineconstexpr

Gets the number of available rows at the tile level.

It is 2 to the power of the level.

Returns
The number of available rows.

◆ ToHereTile()

std::string olp::geo::TileKey::ToHereTile ( ) const

Creates a HERE tile code string from a tile key to later use it in REST API calls.

The string is a quadkey Morton code.

To convert the HERE tile code string back into the tile key, use FromHereTile().

◆ ToQuadKey()

std::string olp::geo::TileKey::ToQuadKey ( ) const

Creates a quad string from a tile key to later use it in REST API calls.

If the tile is the root tile, the quadkey is '-'. Otherwise, the string is a number to the base of 4 without the leading 1 and has the following properties:

  • The number of digits is equal to the level.
  • Removing the last digit gives the parent tile's quadkey string. For example, to get the child tile, add 0, 1, 2, or 3 to a quadkey string.

To convert the quadkey string back into the tile key, use FromQuadKey().

◆ ToQuadKey64()

std::uint64_t olp::geo::TileKey::ToQuadKey64 ( ) const

Creates a 64-bit Morton code from a tile key.

To convert the 64-bit Morton code back into the tile key, use FromQuadKey64().


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