rangeTraits: A container of functions to apply on a 'SpatialPolygons'...

Description Usage Arguments Details Value See Also Examples

View source: R/utils-spatial.R

Description

This is a convenience function returning a named list of functions.

Usage

1
rangeTraits(..., use.default = TRUE)

Arguments

...

functions, given as myfun = FUN, to apply on a SpatialPolygons object

use.default

If TRUE, the default, the output list contains functions to extract Area, Median, Min and Max extent of the SpatialPolygons object. This option is ignored if no functions are given.

Details

The function returns a named list so any additional functions should be given as rangeTraits(funName1 = FUN1, funName2 = FUN2) where FUN1, FUN2 are SpatialPolygons extractor functions.

Value

Returns a named list containing extractor functions to apply on SpatialPolygons objects.

See Also

processRanges.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
summary(rangeTraits(use.default = FALSE))

f = system.file(package = "rangeMapper", "extdata", "wrens", "vector")
troaed = selectShpFiles(f, ogr = TRUE,
	polygons.only = TRUE)[71, ] # path to Troglodytes_aedon
require(rgdal)
r = readOGR(troaed$dsn, troaed$layer)

# Beware of the value returned for Area!
sapply(rangeTraits(), function(x) x(r) )

# Define an extra function to compute correct Area
Area2 = function(x) {
x = spTransform(x,
CRS("+proj=cea +lon_0=0 +lat_ts=30 +x_0=0 +y_0=0 +ellps=WGS84 +units=m +no_defs")
	)

sum(sapply(slot(x, "polygons"), function(x) slot(x, "area") ))
}

sapply(rangeTraits(Area_sqm = Area2), function(x) x(r) )

valcu/rangeMapper documentation built on Feb. 6, 2021, 8:20 p.m.