box_fun: Extract a matchup box from a raster

box_funR Documentation

Extract a matchup box from a raster

Description

Give a row and column number, then get all pixels surrounding it in a box (and planning to add ability to do a radius)

Usage

box_fun(r, boxsize, rowcol, pad = FALSE)

Arguments

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)?

Value

Numeric vector of pixel values. (Will add cell numbers at some point)

Examples


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)


BIO-RSG/oceancolouR documentation built on April 30, 2024, 7:54 a.m.