box_fun | R Documentation |
Give a row and column number, then get all pixels surrounding it in a box (and planning to add ability to do a radius)
box_fun(r, boxsize, rowcol, pad = FALSE)
r |
Raster layer or matrix |
boxsize |
Size of box, must be an odd number in row, column order (i.e., 3 OR c(3,3) for a box 3 rows by 3 columns, c(3, 5) for box of 3 rows by 5 columns). '1' indicates just getting the matchup pixel |
rowcol |
A data frame with row and col of point. See example below |
pad |
TRUE/FALSE, for matrix r only: If rowcol is at the edge of r, should the function return a box with extra NA cells padding the edges (or just cut it off at the edge)? |
Numeric vector of pixel values. (Will add cell numbers at some point)
library(raster)
pt_x = -127.5
pt_y = 49.5
r = yourraster
#Get row and col of your point
xy = extract(r, y = cbind(pt_x, pt_y), cellnumbers=T, df=T)
xy <- as.data.frame(rowColFromCell(s, cell = xy$cells))
# Get pixel values in a 3x3 box around your point
box_fun(r, 3, xy)
#Get a 3x5 box (3 rows by 5 columns) from the same location
box_fun(r, c(3,5), xy)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.