[R-sig-Geo] spdep::listw2lines - removing duplicated lines

Roger Bivand Roger.Bivand at nhh.no
Wed Apr 11 10:57:42 CEST 2012


On Wed, 11 Apr 2012, Mathieu Rajerison wrote:

> Hi,
>
>
> I'm using spdep to generate neighbors, than listw2lines to create a
> SpatialLinesDataFrame.
>
> Considering two neighbors N1 and N2, the line will be duplicated: one
> N1->N2 and one N2->N1

Only if the neighbours are symmetric, and in graph-based or k-nearest 
neighbours, this is not the case.

>
> Would you have any idea on how to select only one line from the two, for
> example the first?

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


> Actually, it would consist in removing duplicated lines with same geometry
> but different directions.
>
>
> Thanks in advance, any help would be greatly appreciated!
>
> Mathieu
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list