Learn R Programming

s2 (version 1.1.7)

s2_cell: Create S2 Cell vectors

Description

The S2 cell indexing system forms the basis for spatial indexing in the S2 library. On their own, S2 cells can represent points or areas. As a union, a vector of S2 cells can approximate a line or polygon. These functions allow direct access to the S2 cell indexing system and are designed to have minimal overhead such that looping and recursion have acceptable performance when used within R code.

Usage

s2_cell(x = character())

s2_cell_sentinel()

s2_cell_invalid()

as_s2_cell(x, ...)

# S3 method for s2_cell as_s2_cell(x, ...)

# S3 method for character as_s2_cell(x, ...)

# S3 method for s2_geography as_s2_cell(x, ...)

# S3 method for wk_xy as_s2_cell(x, ...)

# S3 method for integer64 as_s2_cell(x, ...)

new_s2_cell(x)

Value

An object of class s2_cell

Arguments

x

The canonical S2 cell identifier as a character vector.

...

Passed to methods

Details

Under the hood, S2 cell vectors are represented in R as vectors of type double(). This works because S2 cell identifiers are 64 bits wide, as are doubles on all systems where R runs (The same trick is used by the bit64 package to represent signed 64-bit integers). As a happy accident, NA_real_ is not a valid or meaningful cell identifier, so missing value support in the way R users might expect is preserved. It is worth noting that the underlying value of s2_cell_sentinel() would normally be considered NA; however, as it is meaningful and useful when programming with S2 cells, custom is.na() and comparison methods are implemented such that s2_cell_sentinel() is greater than all valid S2 cells and not considered missing. Users can and should implement compiled code that uses the underlying bytes of the vector, ensuring that the class of any returned object that should be interpreted in this way is constructed with new_s2_cell().

Examples

Run this code
s2_cell("4b59a0cd83b5de49")
as_s2_cell(s2_lnglat(-64, 45))
as_s2_cell(s2_data_cities("Ottawa"))

Run the code above in your browser using DataLab