a5_lonlat_to_cell() maps longitude/latitude coordinates to the cell
containing each point at a resolution. a5_cell_to_lonlat() returns the
centre point of each cell. Indexing a cell's centre at the cell's own
resolution returns the cell.
Arguments
- lon
Numeric vector of longitudes in degrees.
- lat
Numeric vector of latitudes in degrees, between -90 and 90. Non-finite coordinates (
NA,NaN,Inf) giveNAcells.- resolution
Integer scalar or vector of resolutions (0–30), recycled against
lonandlat.- cell
An a5_cell vector (or character coercible to one).
- as_dataframe
Logical scalar controlling the return container. When
FALSE(default), centres are returned as awk::xy()vector with WGS 84 CRS, the geographic-typed form that plugs into wk/sf pipelines. WhenTRUE, centres are returned as a basedata.framewith columnslonandlat.
See also
a5_cell_to_boundary() for full cell polygons,
a5_polygon_to_cells() for areas.
Examples
cell <- a5_lonlat_to_cell(-3.19, 55.95, resolution = 5)
a5_cell_to_lonlat(cell)
#> <wk_xy[1] with CRS=OGC:CRS84>
#> [1] (-3.280745 56.43135)
a5_cell_to_lonlat(cell, as_dataframe = TRUE)
#> lon lat
#> 1 -3.280745 56.43135
# a cell's centre indexes back to the cell
ll <- a5_cell_to_lonlat(cell, as_dataframe = TRUE)
a5_lonlat_to_cell(ll$lon, ll$lat, resolution = 5) == cell
#> [1] TRUE
