[R-sig-Geo] mapping introduction

Paulo van Breugel p.vanbreugel at gmail.com
Mon Nov 26 21:22:31 CET 2007


Dear Tom,

Thanks for the lecture notes, very interesting. I don't use the 
combination R - SAGA for the more advanced geostatistics you're 
describing, but rather to access more basic GIS modules such as the grid 
calculator and resample modules. But I don't see any reason why you 
couldn't use it for the other modules too.

I would recommend to have a look at the RSAGA package. It makes it 
easier to use SAGA. Moreover, it offers extended functionality, which, 
and I quote from the package help file, "include specific functions that 
are intended to be more user-friendly interfaces to the most frequently 
used SAGA modules. These higher-level interfaces support default values 
for the arguments and perform some error checking".

For those modules for which there is no direct interface (most), there 
is a low-level function (rsaga.geoprocessor) that can be used to run any 
SAGA modules and pass arguments. The interface is slightly different 
than when using the command line directly, see the RSAGA documentation 
for that. I just started using RSAGA so maybe you can also contact the 
author of the RSAGA package or use the SAGA user to user forum for more 
information.

Whether you use RSAGA or not, finding out the syntax of the different 
modules is probably the most complicated step because of missing 
documentation. For those interested, I normally use the following steps 
to figure out the arguments to a function (no R involved yet). I assume 
here you know which module you want to use; in this example I want to 
use the grid calculator to multiply grid 'inputA.sgrd' with grid 
'inputB.sgrd'

1) Before you run any command, you have to set the SAGA path, module 
path and data (working) directory, using the following commands (when 
you use RSAGA in R, this is easier):

 > cd c:\\program files\\saga_vc
 > set SAGA=.
 > SET SAGA_MLB=./modules
 > PATH=PATH;%SAGA%;%SAGA_MLB%

2) To find out which module library to call, you can select the module 
library that contains your module in the SAGA GUI (grid-calculus in this 
case) and than the description tab in the object properties window for 
the name of the dll (grid_calculus.dll).

3) Go back to the command line window and type in:

 > saga_cmd grid_calculus

4) You will be presented with a list of modules. Find the one you want 
to use. The grid calculator is module 1.

 > saga_cmd grid_calculus 1

5) you will be presented with the required syntax options. In my 
example, I'll need to give the names of the input and output layers and 
the equation:

 > saga_cmd grid_calculus 1 -INPUT inputA.sgrd;inputB.sgrd -RESULT 
output.sgrd -FORMUL a*b

 From within R, using the RSAGA package, you would use the following code:

