runOTB: Execute the OTB command list via system call

Description Usage Arguments Details Examples

View source: R/parseOTB.R

Description

Wrapper function which paste the OTB command list into a system call compatible string and execute this command.

Usage

1
runOTB(otbCmdList = NULL, gili = NULL, retRaster = TRUE, quiet = TRUE)

Arguments

otbCmdList

the OTB algorithm parameter list

gili

optional gis linkage as done by 'linkOTB()'

retRaster

boolean if TRUE a raster stack is returned

quiet

boolean switch for suppressing messages default is TRUE

Details

#' Please NOTE: You must check the help to identify the correct input file argument codewort ($input_in or $input_il).

Examples

 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
## Not run: 
require(link2GI)
require(raster)
require(listviewer)
rgdal::set_thin_PROJ6_warnings(TRUE)

## link to OTB
otblink<-link2GI::linkOTB()

if (otblink$exist) {
 projRootDir<-tempdir()
 data('rgb', package = 'link2GI')  
 raster::plotRGB(rgb)
 r<-raster::writeRaster(rgb, 
                        filename=file.path(projRootDir,"test.tif"),
                        format="GTiff", 
                        overwrite=TRUE)

## for an image output example we use the Statistic Extraction, 
algoKeyword<- "LocalStatisticExtraction"

## extract the command list for the choosen algorithm 
cmd<-parseOTBFunction(algo = algoKeyword, gili = otblink)

## Please NOTE:
## You must check the help to identify the correct argument codewort ($input_in or $input_il)
listviewer::jsonedit(cmd$help)

## define the mandatory arguments all other will be default
cmd$input_in  <- file.path(tempdir(),"test.tif")
cmd$out <- file.path(tempdir(),"test_otb_stat.tif")
cmd$radius <- 7

## run algorithm
retStack<-runOTB(cmd,gili = otblink)

## plot raster
raster::plot(retStack)

## for a data output example we use the 

algoKeyword<- "ComputeImagesStatistics"

## extract the command list for the chosen algorithm 
cmd<-parseOTBFunction(algo = algoKeyword, gili = otblink)

## get help using the convenient listviewer
listviewer::jsonedit(cmd$help)

## define the mandatory arguments all other will be default
cmd$input_il  <- file.path(tempdir(),"test.tif")
cmd$ram <- 4096
cmd$out <- file.path(tempdir(),"test_otb_stat.xml")
cmd$progress <- 1

## run algorithm
ret <- runOTB(cmd,gili = otblink, quiet = F)

## as vector
print(ret)

## as xml
XML::xmlParse(cmd$out)
 
}

## End(Not run)

link2GI documentation built on Sept. 5, 2021, 5:34 p.m.