poly2sample: poly2sample

Description Usage Arguments Details Value See Also Examples

View source: R/poly2sample.R

Description

Converts a raster grid to point samples based on a overlapping polygon.

Usage

1
poly2sample(x, y, preserve.id = TRUE, min.cover = 0)

Arguments

x

Object of class SpatialPolygons or SpatialPolygonDataFrame.

y

A raster object or a numeric element.

preserve.id

Logical. Should the output be polygon-wide?

min.cover

A numeric element between 0 and 1.

Details

poly2Sample extends on the rasterize function from the raster package making it more efficient over large areas and converting its output into point samples rather than a raster object. For each polygon in ("x"), poly2sample extracts the overlapping pixels of a reference grid. Then, for each pixel, the function estimates the percentage of it that is covered by the reference polygon. If y is a raster object, the function will use it as a reference grid. If y is a numeric element, the function will build a raster from the extent of x and a resolution equal to y. Sometimes, two or more polygons can cover the same pixel. When this happens, the function will assign this pixel to each of the overlapping polygons and thus replicate this sample. When we want to analyze each polygon individually this can be useful. However, if e.g. the polygons are all of same class and we want to avoid replicated samples, we can set preserve.id to FALSE. When doing so, the function will identify all the unique pixels covered polygons and for, the duplicated it will sum the percent cover values. Points with percent values below min.cover will be omitted from the output.

Value

A SpatialPointsDataFrame with sampled pixels reporting on polygon percent coverage.

See Also

raster2sample ccLabel

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
{

 require(raster)

 # read raster data
 r <- raster(system.file("extdata", "ndvi.tif", package="fieldRS")[1])

 # read field data
 data(fieldData)
 fieldData <- fieldData[1,]

 # extract samples
 samples <- poly2sample(fieldData, r)

}

RRemelgado/fieldRS documentation built on June 5, 2020, 1:48 p.m.