group_polys: Group Polygons

Description Usage Arguments Details Value See Also Examples

View source: R/group_polys.R

Description

group_polys groups rows into spatial groups by overlapping polygons (home ranges). The function accepts a data.table with relocation data, individual identifiers and an area argument. The relocation data is transformed into home range SpatialPolygons. If the area argument is FALSE, group_polys returns grouping calculated by overlap. If the area argument is TRUE, the area and proportion of overlap is calculated. Relocation data should be in two columns representing the X and Y coordinates.

Usage

1
2
3
group_polys(DT = NULL, area = NULL, hrType = NULL, hrParams = NULL,
  projection = NULL, id = NULL, coords = NULL, splitBy = NULL,
  spPolys = NULL)

Arguments

DT

input data.table

area

boolean indicating either overlap group (when FALSE) or area and proportion of overlap (when TRUE)

hrType

type of HR estimation, either 'mcp' or 'kernel'

hrParams

a named list of parameters for adehabitatHR functions

projection

PROJ.4 character string

id

Character string of ID column name

coords

Character vector of X coordinate and Y coordinate column names

splitBy

(optional) character string or vector of grouping column name(s) upon which the grouping will be calculated

spPolys

Alternatively, provide solely a SpatialPolygons object

Details

The DT must be a data.table. If your data is a data.frame, you can convert it by reference using data.table::setDT.

The id, coords (and optional splitBy) arguments expect the names of respective columns in DT which correspond to the individual identifier, X and Y coordinates, and additional grouping columns.

The projection expects a PROJ.4 character string (such as those available on spatialreference.org). group_polys expects planar coordinates (not unprojected latitude, longitude).

The hrType must be either one of "kernel" or "mcp". The hrParams must be a named list of arguments matching those of adehabitatHR::kernelUD or adehabitatHR::mcp.

The splitBy argument offers further control over grouping. If within your DT, you have multiple populations, subgroups or other distinct parts, you can provide the name of the column which identifies them to splitBy. The grouping performed by group_polys will only consider rows within each splitBy subgroup.

Value

When area is FALSE, group_polys returns the input DT appended with a group column. As with the other grouping functions, the actual value of group is arbitrary and represents the identity of a given group where 1 or more individuals are assigned to a group. If the data was reordered, the group may change, but the contents of each group would not. When area is TRUE, group_polys returns a proportional area overlap data.table. In this case, ID refers to the focal individual of which the total area is compared against the overlapping area of ID2.

If area is FALSE, a message is returned when a column named group already exists in the input DT, because it will be overwritten.

See Also

build_polys group_times

Other Spatial grouping: group_lines, group_pts

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# Load data.table
library(data.table)

# Read example data
DT <- fread(system.file("extdata", "DT.csv", package = "spatsoc"))

# Cast the character column to POSIXct
DT[, datetime := as.POSIXct(datetime, tz = 'UTC')]

# Proj4 string for example data
utm <- '+proj=utm +zone=36 +south +ellps=WGS84 +datum=WGS84 +units=m +no_defs'

group_polys(DT, area = FALSE, 'mcp', list(percent = 95),
            projection = utm,
            id = 'ID', coords = c('X', 'Y'))

areaDT <- group_polys(DT, area = TRUE, 'mcp', list(percent = 95),
                      projection = utm,
                      id = 'ID', coords = c('X', 'Y'))

ropensci/spatsoc documentation built on Oct. 27, 2018, 12:15 a.m.