| group_polys {spatsoc} | R Documentation |
Group Polygons
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 POLYGONs using build_polys() with adehabitatHR::mcp or
adehabitatHR::kernelUD. If the area argument is FALSE, group_polys
returns grouping calculated by spatial overlap. If the area argument is
TRUE, group_polys returns the area area and proportion of overlap.
Relocation data should be in two columns representing the X and Y
coordinates.
Usage
group_polys(
DT = NULL,
area = NULL,
hrType = NULL,
hrParams = NULL,
projection = NULL,
id = NULL,
coords = NULL,
splitBy = NULL,
sfPolys = NULL
)
Arguments
DT |
input data.table |
area |
boolean indicating either overlap group (when |
hrType |
type of HR estimation, either 'mcp' or 'kernel' |
hrParams |
a named list of parameters for |
projection |
numeric or character defining the coordinate reference
system to be passed to sf::st_crs. For example, either
|
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 |
sfPolys |
Alternatively, provide solely a simple features object with POLYGONs or MULTIPOLYGONs. If sfPolys are provided, id is required and splitBy cannot be used. |
Details
R-spatial evolution
Please note, spatsoc has followed updates from R spatial, GDAL and PROJ for handling projections, see more below and details at https://r-spatial.org/r/2020/03/17/wkt.html.
In addition, group_polys previously used rgeos::gIntersection,
rgeos::gIntersects and rgeos::gArea but has been
updated to use sf::st_intersects, sf::st_intersection and sf::st_area
according to the R-spatial evolution, see more
at https://r-spatial.org/r/2022/04/12/evolution.html.
Notes on arguments
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 argument expects a character string or numeric
defining the coordinate reference system to be passed to sf::st_crs.
For example, for UTM zone 36S (EPSG 32736), the projection
argument is projection = "EPSG:32736" or projection = 32736.
See https://spatialreference.org
for a list of EPSG codes.
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.
Along with changes to follow the R-spatial evolution, group_polys also
now returns area and proportion of overlap with units explicitly specified
through the units package.
See Also
Other Spatial grouping:
group_lines(),
group_pts()
Examples
# 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')]
# EPSG code for example data
utm <- 32736
group_polys(DT, area = FALSE, hrType = 'mcp',
hrParams = list(percent = 95), projection = utm,
id = 'ID', coords = c('X', 'Y'))
areaDT <- group_polys(DT, area = TRUE, hrType = 'mcp',
hrParams = list(percent = 95), projection = utm,
id = 'ID', coords = c('X', 'Y'))
print(areaDT)