gdallocationinfo: Query raster files at points

Description Usage Arguments Value Examples

Description

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

Usage

1
gdallocationinfo(srcfile, pts, simplify = TRUE, sp = FALSE)

Arguments

srcfile

A character vector of file paths to the raster files to be queried.

pts

A matrix, data.frame, or SpatialPoints* object giving the x and y coordinates of a point (or points), given in the coordinate reference system of the rasters indicated at srcfile.

simplify

Logical. If TRUE, then if all files referred to in srcfile are single band rasters, the sampled values will be simplified to a matrix.

sp

Logical. If TRUE, a SpatialPointsDataFrame will be returned, otherwise a data.frame will be returned. If pts is a SpatialPoints* object and has a non-NA CRS, then if sp is TRUE, the returned object will have that same CRS assigned.

Value

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.

Examples

 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)

johnbaums/things documentation built on May 19, 2019, 3:03 p.m.