Description Usage Arguments Value Examples
Return cell values for one or more raster files, at a given point or set of
points. Requires that GDAL is installed and avilable to system
(i.e.
listed in the PATH environmental variable).
1 | gdallocationinfo(srcfile, pts, simplify = TRUE, sp = FALSE)
|
srcfile |
A character vector of file paths to the raster files to be queried. |
pts |
A |
simplify |
Logical. If |
sp |
Logical. If |
If only one file is queried, then a matrix is returned, with columns
corresponding to bands of the file. If simplify
is TRUE
and
all files are single band, the returned value will be a matrix
with
one column for each file, and rows giving the values of cells corresponding
to the coordinates given by x
and y
. If simplify
is
FALSE
, or if one or more files is multiband, the returned value is a
list of matrices, with the columns of each matrix corresponding to the
bands of the file. Further, if sp
is TRUE
, data will be
returned as SpatialPointsDataFrames
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | library(raster)
r <- raster(matrix(runif(1.6e7), ncol=4000))
r[sample(ncell(r), 10000000)] <- NA
writeRaster(r, f <- tempfile(fileext='.tif'))
file.info(f)
xy <- data.frame(x=runif(10000), y=runif(10000))
# Querying a single file at xy
vals <- gdallocationinfo(f, pts=xy)
# Querying multiple files (here identical) at xy:
vals2 <- gdallocationinfo(c(f, f, f), pts=xy)
# Returning as a SpatialPointsDataFrame
vals2 <- gdallocationinfo(c(f, f, f), pts=xy, sp=TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.