Re: [R] spgrass6 and aggregation (bis)

From: Roger Bivand <Roger.Bivand_at_nhh.no>
Date: Wed, 06 Jun 2007 12:30:10 +0200 (CEST)


On Wed, 6 Jun 2007 jessica.gervais_at_tudor.lu wrote:

>
> Dear all,
>
> I have some additionale question concerning the spgrass6 package.
>
> * When you set a region in GRASS, does the readGRASS6 function in R only
> load data contained in the zoomed region or the whole map ?

readRAST6() uses the current region, readVECT6() should not clip to the current region.

>
> * When you have a MASK map in grass, does the readGRASS6 function in R only
> load data contained inside the MASK area ?
>

MASK is respected (in spearfish):

r.mask input=rushmore
d.rast elevation.dem
R
library(spgrass6)
el <- readRAST6("elevation.dem")
summary(el)
image(el)

>
> Could this be the problem ?

No, the problem was that you did not pay attention to the class of the data objects you were reading. You could have done:

my_SGDF <- readRAST6(c("landuse_mapname_in_grass",   "catchement_mapname_in_grass",
  "precipitation_mapname_in_grass"), cat=c(TRUE, TRUE, FALSE))

treating the whole as a single SpatialGridDataFrame, and the first two maps as factors (categorical).

Please remember that class(), summary(), image(), and other methods let you look at the data you have read - here I would certainly do:

summary(my_SGDF)
image(my_SGDF, "precipitation_mapname_in_grass")

You can then try:

my_DF <- as(my_SGDF, "data.frame")
aggregate(my_DF, by=list(my_DF$catchement_mapname_in_grass,   my_DF$landuse_mapname_in_grass), sum, na.rm=TRUE)

although I'm not sure whether this is what you need.

There are two mailing lists that are better suited to this question, R-sig-geo on the R side, and STATGRASS on the GRASS side, both with a fair number of experienced helpers.

>
> Thanks,
>
> Jessica
>
>
> ########################################################################3
>
> Dear all,
>
>
> I am exporting grass map into R thanks to the very useful spgrass6 package.
>
> library(spgrass6)
>
> # I have 3 map I am working with a MASK map of a specific area.
>
> # 1) a landuse map
> landuse<-readRAST6("landuse_mapname_in_grass")
>
> # 2) a catchment map which divide the area in several catchements
> catchment<-readRAST6("catchement_mapname_in_grass")
>
> # 3) a precipitation map
> precipitation<-readRAST6("precipitation_mapname_in_grass")
>
>
> # then I would like to sum the precipitation spatialy over each catchment
> and landuse. So, first I cbind all maps with cbind
>
> MAP<-cbind(landuse,catchment,precipitation)
>
> # then I use the aggregate function
> SUM<-aggregate(MAP[3],by=list(MAP[1],MAP[2]),sum,na.rm=TRUE)
> # here is the problem !!!
> Error in as.vector(x, mode) : invalid argument 'mode'
>
> ....
>
> I don't find any idea to solve this...
>
> Does anyone has a suggestion ??
>
> Thanks in advance
>
>
> Jess
>
> ______________________________________________
> R-help_at_stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
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

______________________________________________
R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Wed 06 Jun 2007 - 10:36:10 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 06 Jun 2007 - 12:31:45 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.