Learn R Programming

CAWaR (version 0.0.2)

extractTS: extractTS

Description

Extracts time series data from a RasterStack for a SpatialPolygons or a SpatialPolygonsDataFrame object.

Usage

extractTS(x, y, z, id)

Arguments

x

Object of class SpatialPolygons, SpatialPolygonsDataFrame, SpatialPoints or SpatialPointsDataFrame.

y

A raster object, a list of RasterLayer objects or a numeric element.

z

Numeric vector with weights for each element in x (when points).

id

Numeric vector with unique identifiers for x (when points).

Value

A list.

Details

For each polygon in x - if x is a SpatialPolygons and SpatialPolygonsDataFrame object - the function identifies the overlapping pixels in y and, for each pixel, estimates the percentage area covered by the polygon. Using this data as weights, the function calculates the weighted mean for each band in y. If y is a numeric element, the function will build a raster with resolution equal to y over which the pixel cover will be estimated. Moreover, if x is a SpatialPoints or a SpatialPointsDataFrame object, the function will skip the pixel extraction step. In this case, the user may provide a vector with sample weights through z and a vector of unique identifiers (reporting on e.g. the polygon membership) The function returns a list of three data.frame objects where each row represents a different polygon in x:

  • pixel.info - SpatialPointsDataFrame with pixel-wise samples for each polygon (identified by the field id).

  • polygon.info - Mean, min, max and standard deviation of the pixel cover; centroid coordinates.

  • weighted.mean - Weighted mean raster values (if y is a raster object).

See Also

analyseTS

Examples

Run this code
# NOT RUN {
{

require(raster)
require(fieldRS)

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

# read field data
data(fieldData)

extractTS(fieldData[1:5,], r)

}
# }

Run the code above in your browser using DataLab