[GRASS-stats] How to use r.what in rgrass7?

Markus Neteler neteler at osgeo.org
Thu Sep 10 08:25:45 PDT 2015


On Thu, Sep 10, 2015 at 1:19 PM, Rainer M Krug <Rainer at krugs.de> wrote:
> Markus Neteler <neteler at osgeo.org> writes:
>
>> Dear list,
>>
>> I try to query from R a raster map at given vector point positions
>> (both maps are in GRASS but it could well be that the points are in R
>> and the (huge) raster map in GRASS).
>>
>> So, simple North Carolina data set example:
>>
>> goutput <- execGRASS("r.what", map="elev_state_500m",
>> points="geodetic_pts", separator=",")
>
> Which data set do you mean? I don't have the maps in the
> nc_basic_spm_grass7 dataset?

I am using "nc_spm_08_grass7" (the full sample dataset).


> did you try to use intern=TRUE :

Great, intern=TRUE does the job (warnings still printed which is fine):

> goutput <- execGRASS("r.what", map="elev_state_500m",
+ points="geodetic_pts", separator=",", intern=TRUE)
Warning message:
In execGRASS("r.what", map = "elev_state_500m", points = "geodetic_pts",  :
  The command:
r.what map=elev_state_500m points=geodetic_pts separator=,
produced at least one warning during execution:
WARNING: 375528.09289275 323036.936425953 is outside your current region
WARNING: 366626.43789275 326709.311425953 is outside your current region
WARNING: 373413.90589275 321705.812425953 is outside your current region
WARNING: 121862.14889275 154448.453425953 is outside your current region
WARNING: 500126.65589275 327185.625425953 is outside your current region
WARNING: 497992.12589275 319289.780425953 is outside your current region
WARNING: 446393.81189275 320264.688425953 is outside your current region
WARNING: 446144.84289275 320081.218425953 is outside your current region
WARNING: 453882.74989275 319223.249425953 is outside your current region
>

Perhaps intern=TRUE should be the default when assigning to an object?

In any case, I now get

> str(goutput)
 chr [1:29939] "571530.81289275,265739.968425953,,187.8082200648" ...

which looks good and simplifies the rest:

> con <- textConnection(goutput)
> go1 <- read.csv(con, header=FALSE)
> str(go1)
'data.frame':    29939 obs. of  4 variables:
 $ V1: num  571531 571359 571976 572391 573011 ...
 $ V2: num  265740 265987 267049 267513 269615 ...
 $ V3: logi  NA NA NA NA NA NA ...
 $ V4: Factor w/ 22738 levels "-0.0048115728",..: 6859 6642 6749 6411
6356 6904 7506 7224 6908 7167 ...

Thanks for the help!

Markus

PS: I'll add that to the rgrass7 Wiki page.


More information about the grass-stats mailing list