raster (version 1.0.4)

rasterToPolygons: Raster to polygons conversion

Description

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

Usage

rasterToPolygons(raster, fun=NULL)

Arguments

raster
a RasterLayer object
fun
function to select a subset of raster values

Value

  • A SpatialPolygonsDataFrame 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
pol <- rasterToPolygons(r, fun=function(x){x>6})
#plot(r)
#plot(pol, add=T, col='red')

Run the code above in your browser using DataCamp Workspace