Skip to content

Instantly share code, notes, and snippets.

@rCarto rCarto/trypar.R
Last active Sep 9, 2016

Embed
What would you like to do?
library(SpatialPosition)
load("../LargeSpatialPostition/com.RData")
# création d'une grille fine (5km)
grid <- CreateGrid(w = com, resolution = 5000)
# Les calculs de matrices de distances sont (beaucoup) plus rapides quand les
# objets spatiaux sont en WGS84 :
# Stocker la projection initiale
old.proj <- proj4string(com)
# passage en WGS84
com <- spTransform(com, "+init=epsg:4326")
grid <- spTransform(grid, "+init=epsg:4326")
knownpts = com
unknownpts = grid
varname = "POPULATION"
typefct = "exponential"
span = 20000
beta = 2
library(foreach)
library(doParallel)
#setup parallel backend to use 8 processors
cl <- makeCluster(3)
registerDoParallel(cl)
# sequence pour découper la grille
sequence <- unique(c(seq(1,nrow(grid), 500),nrow(grid)) )
# nombre d'itération
lseq <- length(sequence)-1
strt0 <- Sys.time()
ls <- foreach(i = 1:lseq, .packages = c('SpatialPosition')) %dopar% {
strt1 <- Sys.time()
print(strt1 - strt0)
mat <- CreateDistMatrix(knownpts = knownpts,
unknownpts = unknownpts[sequence[i]:sequence[i+1],],
bypassctrl = TRUE)
st <- stewart(knownpts = knownpts,
unknownpts = unknownpts[sequence[i]:sequence[i+1],],
matdist = mat,
typefct = "exponential",
span = 20000, beta = 3,
var = "POPULATION")
}
strt1 <- Sys.time()
print(strt1 - strt0)
stopCluster(cl)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.