Skip to content
Snippets Groups Projects
Commit 4fc06660 authored by Francesco Sabatini's avatar Francesco Sabatini
Browse files

Added trycatch to PredictorsExtract

parent 1a81f1c7
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment