nb2lines                package:spdep                R Documentation

_U_s_e _a_r_c-_t_y_p_e _s_h_a_p_e_f_i_l_e_s _f_o_r _i_m_p_o_r_t _a_n_d _e_x_p_o_r_t _o_f _w_e_i_g_h_t_s

_D_e_s_c_r_i_p_t_i_o_n:

     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.

_U_s_a_g_e:

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

_A_r_g_u_m_e_n_t_s:

      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

_D_e_t_a_i_l_s:

     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.

_V_a_l_u_e:

     '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.

_N_o_t_e:

     Original idea due to Gidske Leknes Andersen, Department of
     Biology, University of Bergen, Norway

_A_u_t_h_o_r(_s):

     Roger Bivand Roger.Bivand@nhh.no

_S_e_e _A_l_s_o:

     'sn2listw', 'write.linelistShape'

_E_x_a_m_p_l_e_s:

     data(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 <- read.shape(fn)
     str(inMap$att.data)
     diffnb(sn2listw(df2sn(inMap$att.data))$neighbours, col.gal.nb)
     identical(coords, unique(t(sapply(Map2lines(inMap), function(x) x[1,]))))

