Dear Barry,

I think your grid should be the sgrd file on the disk.

I put an example here wher the input is a raster (raster package).

I first write a sgrd file and use this file in the geoprocessor.

You can replace the lee.filter function with

rsaga.wetness.index

Hope this helps.

JD



lee.filter <- function(pre_filter_dem, noise_abs=1, method=1, workdir=NULL){


   folder <- workdir
   if(is.null(workdir))
   {
     folder <- tempdir()
   }

   # environment variable
   require(RSAGA)
   myenv <- rsaga.env()
   print('importing...')

   # writing raster
   writeRaster(pre_filter_dem,
filename=paste(folder,"/",'pre_filter_dem',sep=''),
format='SAGA',overwrite=TRUE, NAflag=-9999)

   print('filtering...')

   # Filtering data
   rsaga.geoprocessor(lib='grid_filter', module = 3, param = list(
     INPUT=paste(folder,"/",'pre_filter_dem.sgrd',sep=''),
     RESULT=paste(folder,"/",'lee_filter_dem.sgrd',sep=''),
     NOISE_ABS=noise_abs,
     METHOD=method))
   print('writing...')




   return( raster(x=paste(folder,"/",'lee_filter_dem.sdat',sep='')))
}



2013/11/15 Rawlins, Barry G. <bgr@bgs.ac.uk>

> I have been trying to use RSAGA to compute SWI as per various instructions
> on implementing RSAGA.
>
> I have installed SAGA and I can successfully run the rsaga.env() call and
> the other R spatial packages.
>
> I imported a SAGA grid of elevations:
>
> summary(sgrd)
>      Length Class  Mode
> header     8  -none- list
> data   98400  -none- numeric
>
> and I can see elevation data if I summarise the data in the grid.
>
> When I try to run the call to the wetness index:
>
> >rsaga.wetness.index(in.dem=sgrd,out.wetness.index="SWI.grd")
>
> I get:
>
> Error in system(command, intern = intern, show.output.on.console =
> show.output.on.console,  :
>   'CreateProcess' failed to run
> 'C:\Users\bgr\DOCUME~1\R\WIN-LI~1\3.0\RSAGA\SAGA-GIS\saga_cmd.exe
> ta_hydrology "SAGA Wetness Index" -DEM "list(ncols = 410, nrows = 240,
> xllcorner = 277000, yllcorner = 322000, cellsize = 200, nodata_value =
> -9999, xllcenter = 277100, yllcenter = 322100).sgrd" -C "NA" -GN "NA" -CS
> "NA" -SB "NA" -DEM "NA" -C "NA" -GN "NA" -CS "NA" -SB "NA" -DEM "NA" -C
> "NA" -GN "NA" -CS "NA" -SB "NA" -DEM "NA" -C "NA" -GN "NA" -CS "NA" -SB
> "NA" -DEM "NA" -C "NA" -GN "NA" -CS "NA" -S
>
> Does anyone recognise this error and how I might solve it?
>
> My sessionInfo below:
>
> > sessionInfo()
> R version 3.0.1 (2013-05-16)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
>
> locale:
> [1] LC_COLLATE=English_United Kingdom.1252
> [2] LC_CTYPE=English_United Kingdom.1252
> [3] LC_MONETARY=English_United Kingdom.1252
> [4] LC_NUMERIC=C
> [5] LC_TIME=English_United Kingdom.1252
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods
> [7] base
>
> other attached packages:
> [1] maptools_0.8-27 rgdal_0.8-11    sp_1.0-14       RSAGA_0.93-6
> [5] plyr_1.8        shapefiles_0.7  foreign_0.8-55  gstat_1.0-17
> [9] ctv_0.7-8
>
> loaded via a namespace (and not attached):
> [1] grid_3.0.1       intervals_0.14.0 lattice_0.20-15
> [4] MASS_7.3-26      spacetime_1.0-9  tools_3.0.1
> [7] xts_0.9-7        zoo_1.7-10
>
> Thanks, Barry
>
> This message (and any attachments) is for the recipien...{{dropped:21}}

