[R-sig-Geo] polygon identifiers and nb classes

Roger Bivand Roger.Bivand at nhh.no
Fri Apr 14 20:50:46 CEST 2006


On Thu, 13 Apr 2006, Larry Layne wrote:

> > Right. Please look at write.sn2gwt()...
> 

Here is a first cut, which seems to emit a suitable file. If you can try 
it and/or send back an Arc command line say for COLUMBUS.SHP CRIME and 
NEIGNO as index in GeoDa, I would be grateful:

write.sn2Arc <- function(sn, file, field=NULL) {
	if(!inherits(sn, "spatial.neighbour")) 
	    stop("not a spatial.neighbour object")
	if (is.null(field)) stop("field must be given")
	n <- attr(sn, "n")
	if (n < 1) stop("non-positive number of entities")
	nms <- as.character(attr(sn, "region.id"))
	sn[,1] <- nms[sn[,1]]
	sn[,2] <- nms[sn[,2]]
	con <- file(file, open="w")
	writeLines(field, con)
	write.table(as.data.frame(sn), file=con, append=TRUE,
		row.names=FALSE, col.names=FALSE, quote=FALSE)
	close(con)
}

I think it may fall over if the region.id values include white space or 
are non-unique.

sn is a spatial neighbours object as returned by listw2sn(), so in your 
case it would be:

write.sn2Arc(listw2sn(nb2listw(my_nb, style="B")), filename, fieldname)

Roger

> It is also probably a good idea to start using spdep 0.3-22 to take 
> advantage of some of the new functions, which I have done.
> 
> Larry
> 
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no




More information about the R-sig-Geo mailing list