[R] spdep::poly2nb problem
Roger Bivand
Roger.Bivand at nhh.no
Tue May 10 08:44:33 CEST 2011
This message should have had a more informative subject, and, given its
specialist character, been sent to R-sig-geo, as is recommended on the
Spatial Task View. From initial trials, the file you are using includes far
too much boundary detail, and appears to have been assembled from disparate
state/county maps (Florida is added late, not in sequence). With a malformed
input map intended for display only, you shouldn't be surprised that the
topology is wrong. I'll investigate whether there is a code issue, but the
real problem is the choice of a very inappropriate input map of an object
size of 64Mb for 56 objects, where you do not need all of the coastal
detail.
Roger
Philip A. Viton wrote:
>
> I downloaded a US states+territories shapefile from
> http://www.weather.gov/geodata/catalog/national/html/us-state.htm
> and unzipped it into my working directory.
> Then in R (version 12.2.0 for ms-win32):
>
> library(rgdal) # Version: 0.6-28
> library(spdep) # Version: 0.5-24 (loads sp: Version: 0.9-72)
>
> # read in the data
> states<-readOGR(".","s_01de10")
> summary(states)
>
> # now create a neighbors list
> states_nb<-poly2nb(states)
> # create a 0/1 matrix of the neighbors
> nb_mat<-nb2mat(states_nb,style="B",zero.policy=TRUE)
> # add names
> nms<-as.character(states$NAMES)
> # set the matrix names
> dimnames(nb_mat)<-list(nms,nms)
>
> # now see which states have no neighbors
> rowSums(nb_mat)
> # it turns out that Florida seems to have zero neighbors.
>
> I then repeated it with
> states_nb<-poly2nb(states,useC=FALSE)
>
> and this time -- the computation takes a lot longer, of course
> --- Florida has 2 neighbors (correctly: AL and GA).
>
>
> Can anyone tell me what's going wrong here?
>
>
> Thanks!
>
>
> ------------------------
> Philip A. Viton
> City Planning, Ohio State University
> 275 West Woodruff Avenue, Columbus OH 43210
> viton.1 at osu.edu
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
-----
Roger Bivand
Economic Geography Section
Department of Economics
Norwegian School of Economics and Business Administration
Helleveien 30
N-5045 Bergen, Norway
--
View this message in context: http://r.789695.n4.nabble.com/spdep-poly2nb-problem-tp3506042p3511103.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list