[R-sig-Geo] gDistance on a LARGE Spatial Object?

Wouter Steenbeek WSteenbeek at nscr.nl
Fri Oct 26 20:46:01 CEST 2012


I am trying to use the "gDistance" from the "geos" package to calculate the Euclidean distance between a large number of points: to be exact, 28000 points.

I'm doing:
distance <- gDistance(points.sp) 

R doesn't run this on my 32-bit 3Gb RAM machine. The same function works on a subset of these points (say the first 400 points I call "points1_400.sp"). I think that R doesn't run on this is because gDistance keeps a matrix of 28000 * 28000 cells in RAM. With at one byte per cell, this amounts to 28000 * 28000 * 8 / (1024 bytes per Kb / 1024 Kb per Mb / 1024 Mb per Gb) = almost 6 Gb of RAM is needed.

1. Is my interpretation of the problem correct?

2. What would be the best way to tackle this problem? (chop up the points.sp into chunks, calculate distances per chunk, and then merge matrices together? I'm not sure how I can do that in R. Code examples of how to do is is appreciated)


More information about the R-sig-Geo mailing list