Description Usage Arguments Details Value Note Author(s) See Also Examples
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.
1 2 3 | nb2lines(nb, wts, coords, proj4string=CRS(as.character(NA)))
listw2lines(listw, coords, proj4string=CRS(as.character(NA)))
df2sn(df, i="i", i_ID="i_ID", j="j", wt="wt")
|
nb |
a neighbour object of class |
wts |
list of general weights corresponding to neighbours |
coords |
matrix of region point coordinates |
proj4string |
Object of class CRS; holding a valid proj4 string |
listw |
a |
df |
a data frame read from a shapefile, derived from the output of |
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 |
The maptools package function writeSpatialShape
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 data slot of the SpatialLinesDataFrame object into a spatial.neighbour object, which is then converted into a weights list object.
nb2lines
and listw2lines
return a SpatialLinesDataFrame object; its data slot contains 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.
Original idea due to Gidske Leknes Andersen, Department of Biology, University of Bergen, Norway
Roger Bivand Roger.Bivand@nhh.no
1 2 3 4 5 6 7 8 9 10 | require(maptools)
example(columbus)
coords <- coordinates(columbus)
res <- listw2lines(nb2listw(col.gal.nb), coords)
summary(res)
fn <- paste(tempdir(), "nbshape", sep="/")
writeLinesShape(res, fn=fn)
inMap <- readShapeLines(fn)
summary(inMap)
diffnb(sn2listw(df2sn(as(inMap, "data.frame")))$neighbours, col.gal.nb)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.