rsaga.geoprocessor("grid_calculus", module=1, param=list(INPUT 
="inputA.sgrd;inputB.sgrd", RESULT=output.sgrd, FORMUL= 'a*b')

---
Below a small example of some real (but simple) code I used to resample 
grids to a certain extent and resolution. I wrote it as a function 
because I had to resample many grids to the same extent and resolution.

resample.SAGA <- function(sgrd.in, sgrd.out=sgrd, column=4294, 
rows=5415, east=12.210798, south=-13.451510, cell.size=0.008333, 
up.scale=0, down.scale=0){
options(digits=15)
rsaga.geoprocessor("grid_tools", module=0, param=list(INPUT=sgrd.in, 
GRID=sgrd.out, METHOD=1, KEEP_TYPE="", SYSTEM_SYSTEM_NX=column, 
SYSTEM_SYSTEM_NY=rows, SYSTEM_SYSTEM_X=east, SYSTEM_SYSTEM_Y=south, 
SYSTEM_SYSTEM_D=cell.size, SCALE_DOWN_METHOD=up.scale, 
SCALE_UP_METHOD=down.scale))}

---
In the following example I use the 'change grid values' module to change 
the grid values of a raster. The lookup table 'change.clim', with the 
mandatory three columns "Low Value", "High Value", and "Replace with", 
was generated in R:

library(foreign); library(RSAGA)
write.dbf(change.clim, "c:\\temp\\change_clim.dbf")
rsaga.geoprocessor("grid_tools", module=12, 
param=list(GRID_IN=c:\\temp\\clim.sgrd, GRID_OUT=c:\\temp\\climzon, 
METHOD=0, LOOKUP= c:\\temp\\chang_clim.dbf)
shell("del c:\\temp\\change_clim.dbf")

These are very simple examples, but hopefully they are useful nonetheless.

Paulo




Tomislav Hengl wrote:
> Dear Paulo,
>
> I completely agree about SAGA. I have been monitoring the evolution of SAGA (or better to say of
> Olaf Conrad) for quite some time. It is definitively one of the most extensive packages to analyze
> DEMs, but also to do various grid computing (including geostatistics; see also my lecture notes
> down-below).
>
> I would be very much interested to see your R code-examples where you call SAGA operations. Olaf
> told me that this functionality is still under construction (at least no instruction exists yet).
>
> all the best,
>
> Tom Hengl
> http://spatial-analyst.net 
>
> Hengl, T., 2007. A Practical Guide to Geostatistical Mapping of Environmental Variables. EUR 22904
> EN Scientific and Technical Research series, Office for Official Publications of the European
> Communities, Luxemburg, 143 pp.
> http://eusoils.jrc.it/ESDB_Archive/eusoils_docs/other/EUR22904en.pdf 
>
>
> -----Original Message-----
> From: r-sig-geo-bounces at stat.math.ethz.ch [mailto:r-sig-geo-bounces at stat.math.ethz.ch] On Behalf Of
> Paulo van Breugel
> Sent: maandag 26 november 2007 12:55
> To: tomfool at as220.org
> Cc: r-sig-geo at stat.math.ethz.ch
> Subject: Re: [R-sig-Geo] mapping introduction
>
> Hi Tom,
>
> In addition to the (very useful) earlier posts, I would like to point 
> out SAGA GIS. It is a very good GIS software (and freeware / open 
> source), especially for grid analyses. It has a command line version, 
> which together with the ability of R to  invoke system commands using 
> either 'Shell' or 'system' makes it fairly easy to do the typical GIS 
> work in SAGA, and carry out other analyses in R, all from within R. With 
> the recent release of the RSAGA package for R this has become 
> considerably easier.
>
> The documentation for SAGA is somewhat poor, but there are two very 
> useful user guides available. See the SAGA website 
> (http://www.saga-gis.uni-goettingen.de/html/index.php) for links. See 
> CRAN for the RSAGA package.
>
> Paulo
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
>   




Tomislav Hengl wrote:
> Dear Paulo,
>
> I completely agree about SAGA. I have been monitoring the evolution of SAGA (or better to say of
> Olaf Conrad) for quite some time. It is definitively one of the most extensive packages to analyze
> DEMs, but also to do various grid computing (including geostatistics; see also my lecture notes
> down-below).
>
> I would be very much interested to see your R code-examples where you call SAGA operations. Olaf
> told me that this functionality is still under construction (at least no instruction exists yet).
>
> all the best,
>
> Tom Hengl
> http://spatial-analyst.net 
>
> Hengl, T., 2007. A Practical Guide to Geostatistical Mapping of Environmental Variables. EUR 22904
> EN Scientific and Technical Research series, Office for Official Publications of the European
> Communities, Luxemburg, 143 pp.
> http://eusoils.jrc.it/ESDB_Archive/eusoils_docs/other/EUR22904en.pdf 
>
>
> -----Original Message-----
> From: r-sig-geo-bounces at stat.math.ethz.ch [mailto:r-sig-geo-bounces at stat.math.ethz.ch] On Behalf Of
> Paulo van Breugel
> Sent: maandag 26 november 2007 12:55
> To: tomfool at as220.org
> Cc: r-sig-geo at stat.math.ethz.ch
> Subject: Re: [R-sig-Geo] mapping introduction
>
> Hi Tom,
>
> In addition to the (very useful) earlier posts, I would like to point 
> out SAGA GIS. It is a very good GIS software (and freeware / open 
> source), especially for grid analyses. It has a command line version, 
> which together with the ability of R to  invoke system commands using 
> either 'Shell' or 'system' makes it fairly easy to do the typical GIS 
> work in SAGA, and carry out other analyses in R, all from within R. With 
> the recent release of the RSAGA package for R this has become 
> considerably easier.
>
> The documentation for SAGA is somewhat poor, but there are two very 
> useful user guides available. See the SAGA website 
> (http://www.saga-gis.uni-goettingen.de/html/index.php) for links. See 
> CRAN for the RSAGA package.
>
> Paulo
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
>




More information about the R-sig-Geo mailing list