On Sat, 9 Aug 2008, Rainer M Krug wrote:

Hi


I have a SpatialGridDataFrame-class (grd) and a
SpatialPolygonsDataFrame (polyg) with more then one attribute columns,
i.e.

names(slot(polyg, "data"))

results in

"a", "b", "c", ... "z"

I want to use overlay to convert polyg into a grid, by assigning the
values of attribute column "d" to the grid.

Is it possible to specify the column name in the following overlay statement:

d <- overlay(grd, polyg)
grd[[1]] <- d

Not like that. Here with grd a SpatialGrid:

library(sp)
library(maptools)
polyg <- readShapeSpatial(system.file("shapes/sids.shp",
 package="maptools")[1],  IDvar="FIPSNO",
 proj4string=CRS("+proj=longlat +ellps=clrk66"))
grd <- Sobj_SpatialGrid(polyg)$SG
d <- overlay(grd, polyg)
# d contains the indices of the Polygons object into which each cell
# centre falls, or NA
summary(d)
names(polyg)
v <- polyg$SID74[d]
# use d to index the variable of interest
# if grd had been a SpatialGridDataFrame, just assign "$<-", or:
grdd <- SpatialGridDataFrame(grid=slot(grd, "grid"),
 data=data.frame(SID74=v), proj4string=CRS(proj4string(grd)))
summary(grdd)
image(grdd)
spplot(polyg, "SID74")

Roger


results in the values of the attribute column "d" in grd[[1]]?

Thanks,

Rainer



--
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: [EMAIL PROTECTED]

_______________________________________________
grass-stats mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/grass-stats

Reply via email to