Skip to content

spsample: random points within a radius r from observed locations

3 messages · Gabriele Cozzi, Rolf Turner, Rafael Wüest

#
Dear list,

I have a set of relocation data (call it pnts).

What I want to do is to create, for each relocation of pnts, n alternative
relocations within a radius r.

My intuitive approach was to use of the spsample function in the sp
package.

buffer <- gBuffer(spgeom = pnts, width=r,  byid=T)
randompoints <- spsample(x=buffer, n=10, type="random", iter=10)

The problem here is that spsample creates 10 random points over all
Polygons in the buffer object and not for each Polygon within buffer.

Is there a function that returns random locations by passing a
SpatialPoints-class object to it and a radius r?

Any help is appreciated.

Gabriele
#
On 27/10/15 21:37, Gabriele Cozzi wrote:
I don't know what is meant by "relocation" data, but I am pretty sure 
that you could easily accomplish your goal using the spatstat package. 
You would have to adjust your terminology and thought patterns somewhat, 
however.

cheers,

Rolf Turner
#
Hi Gabriele

Don't know of such a function, but the following should return 10 random 
locations per polygon in 'buffer'

randompoints.list <- sapply(buffer at polygons, spsample, n = 10, type = 
'random')
randompoints <- do.call(rbind, randompoints.list)

May be a start...

Cheers,
Rafael
On 27.10.15 09:37, Gabriele Cozzi wrote: