[R-sig-Geo] Running analysis on DEMs using GRASS (from R?)

Tomislav Hengl T.Hengl at uva.nl
Wed Mar 25 10:18:42 CET 2009


Dear list,

I am trying to test some DEM analysis functions in GRASS GIS (under MS Windows machines). This is my
first contact with GRASS scripting (I have successfully installed GRASS 6.4 for windows from
http://grass.itc.it/grass63/binary/mswindows/native/).

For example, with SAGA GIS, I can completely control the analysis from R and use SAGA as external
application to run the processing, e.g. to extract the drainage networks from a DEM:

> library(rgdal)
> library(RSAGA)

# obtain the data:
download.file("http://www.geomorphometry.org/data/DEM25m.zip",
destfile=paste(getwd(),"DEM25m.zip",sep="/"))
fname <- zip.file.extract(file="DEM25m.asc", zipname="DEM25m.zip")
file.copy(fname, "./DEM25m.asc", overwrite=TRUE)

# load to SAGA format:
> rsaga.esri.to.sgrd(in.grids="dem25m.asc", out.sgrds="dem25m.sgrd", in.path=getwd())
# Fill the spurious sinks:
> rsaga.geoprocessor(lib="ta_preprocessor", module=2, param=list(DEM="dem25m.sgrd",
RESULT="dem25m_f.sgrd", MINSLOPE=0.05))
# extract the channel network:
> rsaga.geoprocessor(lib="ta_channels", module=0, param=list(ELEVATION="dem25m_f.sgrd",
CHNLNTWRK="channel_ntwrk.sgrd", CHNLROUTE="channel_route.sgrd", SHAPES="channels.shp",
INIT_GRID="dem25m_f.sgrd", DIV_CELLS=3, MINLEN=40))
# read back to R:
> channels <- readOGR("channels.shp", "channels")
> spplot(channels["LENGTH"], col.regions=bpy.colors())


How could I run the same processing using GRASS? Can you control GRASS from R at all? (I would be a
bit disappointed with GRASS if I am not able to run the analysis from R).

Many thanks for your time and suggestions in advance!


Tom Hengl
http://home.medewerker.uva.nl/t.hengl/



More information about the R-sig-Geo mailing list