Skip to content
Prev 6433 / 29559 Next

adding ids and df to hexagonal polys ?

On Wed, 9 Sep 2009, Horacio Samaniego wrote:

            
library(maptools)
xx <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1],
  IDvar="FIPSNO", proj4string=CRS("+proj=longlat +ellps=clrk66"))
hpts <- spsample(xx, type="hexagonal", n=100)
hpoly <- HexPoints2SpatialPolygons(hpts)
o <- overlay(xx, hpts)
row.names(o) <- row.names(hpoly)
hpoly1 <- SpatialPolygonsDataFrame(hpoly, data=o)
summary(hpoly1)
spplot(hpoly1, "BIR74")

After making sure that the IDs agree, just use the constructor for
SpatialPolygonsDataFrame objects.

Hope this helps,

Roger