Skip to content
Prev 14804 / 29559 Next

spdep::listw2lines - removing duplicated lines

On Wed, 11 Apr 2012, Mathieu Rajerison wrote:

            
Only if the neighbours are symmetric, and in graph-based or k-nearest 
neighbours, this is not the case.
If the neighbours are symmetric, it would be possible to do for example:

library(spdep)
set.seed(1)
xy <- cbind(x=runif(50), y=runif(50))
nb <- dnearneigh(xy, 0, 0.2)
nb
is.symmetric.nb(nb)
nb1 <- vector(mode="list", length=length(nb))
for (i in seq(along=nb)) nb1[[i]] <- nb[[i]][nb[[i]] <= i]
class(nb1) <- "nb"
attr(nb1, "region.id") <- attr(nb, "region.id")
nb1

It could probably also be done with gEquals() in rgeos also for asymmetric 
neighbours to remove duplications where they occur.

Roger