On Wed, 5 Sep 2007, Philip A. Viton wrote: > > (Very new-user problem, sorry) Can anyone help me with generating an > nb file using only R/spdep tools, ie without using GeoDa as an > intermediate step? I have a shape file, say "myshape.shp" with its > associated (eg) dbf files. My idea is to read it with maptools, then > convert to polygons, neighbors, then finally weights. > > In R (2.5.1 under Winxp): > > library(spdep) > > map <-readshape("myshape") > # seems OK > > mappoly <-Map2poly(map,region.id="OBJECTID") > # also seems OK, though it takes a LONG time > > mapnb = poly2nb(mappoly,row.names = NULL, > snap=sqrt(.Machine$double.eps), queen=TRUE) > > # problem is, this hangs R (GUI says "Not responding")
This suggests that the coastline is very detailed. R is just working on all the coastal points, it will get there in the end. Nowadays you can use either: getinfo.shape("myshape.shp") # to check type of shapes mapSP <- readShapePoly("myshape.shp") mapnb <- poly2nb(mapSP) # other arguments are default values or library(rgdal) mapSP <- readOGR(dsn=".", layer="myshape") # sets the shape type itself # and reads *.prj but most likely myshape.shp is large and detailed, it isn't so much the number of polygons that impacts performance, rather the numbers of coordinates in the polygons being matched. If the coastlines are very detailed, all the islands will be being checked too, so just leave it to complete without watching (runs faster if nobody is looking!). Hope this helps, Roger > > (then, if I ever get this far, use nb2listw to generate the weights). > The shape file is a US-48-states file, so not, I would assume, too > big; but obviously something is going wrong. Can anyone suggest a better way? > > > Thanks! > > ------------------------ > Philip A. Viton > City Planning, Ohio State University > 275 West Woodruff Avenue, Columbus OH 43210 > [EMAIL PROTECTED] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo@stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > -- 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: [EMAIL PROTECTED] _______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo