1

What libraries do I need to execute this GRASS tool (or any other) from an script in R ? Has anybody try to compare performance between using r.viewshed from QGIS and r.viewshed from R ?

  • 2
    Look at R statistics/rgrass7 – gene Feb 25 at 15:56
  • I would like to execute the tool r.viewshed like I do within QGIS. Just like "> function(parameter1, parameter2, ...)" – César Arquero Feb 26 at 15:51
1

Quite a few GIS articles cover this. I think Riggs paper in TGIS is likely the one you want.

https://onlinelibrary.wiley.com/doi/abs/10.1111/j.1467-9671.2007.01040.x

  • Sorry but, this is not what I'm asking about performance. I mean the execution time for r.viewshed in R or in QGIS. – César Arquero Feb 26 at 15:53
0

You must have a R and GRASS version installed. Check the compatibility among them. Then you can use:

library(rgrass7)

loc <- initGRASS('C://Program Files//GRASS GIS 7.4.0', # Path to your GRASS folder
                   gisDbase='D://grass', # Yor grass DB
                   location = 'MAGNA2', # Grass location
                   mapset ='PERMANENT', # Grass mapset
                   override = TRUE) # 

## Calculate new layer. A raster ER is created into GRASS DB, not into R environment
execGRASS("r.mapcalc", expression = 'ER=if(P_over_L>0.316,ptrast/sqrt(0.9+P_over_L^2),ptrast)', flags = 'overwrite')
execGRASS("r.watershed", elevation='dem', flow = 'flow', depression = 'depression', flags = 'help')

execGRASS('g.list', mapset = 'PERMANENT', type = 'raster', intern = TRUE)
execGRASS('g.list', mapset = 'PERMANENT', type = 'vector', intern = TRUE)

## List available layers. Use ´intern = TRUE´ for bring the list into R
layers <- execGRASS('g.list', mapset = 'PERMANENT', type = 'all', intern = TRUE)

## Bring GRASS layer into R
exampleVEC <- readVECT('basin_1101_11017010')

## Bring GRASS layer into R
exampleR <- readRAST('ER)

Hope you find it useful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.