grainchanger (version 0.2.0)

prop: Calculate proportion of a given value

Description

Calculate the proportion of a given value present within a raster. Useful for calculating land-cover or soil type proportions. Should be used with a categorical raster

Usage

prop(x, lc_class, ...)

# S3 method for winmove prop(x, lc_class, d, type, ...)

# S3 method for numeric prop(x, lc_class, ...)

Arguments

x

numeric, winmove. The data over which to calculate the proportion

lc_class

numeric. The class value to calculate the proportion of

...

further arguments passed to or from other methods

d

numeric. If type=circle, the radius of the circle (in units of the CRS). If type=rectangle the dimension of the rectangle (one or two numbers)

type

character. The shape of the moving window

Value

If class(x) == "winmove", a smoothed raster with the proportion of cells of the given class calculated within the specified moving window

If class(x) == "numeric", a single value representing the proportion of values of a given class in x

Examples

Run this code
# NOT RUN {
# load required data
data(cat_ls)

# convert data to object of class winmove
cat_ls <- new("winmove", cat_ls)

# aggregate using a rectangular window with dimension 5 for class 3
d <- prop(cat_ls, d = 5, type = "rectangle", lc_class = 3)

# convert data to object of class numeric
cat_ls <- raster::values(cat_ls)
d <- prop(cat_ls, lc_class = 2)
# }

Run the code above in your browser using DataLab