| tiff_extract_points | R Documentation |
Samples band values from a GeoTIFF at specific (x, y) locations using the file's affine geotransform. Only the strips containing query points are read, making this efficient for sparse point sets on large rasters.
tiff_extract_points(path, x, y = NULL)
path |
Path to a GeoTIFF file. |
x |
Numeric vector of x coordinates, or a data.frame / matrix with
columns named |
y |
Numeric vector of y coordinates (ignored if |
Points that fall outside the raster extent return NA for all bands.
Pixel assignment uses nearest-pixel rounding (i.e., the point is assigned to
the pixel whose center is closest).
A data.frame with columns x, y, band1, band2, etc.
One row per input point, in the same order as the input.
f <- tempfile(fileext = ".tif")
df <- data.frame(x = as.double(rep(1:4, 3)),
y = as.double(rep(1:3, each = 4)),
band1 = as.double(1:12))
write_tiff(df, f)
# Sample at specific locations via data.frame
pts <- data.frame(x = c(2, 3), y = c(1, 2))
tiff_extract_points(f, pts)
# Or pass x and y separately
tiff_extract_points(f, x = c(2, 3), y = c(1, 2))
unlink(f)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.