1% Copyright 2003-4 by Roger S. Bivand
2\name{read.gwt2nb}
3\alias{read.gwt2nb}
4\alias{write.sn2gwt}
5\alias{read.dat2listw}
6\alias{write.sn2dat}
7%- Also NEED an '\alias' for EACH other topic documented here.
8\title{Read and write spatial neighbour files}
9\description{
10  The "gwt" functions read and write GeoDa GWT files (the example file baltk4.GWT was downloaded from the site given in the reference), and the "dat" functions read and write Matlab sparse matrix files as used by James LeSage's Spatial Econometrics Toolbox (the example file wmat.dat was downloaded from the site given in the reference). The body of the files after any headers should have three columns separated by white space, and the third column must be numeric in the locale of the reading platform (correct decimal separator).
11}
12\usage{
13read.gwt2nb(file, region.id=NULL)
14write.sn2gwt(sn, file, shpfile=NULL, ind=NULL, useInd=FALSE, legacy=FALSE)
15read.dat2listw(file)
16write.sn2dat(sn, file)
17}
18%- maybe also 'usage' for other objects documented here.
19\arguments{
20  \item{file}{name of file with weights data}
21  \item{region.id}{region IDs}
22  \item{sn}{a \code{spatial.neighbour} object}
23  \item{shpfile}{character string: if not given Shapefile name taken from GWT file for this dataset}
24  \item{ind}{character string: region id indicator field name}
25  \item{useInd}{default FALSE, if TRUE, write \code{region.id} attribute ID key tags to output file (use in OpenGeoDa will depend on the shapefile having the field named in the \code{ind} argument matching the exported tags)}
26  \item{legacy}{default FALSE; if TRUE, header has single field with number of observations only}
27}
28\details{
29Attempts to honour the region.id argument given when reading GWT files. If the region IDs given in \code{region.id=} do not match the origins or destinations in the GWT file, an error will be thrown reporting \code{Error: !anyNA(reg*dij) is not TRUE} where '*' may be \sQuote{o} for origins or \sQuote{d} for destinations.
30}
31\value{
32  \code{read.gwt2nb} returns a neighbour "nb" object with the generalised weights stored as a list element called "dlist" of the "GeoDa" attribute.
33}
34
35\references{Luc Anselin (2003) \emph{GeoDa 0.9 User's Guide}, pp. 80--81, Spatial Analysis Laboratory, Department of Agricultural and Consumer Economics, University of Illinois, Urbana-Champaign, \url{http://geodacenter.github.io/docs/geoda093.pdf}; also \url{http://spatial-econometrics.com/data/contents.html}}
36
37\author{Roger Bivand \email{Roger.Bivand@nhh.no}}
38
39\seealso{\code{\link{read.gal}}}
40
41\examples{
42data(baltimore, package="spData")
43STATION <- baltimore$STATION
44gwt1 <- read.gwt2nb(system.file("weights/baltk4.GWT", package="spData")[1],
45 STATION)
46cat(paste("Neighbours list symmetry;", is.symmetric.nb(gwt1, FALSE, TRUE),
47 "\n"))
48listw1 <- nb2listw(gwt1, style="B", glist=attr(gwt1, "GeoDa")$dist)
49tmpGWT <- tempfile()
50write.sn2gwt(listw2sn(listw1), tmpGWT)
51gwt2 <- read.gwt2nb(tmpGWT, STATION)
52cat(paste("Neighbours list symmetry;", is.symmetric.nb(gwt2, FALSE, TRUE),
53 "\n"))
54diffnb(gwt1, gwt2)
55data(oldcol)
56tmpMAT <- tempfile()
57COL.W <- nb2listw(COL.nb)
58write.sn2dat(listw2sn(COL.W), tmpMAT)
59listwmat1 <- read.dat2listw(tmpMAT)
60diffnb(listwmat1$neighbours, COL.nb, verbose=TRUE)
61listwmat2 <- read.dat2listw(system.file("etc/weights/wmat.dat",
62 package="spdep")[1])
63diffnb(listwmat1$neighbours, listwmat2$neighbours, verbose=TRUE)
64}
65\keyword{spatial}
66