Hi Marta,

for your loop:
1) maybe you can first make your calculations and afterwards plot the result.
It might be faster this way.

2) maybe you can use the parallel for each loop in order to use the whole performance of your cpu

3) loops in R are really slow in general.. you could also think about some fancy stuff like some R compiler or Rcpp package

4) in order to analyze your memory consumption, you should have a view on your system resources (depending on your OS: task manager (win) or htop (linux))

Best regards,
Marcel


On 06.03.2017 12:51, marta azores wrote:
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@coords
[1,],effortSP_tormenta@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@coords
[i,],effortSP_tormenta@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]]

_______________________________________________
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

_______________________________________________
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to