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

3 messages Options
Embed this post
Permalink
Rainer M Krug-6

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

Reply Threaded More More options
Print post
Permalink
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

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

Thanks,

Rainer

--
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
_______________________________________________
grass-stats mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-stats
Roger Bivand

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

Reply Threaded More More options
Print post
Permalink
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: [hidden email]

_______________________________________________
grass-stats mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-stats
Roger Bivand
Economic Geography Section
Department of Economics
Norwegian School of Economics and Business Administration
Helleveien 30
N-5045 Bergen, Norway
Rainer M Krug-6

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

Reply Threaded More More options
Print post
Permalink
On Sat, Aug 9, 2008 at 6:33 PM, Roger Bivand <[hidden email]> 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: [hidden email]
>
>



--
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
_______________________________________________
grass-stats mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-stats