Skip to content
Prev 2107 / 29559 Next

All zero link when reading a modified shapefile into R

On Thu, 31 May 2007, Danlin Yu wrote:

            
Could you try with just one deleted polygon first? Is it possible that 
ArcGIS does some cleaning at the same time, and moves the shapes apart? 
If that is the case, might increasing the snap= argument in poly2nb() 
help?

Incidentally, poly2nb() does take an object extending SpatialPolygons too, 
so you can also do:

x <- readShapePoly("x.shp")
plot(x)
x_nb <- poly2nb(x) # maybe increase snap=

avoiding using Map and polylist objects. Then

plot(x, border="grey")
plot(x_nb, coordinates(x), pch=".")

plots the neighbour graph on the tract boundaries.

In the last resort, do the deletion in R:

x <- readShapePoly("x.shp")
keep <- x$attribute is useful, logical condition
table(keep)
plot(x, col=c("red", "green")[(keep+1)])
x_subset <- x[keep,]
writePolyShape(x_subset, fn="x_subset")

or the equivalent readOGR() and writeOGR() functions in rgdal.

Hope this helps,

Roger