Learn R Programming

spdep (version 0.4-2)

nb2lines: Use arc-type shapefiles for import and export of weights

Description

Use arc-type shapefiles for import and export of weights, storing spatial entity coordinates in the arcs, and the entity indices in the data frame.

Usage

nb2lines(nb, wts, coords)
listw2lines(listw, coords)
df2sn(df, i="i", i_ID="i_ID", j="j", wt="wt")

Arguments

nb
a neighbour object of class nb
wts
list of general weights corresponding to neighbours
coords
matrix of region point coordinates
listw
a listw object of spatial weights
df
a data frame read from a shapefile, derived from the output of nb2lines
i
character name of column in df with from entity index
i_ID
character name of column in df with from entity region ID
j
character name of column in df with to entity index
wt
character name of column in df with weights

Value

  • nb2lines and listw2lines return a list of two objects, ll is a list of lines, and df is a data frame with the from and to indices of the neighbour links and their weights. df2sn converts the data retrieved from reading the data from df back into a spatial.neighbour object.

Details

The maptools package function write.linelistShape is used to transport out the list of lines made by nb2lines or listw2lines, which is a simple wrapper function. The neighbour and weights objects may be retrieved by converting the specified columns of the attribute data of the Map object into a spatial.neighbour object, which is then converted into a weights list object.

See Also

sn2listw, write.linelistShape

Examples

Run this code
example(columbus)
coords <- coordinates(columbus)
res <- listw2lines(nb2listw(col.gal.nb), coords)
str(res$df)
fn <- paste(tempdir(), "nbshape", sep="/")
write.linelistShape(res$ll, res$df, file=fn)
inMap <- readShapeLines(fn)
summary(inMap)
diffnb(sn2listw(df2sn(as(inMap, "data.frame")))$neighbours, col.gal.nb)

Run the code above in your browser using DataLab