Last active
September 9, 2016 10:07
-
-
Save rCarto/c776c9417662b2d2ebed3a45e5ed781d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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