Skip to content

(no subject)

4 messages · Steven J. Pierce, Roger Bivand

#
Hi folks,

After using spdep to construct a neighbor list from a SpatialPolygons
object, I plotted the neighbor list and noted that I needed one more link
that wasn't caught by the poly2nb command. I found the edit.nb() function
and can successfully use the interactive graphical interface to add the
link, but would like to know if there is an alternative method for adding a
link between two regions. What would I need to do to directly edit the
neighbor list object to include an additional link between regions 23 and
31?
this
package
+
proj4string=CRS(projection.details))
facilitate
snap=sqrt(.Machine$double.eps), queen=TRUE)
plotting
yaxs="i")
Identifying contiguity for deletion ...
No contiguity between chosen points
Add contiguity? (y/n) y
added contiguity between point 23 and 31 
Options: quit[q] refresh[r] continue[c] q
yaxs="i")
Steven J. Pierce
E-mail: pierces1 at msu.edu
#
On Fri, 2 Jun 2006, Steven J. Pierce wrote:

            
There is a drop.links() function but no add.links(). So yes, you could 
manipulate the list directly. If ij is a two element vector for the 
missing link:

nb[[ij[1]]] <- sort(unique(c(nb[[ij[1]]], ij[2])))
nb[[ij[2]]] <- sort(unique(c(nb[[ij[2]]], ij[1])))

should do it (untried). If there are more links, have a look at drop.links 
and see if you can adapt it.
I think:

CITY.polys <- as(CITY.ZCTA.data, "SpatialPolygons")

should be enough, in time poly2nb() will do that internally.
Could be:

coords.mat <- coordinates(CITY.ZCTA.data)

if the centroid.x|y values correspond to the polygon centroids.

Roger

  
    
9 days later
#
Hi folks,

I tried Roger's suggested method for adding extra links directly into a
neighbor list. To get it to work, I had to coerce the vector representing
the new link to be an integer vector instead of a numeric vector. Here's
what worked.

# Create an integer vector of the 2 regions (23 & 31) that need to be
connected.

ij <- as.integer(c(23,31))

# Update the neighbor list to add the symmetric link.

nb[[ij[1]]] <- sort(unique(c(nb[[ij[1]]], ij[2])))
nb[[ij[2]]] <- sort(unique(c(nb[[ij[2]]], ij[1])))

I just wanted to share that detail back to the list in case anyone else
wants to do this sort of data manipulation.

Steven J. Pierce
E-mail: pierces1 at msu.edu

-----Original Message-----
From: Roger Bivand [mailto:Roger.Bivand at nhh.no] 
Sent: Saturday, June 03, 2006 7:11 AM
To: Steven J. Pierce
Cc: r-sig-geo at stat.math.ethz.ch
Subject: Re: [R-sig-Geo] adding links to neighbour lists
On Fri, 2 Jun 2006, Steven J. Pierce wrote:

            
a
There is a drop.links() function but no add.links(). So yes, you could 
manipulate the list directly. If ij is a two element vector for the 
missing link:

nb[[ij[1]]] <- sort(unique(c(nb[[ij[1]]], ij[2])))
nb[[ij[2]]] <- sort(unique(c(nb[[ij[2]]], ij[1])))

should do it (untried). If there are more links, have a look at drop.links 
and see if you can adapt it.
object,
I think:

CITY.polys <- as(CITY.ZCTA.data, "SpatialPolygons")

should be enough, in time poly2nb() will do that internally.
CITY.ZCTA.data$centroid.y)
Could be:

coords.mat <- coordinates(CITY.ZCTA.data)

if the centroid.x|y values correspond to the polygon centroids.

Roger
graphics

  
    
#
On Mon, 12 Jun 2006, Steven J. Pierce wrote:

            
Yes, of course, thanks for your careful attention! 

Roger