Learn R Programming

rsMove (version 0.2.3)

poly2sample: poly2sample

Description

Converts a raster grid to points depending on how much each pixel is covered by a polygon.

Usage

poly2sample(pol.shp = pol.shp, ref.ext = ref.ext, min.cover = NULL,
  pixel.res = NULL)

Arguments

pol.shp

Object of class SpatialPolygons or SpatialPolygonDataFrame.

ref.ext

Object of class Extent or a RasterLayer from which an extent can be derived.

min.cover

Minimum percent a pixel should be covered by a polygon for sampling (0-100). Default is 100.

pixel.res

Pixel resolution. Required if ref.ext is an Extent object. Unit depends on spatial projection.

Value

A SpatialPointsDataFrame with sampled pixels reporting on polygon percent coverage.

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 ("pol.shp"), poly2sample extracts the overlapping pixels derived from ref.ext. Then, for each pixel, the function estimates the percentage of it that is covered by the reference polygon. Finally, the function extracts coordinate pairs for pixels that has a percent coverage equal to or greater than min.cover.

See Also

dataQuery imgInt

Examples

Run this code
# NOT RUN {
{

 require(raster)

 # load example probability image
 file <- system.file('extdata', 'konstanz_probabilities.tif', package="rsMove")
 img <- raster(file)

 # load area of interest
 file <- system.file('extdata', 'konstanz_roi.shp', package="rsMove")
 roi <- shapefile(file)

 # segment probabilities
 samples <- poly2sample(pol.shp=roi, ref.ext=img)

}
# }

Run the code above in your browser using DataLab