extract {quadtree}R Documentation

Extract Quadtree values

Description

Extracts the cell values and optionally the cell extents at the given points.

Usage

## S4 method for signature 'Quadtree,ANY'
extract(x, y, extents = FALSE)

Arguments

x

a Quadtree

y

a two-column matrix representing point coordinates. First column contains the x-coordinates, second column contains the y-coordinates

extents

boolean; if FALSE (the default), a vector containing cell values is returned. If TRUE, a matrix is returned providing each cell's extent in addition to its value

Value

If extents = FALSE, returns a numeric vector corresponding to the values at the points represented by pts.

If extents = TRUE, returns a six-column numeric matrix providing the extent of each cell along with the cell's value and ID. The six columns are, in this order: id, xmin, xmax, ymin, ymax, value.

Examples

library(quadtree)
habitat <- terra::rast(system.file("extdata", "habitat.tif", package="quadtree"))

# create quadtree
qt1 <- quadtree(habitat, split_threshold = .1, adj_type = "expand")
plot(qt1)

# create points at which we'll extract values
coords <- seq(-1000, 40010, length.out = 10)
pts <- cbind(coords,coords)

# extract the cell values
vals <- extract(qt1, pts)

# plot the quadtree and the points
plot(qt1, border_col = "gray50", border_lwd = .4)
points(pts, pch = 16, cex = .6)
text(pts, labels = round(vals, 2), pos = 4)

# we can also extract the cell extents in addition to the values
extract(qt1, pts, extents = TRUE)

[Package quadtree version 0.1.14 Index]