[R-sig-Geo] All zero link when reading a modified shapefile into R

Danlin Yu yud at mail.montclair.edu
Fri Jun 1 05:45:34 CEST 2007


Dear Roger:

Thanks very much for your response. By increasing the snap value, the 
neighbor list was successfully created, which leads me to believe ArcGIS 
must have done something really wierd for when some polygons were 
deleted. However, after I loaded the original file and started to try 
your suggestions, I found that I was totally wrong - previously I 
thought I used the orginal shapefile to create the neighbor list, but I 
actually used a built and cleaned one - which was created from the 
orginal file. While in the meantime, I found that the original tract 
shapefile does not contain any topological information in it, that's why 
neither R nor GeoDa can create a useful neighbor list.

Totally my bad. But three lessons learned nonetheless:

1. with increased snap value in poly2nb, a useful link based on 
contiguity can be built from a spaghetti shapefile, but caution needs to 
be taken;
2. never create too many shapefiles at the same time with similar names
3. by converting a non-topology shapefile to a feature class into a 
personal Geodatabase and convert it back to shapefile, you can 
successfully build a shapefile with topology.

Thanks to Roger and apology to the list for my carelessness.

Best,
Danlin

Roger Bivand wrote:

>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
>>
>>    
>>
>
>  
>




More information about the R-sig-Geo mailing list