[R-sig-Geo] loop memory problem
marta azores
martazores at gmail.com
Mon Mar 6 12:51:45 CET 2017
Hi all the members,
I have an script with a loop. It's working properly with a few points.
However, when I tried to run all my database 90.000 points, the loop
stopped each 3.000 points. And it takes 8hours for run 3.000 points.
My computer has 32GB of RAM, intel corei7 6700HQ CPU @ 2.60GHz .
Do you think it can be a memory problem? Is there anyway to make it faster??
Thanks you in advance,
Marta
####files
https://drive.google.com/open?id=0BwqSBe1Yq-FBUWVBOUdvaThEU1k
##############the script
library(sp)
library(gdistance)
library(rgeos)
### define data folder
path_data<-"C:/Users/Q11/"
#debug test# tormenta1
tor<- read.table(paste0(path_data,"tormenta1.csv"), header=TRUE, sep=",",
na.strings="NA", dec=".", strip.white=TRUE)
#transition layer
costa6Azo<- raster(paste0(path_data,"costa6Azo_projected.tif"))#wgs84
transitioncosta6Azo <- transition(costa6Azo, min, directions=16)#porque
min????
trCostS16 <- gdistance::geoCorrection(transitioncosta6Azo, type="c")
#
effortSP_tormentapos_1_1<-as.data.frame(cbind(tor$Lat1,tor$Long1,tor$transect))
str(effortSP_tormentapos_1_1)
sp::coordinates(effortSP_tormentapos_1_1) <- ~V2+V1
sp::proj4string(effortSP_tormentapos_1_1) <-CRS("+proj=longlat +datum=WGS84
+no_defs")
effortSP_tormenta <-sp::spTransform(effortSP_tormentapos_1_1,
CRS("+proj=utm +zone=26 +ellps=intl +towgs84=-104,167,-38,0,0,0,0 +units=m
+no_defs"))
#effortSP_tormenta#to keep the same names
plot(effortSP_tormentapos_1_1,axes=TRUE,add=TRUE)
# calculating the first segment of the whole sailing path# 10 total points
tormenta<- gdistance::shortestPath(trCostS16, effortSP_tormenta at coords
[1,],effortSP_tormenta at coords[2,], output="SpatialLines")
gLength(tormenta)
lines(tormenta,col=5)
### here we start with the for-loop :
for (i in (seq(2,length(effortSP_tormenta)-1))) { {
print(tormenta)
nextSegment<- gdistance::shortestPath(trCostS16, effortSP_tormenta at coords
[i,],effortSP_tormenta at coords[i+1,], output="SpatialLines")
# simple addition combines the single spatialline segements
tormenta <- nextSegment + tormenta
# we plot each new segement
lines(nextSegment)
gLength(nextSegment)
}}
####################################
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list