Description Usage Arguments Details Value Author(s) See Also Examples
The function uses the deldir
package to convert a matrix of
two-dimensional coordinates into a neighbours list of class nb
with a list of integer vectors containing neighbour region number
ids.
1 |
coords |
matrix of point coordinates with two columns |
row.names |
character vector of region ids to be added to the neighbours list as attribute |
If coordinates are duplicated, this function cannot be used.
If the coordinates are from a grid, then they need to be ordered
such that the first three are not collinear, so that the first triangle
can be constructed. This can be achieved by randomising the order of
the coordinates (possibly several times), and then re-ordering the order
of the data to match the new order of the neighbour list - if this fix
is used, remember to re-order the row.names argument as well as the
coordinates! Please also note that triangulation of grid points will
give arbitrary diagonal neighbours, which may not be a sensible outcome,
and dnearneigh()
may serve better where tri2nb()
cannot
be used.
The function returns an object of class nb
with a list of integer vectors containing neighbour region number ids.
Roger Bivand Roger.Bivand@nhh.no
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | example(columbus)
coords <- coordinates(columbus)
ind <- sapply(slot(columbus, "polygons"), function(x) slot(x, "ID"))
col.tri.nb <- tri2nb(coords, row.names=ind)
W <- as(nb2listw(col.tri.nb, style="B"), "CsparseMatrix")
plot(columbus, border="grey")
plot(col.tri.nb, coords, add=TRUE)
title(main="Raw triangulation links")
x <- seq(0,1,0.1)
y <- seq(0,2,0.2)
xy <- expand.grid(x, y)
try(xy.nb <- tri2nb(xy))
seed <- 1234
xid <- sample(1:nrow(xy))
xy.nb <- tri2nb(xy[xid,])
plot(xy.nb, xy[xid,])
|
Loading required package: sp
Loading required package: Matrix
colmbs> require(maptools)
Loading required package: maptools
Checking rgeos availability: TRUE
colmbs> columbus <- readShapePoly(system.file("etc/shapes/columbus.shp",
colmbs+ package="spdep")[1])
colmbs> col.gal.nb <- read.gal(system.file("etc/weights/columbus.gal",
colmbs+ package="spdep")[1])
Warning message:
use rgdal::readOGR or sf::st_read
PLEASE NOTE: The components "delsgs" and "summary" of the
object returned by deldir() are now DATA FRAMES rather than
matrices (as they were prior to release 0.0-18).
See help("deldir").
PLEASE NOTE: The process that deldir() uses for determining
duplicated points has changed from that used in version
0.0-9 of this package (and previously). See help("deldir").
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.