[R-sig-Geo] How to speed up "extract" function in raster package?

Kamil Konowalik konno_kazuma at mailplus.pl
Mon Jan 18 12:02:43 CET 2016


Dear list members,
I'm trying to extract values for ca. 1000 points from 19 raster files. It is a very simple task - as an output I need a table where each point has additional 19 columns with values derived from those raster files (specifically I'm creating a SWD input file for Maxent). I used extract function but the whole task is running very slow - so far the whole process took 10 days and it is not finished yet. My computer is rather slow (Windows 7 32 bit, intel core duo 2.2 GHz, 3 GB RAM) but currently I need to use this machine. I was wondering whether there is a way to speed up the whole process by using a different command or maybe there is any trick that can speed it up?

Here's the code I'm using:

files <- list.files("C:/GIS/worldclim/biolcimatic_variables_ASCII",pattern='asc',full.names=TRUE)
Grids <- raster::stack(files)
background <- read.csv("C:/GIS/species_background/bg.csv",header=TRUE)
LonLatData2 <- background[,c(2,3)]
var_at_background <- raster::extract(Grids,LonLatData2) #I'm here since 10 days
outfile2 <- as.data.frame(cbind("species",LonLatData2,var_at_background))
colnames(outfile2) <- c("species","longitude","latitude",colnames(var_at_background))
write.csv(outfile2, file="variables_background.csv", append = FALSE, sep = ",", eol = "\n", na = "NA", dec = ".", col.names = TRUE, row.names = FALSE)

I started to use R relatively recently so excuse me if there is something that I missed here but I was searching for an answer without any success.
Best regards,
Kamil 

Wrocław University of Environmental and Life Sciences, Poland



More information about the R-sig-Geo mailing list