Description Usage Arguments Details Value Note Author(s) See Also Examples
The functions provide an interface to GRASS commands run through system
, based on the values returned by the --interface description
flag using XML parsing. If required parameters are omitted, and have declared defaults, the defaults will be used.
1 2 3 4 5 6 7 8 9 10 11 | execGRASS(cmd, flags = NULL, ..., parameters = NULL, intern = NULL,
ignore.stderr = NULL, Sys_ignore.stdout=FALSE, Sys_wait=TRUE,
Sys_input=NULL, Sys_show.output.on.console=TRUE, Sys_minimized=FALSE,
Sys_invisible=TRUE, echoCmd=NULL, redirect=FALSE, legacyExec=NULL)
doGRASS(cmd, flags = NULL, ..., parameters = NULL, echoCmd=NULL,
legacyExec=NULL)
parseGRASS(cmd, legacyExec=NULL)
## S3 method for class 'GRASS_interface_desc'
print(x, ...)
getXMLencoding()
setXMLencoding(enc)
|
cmd |
GRASS command name |
flags |
character vector of GRASS command flags |
... |
for |
parameters |
list of GRASS command parameters, used if GRASS parameters are not given as R arguments directly; the two methods for passing GRASS parameters may not be mixed. The storage modes of values passed must match thos required in GRASS, so a single GRASS string must be a character vector of length 1, a single GRASS integer must be an integer vector of length 1 (may be an integer constant such as 10L), and a single GRASS float must be a numeric vector of length 1. For multiple values, use vectors of suitable length |
intern |
default NULL, in which case set internally from |
ignore.stderr |
default NULL, taking the value set by |
Sys_ignore.stdout, Sys_wait, Sys_input |
pass extra arguments to |
Sys_show.output.on.console, Sys_minimized, Sys_invisible |
pass extra arguments to |
echoCmd |
default NULL, taking the logical value set by |
redirect |
default |
legacyExec |
default NULL, taking the logical value set by |
x |
object to be printed |
enc |
character string to replace UTF-8 in header of XML data generated by GRASS module –interface-description output when the internationalised messages are not in UTF-8 (known to apply to French, which is in latin1) |
parseGRASS
checks to see whether the GRASS command has been parsed already and cached in this session; if not, it reads the interface description, parses it and caches it for future use. doGRASS
assembles a proposed GRASS command with flags and parameters as a string, wrapping parseGRASS
, and execGRASS
is a wrapper for doGRASS
, running the command through system
(from 0.7-4, the ...
argument is not used for passing extra arguments for system
). The command string is termed proposed, because not all of the particular needs of commands are provided by the interface description, and no check is made for the existence of input objects. Support for multiple parameter values added with help from Patrick Caldon. Support for defaults and for direct use of GRASS parameters instead of a parameter list suggested by Rainer Krug.
parseGRASS
returns a GRASS_interface_desc
object, doGRASS
returns a character string with a proposed GRASS command - the expanded command name is returned as an attribute, and execGRASS
returns what system
or system2
return, particularly depending on the intern
argument when the character strings output by GRASS modules are returned. If intern
is FALSE
, system
returns the module exit code, while system2
returns the module exit code with “resOut” and “resErr” attributes.
If any package command fails with a UTF-8 error from the XML package, try using setXMLencoding
to work around the problem that GRASS modules declare –interface-description output as UTF-8 without ensuring that it is (French is of 6.4.0 RC5 latin1).
Roger S. Bivand, e-mail: Roger.Bivand@nhh.no
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | if (nchar(Sys.getenv("GISRC")) > 0 &&
read.dcf(Sys.getenv("GISRC"))[1,"LOCATION_NAME"] == "nc_basic_spm_grass7") {
oechoCmd <- get.echoCmdOption()
set.echoCmdOption(TRUE)
print(parseGRASS("r.slope.aspect"))
doGRASS("r.slope.aspect", flags=c("overwrite"),
elevation="elevation.dem", slope="slope", aspect="aspect")
pars <- list(elevation="elevation", slope="slope", aspect="aspect")
doGRASS("r.slope.aspect", flags=c("overwrite"), parameters=pars)
print(parseGRASS("r.buffer"))
doGRASS("r.buffer", flags=c("overwrite"), input="schools", output="bmap",
distances=seq(1000,15000,1000))
pars <- list(input="schools", output="bmap", distances=seq(1000,15000,1000))
doGRASS("r.buffer", flags=c("overwrite"), parameters=pars)
set.echoCmdOption(oechoCmd)
try(res <- execGRASS("r.stats", input = "fire_blocksgg", # no such file
flags = c("C", "n")), silent=FALSE)
res <- execGRASS("r.stats", input = "fire_blocksgg", flags = c("C", "n"),
legacyExec=TRUE)
print(res)
if (res != 0) {
resERR <- execGRASS("r.stats", input = "fire_blocksgg",
flags = c("C", "n"), redirect=TRUE, legacyExec=TRUE)
print(resERR)
}
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.