row and colum to map unit conversion functions | R Documentation |
x2c
and y2r
return the integer column or row of the x or y
dimension while the fractional versions return real rows and columns. In most
cases the non-fractional version will be prefered.
c2x
and r2y
return the position along the x or y dimension of the center of the cell as a real number; these do not work with fractional row and column values.
c2x(c, list, cellsize = list$cellsize, xll = list$xll)
r2y(r, list, cellsize = list$cellsize, yll = list$yll, nrow = list$nrow)
x2c(x, list, cellsize = list$cellsize, xll = list$xll)
y2r(y, list, cellsize = list$cellsize, yll = list$yll, nrow = list$nrow)
x2fractionalc(x, list, cellsize = list$cellsize, xll = list$xll)
y2fractionalr(y, list, cellsize = list$cellsize, yll = list$yll, nrow = list$nrow)
r, c |
The row and column index of the focal cell. |
x, y |
x and y coordinates of a point in map units |
list |
A list describing spatial location and extent of a grid or access
window containing the following items: |
cellsize |
The size of each cell in map units. |
xll |
The x coordinate of the lower left corner of the lower left (southwest) cell in the landscape or grid. |
yll |
The y coordinate of the lower left corner of the lower left (southwest) cell in the landscape or grid. |
nrow |
The number of rows in the landscape or grid |
These functions provide two ways of passing the spatial reference information:
1. as a list or 2. explicitly by using the remaining arguments. If both are
used the explicit arguments take precedence.
Using the list argument is convenient as none of the subsequent arguments are
required and generally the information will already be in list format as in a
grid
object.
x2c
and y2r
return the column and row index (integer) of the
corresponding x and y dimension.
r2y
and c2x
return the y or x dimension (a real number) of the
center of the cells with the corresponding row or column index.
x2c
and y2r
return the precise location in column and row space
(a real number) of of the corresponding x and y dimension.
Ethan Plunkett
grid-class
g <- asgrid(matrix(1:12, 3, 4, byrow = TRUE), xll = 0, yll = 0, cellsize = 10)
x = c(5, 15)
y = c(11, 21)
plot(g, restore.par = FALSE)
points(x, y)
g$m[cbind(y2r(y, g), x2c(x, g))] # sample x and y locations from grid
x2c(20, g) # x and y values that fall exactly on the boundary are
y2r(10, g) # considered part of the row or column with the lower index value
# This is the cell to the west or north
# as the first row in the matrix is the northernmost and the first
# column is the westernmost
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.