diff --git a/code/A98_PredictorsExtract.R b/code/A98_PredictorsExtract.R index 7b8aad7b91c56400a747021728484947191c5b65..4221167ddbfe4eae2dff0cafe5c1cc3ab3010692 100644 --- a/code/A98_PredictorsExtract.R +++ b/code/A98_PredictorsExtract.R @@ -10,6 +10,7 @@ PredExtr <- function(x.shp, myfunction=NA, output, require(rgdal) print(paste("Loading", typp, "data :", toextract)) + print(paste("output will be:", output)) if(typp=="raster"){ mypredictor <- raster(toextract)} else mypredictor <- readOGR(toextract) header.shp <-readOGR(x.shp) @@ -45,13 +46,14 @@ PredExtr <- function(x.shp, myfunction=NA, output, out <- sp::over(x=header.shp, y=mypredictor) toassign <- header.shp[which(is.na(out[,1])),] print(paste(length(toassign), "plots not matched directely - seek for NN")) - + if(length(toassign)>0){ nearest <- foreach(i=1:length(toassign), .packages=c('raster'), .combine=rbind) %dopar% { 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) } stopCluster(cl) diff --git a/code/submit-A98.sh b/code/submit-A98.sh index 28b7664cf47ef69548bbb94ee351c22b31560bd3..25e5c6dbc776f3ff101afb5c86bc4cd872c3eb50 100644 --- a/code/submit-A98.sh +++ b/code/submit-A98.sh @@ -3,7 +3,7 @@ #$ -S /bin/bash #$ -N PredictorExtract -#$ -o /work/$USER/$JOB_NAME-$JOB_ID.log +#$ -o /work/$USER/$JOB_NAME-$JOB_ID-$TASK_ID.log #$ -j y #$ -l h_rt=00:30:00:00 @@ -21,7 +21,7 @@ module load R filename="$1" shift -output=/work/$USER/output_pred/$(basename $filename .shp).csv +output=/data/splot/_data_splot3/output_pred/$(basename $filename .shp)-$SGE_TASK_ID.csv Rscript \ cli_A98.r \