Orfeo ToolBox and R ToolBox

Would it be possible at cmake-build/package level to generate these kind of code for R ?

If this can get to talk with allies already on R (grass, gdal etc…) that is cool.

I didn’t looked any detail in to R code. I put this thread to see if there is any interest or idea on R and OTB. This particular answer “looks” nice, so just moved this to forum.

Feel free to send your thoughts.

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),
file.path(imadir,fnameimaDref2),
file.path(imadir,fnameimaWref2))
comm3 <- “-out result.tif -exp ‘(im1-im2) div (im3-im2)’”
comm <- paste(comm1, comm2, comm3)
print(comm)
if(Sys.info()[1]!=“Windows”) {
cat(". /home/alobo/OTB-6.6.1-Linux64/otbenv.profile \n",comm,file=“test.scr”)
system(“sh test.scr”, intern=TRUE)
}
if(Sys.info()[1]==“Windows”){
cat("@ECHO OFF\n",
paste(comm1, comm2),
“-out result.tif -exp “(im1-im2) div (im3-im2)””,
file=“otbBandMath.bat”)
shell(“otbBandMath.bat”)
}

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.

Agus