From 02e4967f401630176b379bf09d20d82d2a37802f Mon Sep 17 00:00:00 2001 From: Vincent van Hees Date: Thu, 1 Aug 2024 17:37:37 +0200 Subject: [PATCH 1/4] error when CRS is not specified in GIR file, fixes #26 --- R/build_whenwhatwhere.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/build_whenwhatwhere.R b/R/build_whenwhatwhere.R index b6c2fb3..d04276e 100644 --- a/R/build_whenwhatwhere.R +++ b/R/build_whenwhatwhere.R @@ -30,6 +30,10 @@ build_whenwhatwhere <- function(data = NULL, verbose = TRUE, whenwhat_field = NU Nlocations = length(loca) for (i in 1:Nlocations) { for (j in 1:2) { + if (is.na(st_crs(loca[[i]][[j]]))) { + stop(paste0("GIS file lacks coordinate reference system specification", + " as expected by hbGIS"), call. = FALSE) + } txt = paste0(names(loca[[i]])[j], " = loca[[i]][[j]]") eval(parse(text = txt)) } From 53fc95ee13fb57553212728602c8ee63d6c68296 Mon Sep 17 00:00:00 2001 From: Vincent van Hees Date: Thu, 1 Aug 2024 17:38:44 +0200 Subject: [PATCH 2/4] Error when location of the ID not successfullly identified --- R/hbGIS.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/R/hbGIS.R b/R/hbGIS.R index 6e32bf2..ab7fec7 100644 --- a/R/hbGIS.R +++ b/R/hbGIS.R @@ -176,7 +176,10 @@ hbGIS <- function(gisdir = "", if (!is.null(loca[[i]][3][[1]])) { # only consider locations with data for (j in 1:2) { loc_id = grep(pattern = "ID|identifier|_id", x = colnames(loca[[i]][j][[1]])) - if (length(loc_id) > 0) { + if (length(loc_id) == 0) { + stop(paste0("Unclear which column to use as location identifier in ", + loca[[i]][3][[1]], " we see ", paste0(colnames(loca[[i]][j][[1]]), collapse = " "))) + } else if (length(loc_id) > 0) { loca[[i]][j][[1]][[loc_id]] = as.character(loca[[i]][j][[1]][[loc_id]]) } } @@ -419,7 +422,6 @@ hbGIS <- function(gisdir = "", if (verbose) cat("\n<<< building whenwhatwhere...\n") if (length(palms) > 0 & length(whenwhat_field) & all(Nlocation_objects > 0) & length(participant_basis) > 0) { - whenwhatwhere <- build_whenwhatwhere(data = palms, whenwhat_field = whenwhat_field, loca = loca, From bf61043bd96832dd081a151e7d21c10ae93168ad Mon Sep 17 00:00:00 2001 From: Vincent van Hees Date: Thu, 1 Aug 2024 17:38:59 +0200 Subject: [PATCH 3/4] Update DESCRIPTION --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 82eb1a3..5810439 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,4 +18,4 @@ Suggests: testthat, covr, rmarkdown Depends: stats, utils, R (>= 3.5.0) Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 From 64102b787f99fc95b06e5ae91d97fcc0d01e923b Mon Sep 17 00:00:00 2001 From: Vincent van Hees Date: Thu, 1 Aug 2024 17:46:23 +0200 Subject: [PATCH 4/4] fixes #27 --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5810439..6992f53 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -11,7 +11,7 @@ Authors@R: person("Tom", "Stewart", role = "cph", email = "tom.stewart@aut.ac.nz", comment = "holds copyright over original palmsplusr code")) License: LGPL-3 | file LICENSE -Imports: dplyr, sf, readr, tidyr, stringr, palmsplusr, data.table, rlang, purrr, geosphere +Imports: dplyr, sf, readr, tidyr, stringr, palmsplusr, data.table, rlang, purrr, geosphere, lwgeom Remotes: vincentvanhees/palmsplusr LazyData: true Suggests: testthat, covr, rmarkdown