View source: R/grid_location.R
grid_location | R Documentation |
Grid the locations with fixed cell size
grid_location(
lon,
lat,
sp.resolution = 2,
lon.range = range(lon),
lat.range = range(lat)
)
lon |
Numeric, |
lat |
Numeric, |
sp.resolution |
Numeric, must be a single value that indicates the minimal unit length of a grid cell. |
lon.range |
Optional vector that indicates the range of |
lat.range |
Optional vector that indicates the range of |
The longitude and latitude of each grid cell are the coordinate of the cell center.
For example, if sp.resolution=1
, then cell_lon=55.5
and cell_lat=22.5
correspond to the
square whose left boundary is 55, right boundary is 56, upper boundary is 23, and lower boundary
is 22.
An n x 3
data frame containing three variables: cell_ind
corresponds to unique id
for each grid cell,
cell_lon
is the longitude of the grid cell, cell_lat
is the latitude of the grid cell.
Since the output data frame retains the order of the input coordinates, the original coordinate
dataset and the output have can be linked one-to-one by the row index.
longitude <- runif(20, -90, 80)
latitude <- runif(20, 40, 60)
grid_locs <- grid_location(longitude, latitude, sp.resolution=0.5)
cbind(longitude, latitude, grid_locs)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.