diff --git a/code/A98_PredictorsExtract.R b/code/A98_PredictorsExtract.R
index 4221167ddbfe4eae2dff0cafe5c1cc3ab3010692..abdf8430796d6d423072c0ab7f4a763fc8fb4043 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)