You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#' Build Polygons (deprecated version of function with retired spatial packages)
2
+
#'
3
+
#' @inheritParams build_polys
4
+
#' @export
5
+
#'
6
+
#' @family Build functions
7
+
#' @seealso \code{\link{group_polys}}
8
+
build_polys_sp<-function(DT=NULL,
9
+
projection=NULL,
10
+
hrType=NULL,
11
+
hrParams=NULL,
12
+
id=NULL,
13
+
coords=NULL,
14
+
splitBy=NULL,
15
+
spPts=NULL) {
16
+
.Deprecated(msg='build_polys has been updated to use modern spatial R packages, removing dependencies on rgdal, rgeos, maptools in favor of sf. This version will be preserved until September 2023 for testing and user transition.')
17
+
18
+
# due to NSE notes in R CMD check
19
+
.<-NULL
20
+
21
+
if (is.null(DT) && is.null(spPts)) {
22
+
stop('input DT or spPts required')
23
+
}
24
+
25
+
if (!is.null(DT) &&!is.null(spPts)) {
26
+
stop('cannot provide both DT and spPts')
27
+
}
28
+
29
+
if (!is.null(DT) && is.null(spPts)) {
30
+
if (is.null(coords)) {
31
+
stop('coords must be provided')
32
+
}
33
+
34
+
if (is.null(id)) {
35
+
stop('id must be provided')
36
+
}
37
+
38
+
if (is.null(projection)) {
39
+
stop('projection must be provided')
40
+
}
41
+
42
+
if (length(coords) !=2) {
43
+
stop('coords requires a vector of column names for coordinates X and Y')
44
+
}
45
+
46
+
if (is.null(splitBy)) {
47
+
splitBy<-id
48
+
} else {
49
+
splitBy<- c(id, splitBy)
50
+
}
51
+
52
+
if (any(!(c(splitBy, coords) %in% colnames(DT)))) {
53
+
stop(paste0(
54
+
as.character(paste(setdiff(
55
+
c(id, coords), colnames(DT)
56
+
),
57
+
collapse=', ')),
58
+
' field(s) provided are not present in input DT'
59
+
))
60
+
}
61
+
62
+
if (any(!(DT[, vapply(.SD, is.numeric, TRUE),
63
+
.SDcols=coords]))) {
64
+
stop('coords must be numeric')
65
+
}
66
+
67
+
if (any(!(DT[, lapply(
68
+
.SD,
69
+
FUN=function(x) {
70
+
is.numeric(x) | is.character(x) | is.integer(x)
71
+
}
72
+
), .SDcols=splitBy]))) {
73
+
stop(
74
+
strwrap(
75
+
prefix="",
76
+
initial="",
77
+
x='id (and splitBy when provided)
78
+
must be character, numeric or integer type'
79
+
)
80
+
)
81
+
}
82
+
83
+
}
84
+
85
+
86
+
if (is.null(hrType)) {
87
+
stop('hrType must be provided')
88
+
}
89
+
90
+
if (is.null(hrParams)) {
91
+
message('hrParams is not provided, using defaults')
92
+
}
93
+
94
+
if (is.null(spPts)) {
95
+
spPts<-sp::SpatialPointsDataFrame(
96
+
DT[, .SD, .SDcols= eval.parent(coords, n=1)],
97
+
proj4string=sp::CRS(projection),
98
+
data=DT[, .(ID= do.call(paste,
99
+
c(.SD, sep='-'))),
100
+
.SDcols=splitBy])
101
+
}
102
+
103
+
hrParams$xy<-spPts
104
+
105
+
if (hrType=='mcp') {
106
+
functionParams<- formals(adehabitatHR::mcp)
107
+
if (all(names(hrParams) %in% names(functionParams))) {
108
+
if (!('unout'%in% names(hrParams))) {
109
+
hrParams$unout<-'m2'
110
+
}
111
+
return(do.call(adehabitatHR::mcp, hrParams))
112
+
} else {
113
+
stop(
114
+
strwrap(
115
+
prefix="",
116
+
initial="",
117
+
x='hrParams provided do not match function parameters,
0 commit comments