[GRASS-stats] Specify attribute column in SpatialPolygonsDataFrame when using overlay(grd, polyg)

Rainer M Krug r.m.krug at gmail.com
Sun Aug 10 10:15:05 EDT 2008


On Sat, Aug 9, 2008 at 6:33 PM, Roger Bivand <Roger.Bivand at nhh.no> wrote:
> 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

Thanks a lot Roger - no I understand how it works.

Rainer



> 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: Roger.Bivand at nhh.no
>
>



-- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Faculty of Science
Natural Sciences Building
Private Bag X1
University of Stellenbosch
Matieland 7602
South Africa


More information about the grass-stats mailing list