build_polys: Build Polygons

Description Usage Arguments Details Value See Also Examples

View source: R/build_polys.R

Description

build_polys creates a SpatialPolygons object from a data.table. The function accepts a data.table with relocation data, individual identifiers, a projection, hrType and hrParams. The relocation data is transformed into SpatialPolygons for each individual and optionally, each splitBy. Relocation data should be in two columns representing the X and Y coordinates.

Usage

1
2
3
build_polys(DT = NULL, projection = NULL, hrType = NULL,
  hrParams = NULL, id = NULL, coords = NULL, splitBy = NULL,
  spPts = NULL)

Arguments

DT

input data.table

projection

PROJ.4 character string

hrType

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

hrParams

a named list of parameters for adehabitatHR functions

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

spPts

alternatively, provide solely a SpatialPointsDataFrame with one column representing the ID of each point.

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). build_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 and adehabitatHR::getverticeshr or adehabitatHR::mcp.

The splitBy argument offers further control building SpatialPolygons. If in your DT, you have multiple temporal groups (e.g.: years) for example, you can provide the name of the column which identifies them and build SpatialPolygons for each individual in each year.

group_polys uses build_polys for grouping overlapping polygons created from relocations.

Value

build_polys returns a SpatialPolygons object with a polyon for each individual (and optionally splitBy combination).

An error is returned when hrParams do not match the arguments of the hrType adehabitatHR function.

See Also

group_polys

Other Build functions: build_lines

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 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'

# Build polygons for each individual using kernelUD and getverticeshr
build_polys(DT, projection = utm, hrType = 'kernel',
            hrParams = list(grid = 60, percent = 95),
            id = 'ID', coords = c('X', 'Y'))

# Build polygons for each individual by year
DT[, yr := year(datetime)]
build_polys(DT, projection = utm, hrType = 'mcp', hrParams = list(percent = 95),
            id = 'ID', coords = c('X', 'Y'), splitBy = 'yr')

# Build polygons from SpatialPointsDataFrame
library(sp)
pts <- SpatialPointsDataFrame(coords = DT[, .(X, Y)],
                              proj4string = CRS(utm),
                              data = DT[, .(ID)]
)

build_polys(spPts = pts, hrType = 'mcp', hrParams = list(percent = 95))

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