[R-sig-Geo] All zero link when reading a modified shapefile into R
Roger Bivand
Roger.Bivand at nhh.no
Thu May 31 22:39:19 CEST 2007
On Thu, 31 May 2007, Danlin Yu wrote:
> Hi all-
>
> When I read a shapefile using read.shape into R, and used Map2poly ->
> poly2nb to create my neighbor list, the summary of the newly created
> neighbor list indicates that all the regions have zero link.
>
> The shapefile is a modified census tract shapefile of New Jersey: a few
> tracts that have no useful attributal information were deleted from the
> map (hence left some holes) in ArcGIS (Start Edit -> select ->
> delete).
>
> The original shapefile (with all the tracts) was read fine and create
> the correct neighbor list. But when using this modified one, I got all
> zero link. The same happened when I used GeoDa. Is this because of the
> holes created in the shapefile by deleting some polygons? If so, how can
> I make it work? If not, can anyone please direct me to the right
> solution?
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
>
> Many thanks.
>
> Best,
> Danlin
>
> ___________________________________________
> Danlin Yu, Ph.D.
> Assistant Professor
> Department of Earth & Environmental Studies
> Montclair State University
> Montclair, NJ, 07043
> Tel: 973-655-4313
> Fax: 973-655-4072
> email: yud at mail.montclair.edu
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at 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: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list