From 4fc06660c752cf1d431c2bb76f3327bbaf2e7231 Mon Sep 17 00:00:00 2001 From: Francesco Sabatini <francesco.sabatini@idiv.de> Date: Sat, 15 Feb 2020 14:29:16 +0100 Subject: [PATCH] Added trycatch to PredictorsExtract --- code/A98_PredictorsExtract.R | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/code/A98_PredictorsExtract.R b/code/A98_PredictorsExtract.R index 4221167..abdf843 100644 --- a/code/A98_PredictorsExtract.R +++ b/code/A98_PredictorsExtract.R @@ -49,9 +49,19 @@ PredExtr <- function(x.shp, myfunction=NA, output, if(length(toassign)>0){ nearest <- foreach(i=1:length(toassign), .packages=c('raster'), .combine=rbind) %dopar% { - nearest.tmp <- geosphere::dist2Line(toassign[i,], mypredictor) + nearest.tmp <- tryCatch(geosphere::dist2Line(mypoints[i,], mypredictor), + error = function(e){out <- mypredictor[1,] + out[1,] <- NA + return(out)} + ) + #nearest.tmp <- geosphere::dist2Line(toassign[i,], mypredictor) return(nearest.tmp) - } + } + + + + + out[which(is.na(out[,1])),] <- mypredictor@data[nearest[,"ID"],] } write.csv(out, file=output) -- GitLab