[R-sig-Geo] adding ids and df to hexagonal polys ?
Roger Bivand
Roger.Bivand at nhh.no
Thu Sep 10 09:22:51 CEST 2009
On Wed, 9 Sep 2009, Horacio Samaniego wrote:
> Hi,
>
> I am trying to understand the different data types in the sp package.
> However, I do not seem to get the way that spdf are built.
>
> For example, let say that I can build a hexagonal grid. That work just
> fine using
>
>> regio <- readShapePoly("regions.shp")
>> hpts <- spsample(regio,type="hexagonal",cells=30000)
>> hpoly = HexPoints2SpatialPolygons(hpts)
>
> I'm unclear about adding a df with IDs to this new SpetialPolygons class
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
>
> I guess that I'm not understanding how ids are assigned... any hint
> would be appreciated
>
> thanks
>
> _______________________________________________
> 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