raster (version 1.0.4)

rasterToPoints: Raster to points conversion

Description

Raster to point conversion. Cells with NA are not converted. A function can be used to select a subset of the raster cells (by their values).

Usage

rasterToPoints(x, fun=NULL, asSpatialPoints=FALSE)

Arguments

x
a Raster object
fun
function to select a subset of raster values
asSpatialPoints
if TRUE, the function returns a SpatialPointsDataFrame object

Value

  • A matrix with three columns: x, y, and v (value), or a SpatialPointsDataFrame object

Details

fun should be a simple function returning a logical value e.g.: fun=function(x){x==1} or fun=function(x){x>3}

Examples

Run this code
r <- raster(nrow=18, ncol=36)
r[] <- runif(ncell(r)) * 10
r[r>8] <- NA
p <- rasterToPoints(r)
p <- rasterToPoints(r, fun=function(x){x>6})
#plot(r)
#points(p)

Run the code above in your browser using DataCamp Workspace