[R-sig-Geo] RSAGA issues

Rainer Hurling rhurlin at gwdg.de
Sun Oct 28 18:57:12 CET 2012


On 26.10.2012 09:44 (UTC+2), Ludwig Hilger wrote:
> 
> Dear list,
> 
> I am comparatively new to RSAGA and have come across three problems I
> have not been able solve by searching on the internet. Your help would
> be very much appreciated. This is SAGA 2.0.8 and R 2.15.1.
> 
> 1. Is there a way to access the header of a *.sgrd without having to
> load the whole grid, i.e. not using read.sgrd()$header? I want to
> determine the cellsize of a *.sgrd from within r for informational
> purposes and I have 1 m grids with 62 km2.....

The .sgrd file _is_ the header file of a SAGA GIS grid file. The grids
data is in .sdat instead. You can read these very small header files
(.sgrd) with several functions, for example


hd <- readLines("filename.sgrd", n=-1)

# split strings in names and values parts
require(stringr)
hd <- unlist(str_split(hd, "\t= "))

# make a dataframe from the header data
header <- data.frame(Parameter=hd[seq(1,length(hd),2)],
                     Value=hd[seq(2,length(hd),2)])

# The contents of such header is like that
header
#         Parameter              Value
#1             NAME          DGM5_saga
#2      DESCRIPTION
#3             UNIT
#4  DATAFILE_OFFSET                  0
#5       DATAFORMAT              FLOAT
#6    BYTEORDER_BIG              FALSE
#7    POSITION_XMIN 3449220.0000000000
#8    POSITION_YMIN 5487020.0000000000
#9      CELLCOUNT_X               2907
#10     CELLCOUNT_Y               6538
#11        CELLSIZE      10.0000000000
#12        Z_FACTOR           1.000000
#13    NODATA_VALUE      -99999.000000
#14     TOPTOBOTTOM              FALSE


The other questions seem to be already answered on r-sig-geo and/or SAGA
GIS discussion forum (
http://sourceforge.net/p/saga-gis/discussion/790705/thread/77e3979c/ ).

Hope this helps,
Rainer


> -------------------------------------------------------------------------------
> 
> 
> 2. I have tried to call the Grid sum module in the following way:
>     rsaga.geoprocessor(
>     lib = “grid_calculus”,
>     module = 8,
>     param = list(
>     GRIDS = list(“t_elev_class.sgrd”, “t_asp_class.sgrd”),
>     RESULT = “t_codes”
>             )
>     )
> 
> I get the following error, i.e. arguments of the function seem to get
> mixed up:
> 
> “library path: C:Program Files (x86)SAGA-GIS_2.0.8/modules
> library name: grid_calculus
> module name : Grids Sum
> author : O. Conrad (c) 2010
> 
> Load grid: t_codes...
> 
> failed
> 
> error: Grid file could not be opened.
> 
> error: input file t_codes
> 
> error: empty input list GRIDS
> Usage: 8 -GRIDS -RESULT
> -GRIDS: Grids
> Grid list (input)
> -RESULT: Sum
> Grid (output)
> 
> error: executing module Grids Sum
> Warnmeldung:
> Ausführung von Kommando '"C:Program Files
> (x86)SAGA-GIS_2.0.8/saga_cmd.exe" grid_calculus 8 -GRIDS
> "t_elev_class.sgrd" -RESULT "t_asp_class.sgrd" -GRIDS "t_codes"' ergab
> Status 1”
> 
> I have also tried c() instead of list() for the GRID-argument, I have
> moeved GRID out of the param-list, etc. . In contrast,
> rsaga.grid.calculus() works fine. I seem to have the same problem with
> other modules as well, probably I do not provide the input grids in the
> right way?
> 
> -------------------------------------------------------------------------------
> 
> 
> 3.
> a) When I resample a grid, I have to provide USER_YMIN, USER_XMIN,
> USER_XMAX and USER_YMAX. Is there a way to automatically calculate these
> values from the input DEM header and the cellsize selected for
> resampling (as SAGA seems to do in the GUI)?
> b) If I want to use a target grid as a model for the new grid, where is
> this to be specified? rsaga.get.usage("grid_tools", 0) gives me only the
> options GRID_GRID and USER_GRID (which are output arguments according to
> get.usage). There are no arguments for the path to the target grid.
> 
> thank you,
> Ludwig



More information about the R-sig-Geo mailing list