Using R as a geospatial scripting language is very convenient, particularly for the many (> 6 M) R users that are reluctant to learn python also… OTB is much faster than R as soon as you get moderately sized images, but usning R as the “glue” is very convenient.
I often run OTB from within R using a very similar approach, I run otbenv.profile before the actual otbcli command to ensure portability. The fact that otbcli* commands are named otbcli*.bat on windoze
makes you check the OS.
It is not strictly needed to write an R function such as aldo_tapia did (although it is very convenient if you plan to use it more than once), i.e.
#5 Calculate Reflectance using OTB (gdal_calc.py produces weird results)
print(“Calculating and saving Reflectance image…”)
comm1 <- file.path(otbpath,“otbcli_BandMathX -progress 0 -il”)
comm2 <- paste(file.path(imadir,fnameimaRad),
comm3 <- “-out result.tif -exp ‘(im1-im2) div (im3-im2)’”
comm <- paste(comm1, comm2, comm3)
cat(". /home/alobo/OTB-6.6.1-Linux64/otbenv.profile \n",comm,file=“test.scr”)
system(“sh test.scr”, intern=TRUE)
“-out result.tif -exp “(im1-im2) div (im3-im2)””,
but generalizing this into a otbcli_BandMathX.R function would be better.
It would be good if everyone working with R/OTB could share simple functions such as the one by aldo_tapia, we could make a collaborative ROTB package. The goal would be having an R function for running each otbcli command. We would need to agree on some common style.