[STATSGRASS] Problems understanding how to use Rpy ( a Python
module) to accessGRASS rasters in R
Roger Bivand
Roger.Bivand at nhh.no
Thu Feb 17 12:57:16 EST 2005
On Thu, 17 Feb 2005, William Hudspeth wrote:
> Hello,
>
> I have previously used BASH shell scripts to successfully pass GRASS
> raster data sets to R, and then run basic statistics and plotting
> functions. Now, I am using Rpy 0.4.0 in an application that loads the
> GRASS GIS library. Prior to calling Rpy functions, I make sure to use
> Python to set up all of my environmental variables. I am then able to
> use code such as you see below to load my GRASS location metadata into
> Python objects:
>
> r_results=r.library('GRASS')
> G=r.gmeta()
> maps=r.get_mapsets()
> raster_layers=r.list_grass(type="cell")
>
> I understand that the variables on the left are Python objects - I can
> print out correct locational values to screen. However, if I want to
> summarize and plot the values in a certain raster map layer, I know that
> I probably need to create an R object first. It is not clear to me how I
> go about doing this given what I have read in the Rpy documentation. I
> have tried to move a raster into a Python object as such:
>
> elev=r.rast_get(G,"elevation")
>
> but, this fails with the error
>
> sh: line 1: rm command not found
>
Seeing that, I would back away quietly! I'm not sure that having the R
Python interface try to delete files is a good idea!
Please try out Rpy on very simple examples first to see how the
representations work. Say try two numeric vectors from rnorm(), and try a
t.test(). See if you can access the components in the htest object
returned. My guess would be, without ever having tried Rpy seriously, that
the arguments to rast.get() are not being passed correctly. Is there any
way to run R debug from Rpy (probably not)? Could you try to write your
own function to source into R from a file, that you know works without
Rpy, and that could avoid having to move anything but simple objects
across the R/Python interface - just single character strings and integer
or numeric vectors?
Please report back if you make any progress!
Best wishes,
Roger
> In short, it is unclear how I go about using the GRASS R libary
> functions through Rpy. I can run some of the library functions and
> create Python objects, but don't get how to create analogous objects in
> R and work with them. I am ultimately interested in working with raster
> layers and generating basic statistics and plots.
>
> Any sample code or guidance would help.
>
>
> Bill
>
> _______________________________________________
> statsgrass mailing list
> statsgrass at grass.itc.it
> http://grass.itc.it/mailman/listinfo/statsgrass
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: Roger.Bivand at nhh.no
More information about the grass-stats
mailing list