Skip to content

MEM : Spatial structures detection issues

3 messages · David Bauman, Roger Bivand

#
On Sun, 1 Dec 2013, David Bauman wrote:

            
library(sp)
GT <- GridTopology(c(12.5, 12.5), c(25, 25), c(8, 20))
SG <- SpatialGrid(GT)
bbox(SG) # if the orientation is rotated, reverse the third
# argument to GridTopology()
SPix <- as(SG, "SpatialPixels")
SPol <- as(SPix, "SpatialPolygons")
plot(SPol)
set.seed(1) # emulating your sample
ids <- sample.int(length(SPol), 24)
C_ids <- coordinates(SPol)[ids,] # C_ids are your sample centre points
o <- over(SpatialPoints(C_ids), SPol)
SSPol <- SPol[o]
plot(SSPol, col="yellow", add=TRUE)
text(coordinates(SSPol), label=row.names(SSPol), cex=0.6)
library(rgeos)
GD <- gDistance(SSPol, byid=TRUE) # matrix of distances

gives a matrix of distances between plots.

sp gets most of the way there, finishing with rgeos for distances between 
geometries.

Roger