r-spatial / link2GI

Simplify the linking of GIS/RS and CLI tools
https://r-spatial.github.io/link2GI
GNU General Public License v3.0
25 stars 7 forks source link

link2GI::runOTB error #59

Closed Runge123 closed 11 months ago

Runge123 commented 1 year ago

Hi Chris,

While output linkOTB is correct

otb = link2GI::linkOTB(searchLocation = "~/OTB-8.1.1-Linux64") otb $pathOTB
1 /home/cmr/OTB-8.1.1-Linux64/bin/ $version binDir otbCmd 1 /home/cmr/OTB-8.1.1-Linux64/bin/ /home/cmr/OTB-8.1.1-Linux64/bin/otbcli $exist [1] TRUE

In the terminal the $PATH of otbcli looks correct

cmr@cmr:~$ otbcli Usage: /home/cmr/OTB-8.1.1-Linux64/bin/otbApplicationLauncherCommandLine module_name [MODULEPATH] [arguments]

then I call a raster and the "DimensionalityReduction" to calculate pca and its output

rgbFN= file.path(envrmt$path_data_lev1,"ortho_5mm/", patternImgFiles,".tif",fsep = "") pca = link2GI::parseOTBFunction("DimensionalityReduction",otb) r <- terra::rast(rgbFN) pca$input_in = r r class : SpatRaster dimensions : 6000, 6000, 3 (nrow, ncol, nlyr) resolution : 0.005, 0.005 (x, y) extent : 686552, 686582, 4606182, 4606212 (xmin, xmax, ymin, ymax) coord. ref. : ETRS89 / UTM zone 30N (EPSG:25830) source : ortho_zgz_5mm.342.tif colors RGB : 1, 2, 3 names : ortho_zgz_5mm.342_1, ortho_zgz_5mm.342_2, ortho_zgz_5mm.342_3 pca$out=file.path(R.utils::getAbsolutePath(envrmt$path_run),paste0("otb_pca_all"))

but finally when I use the runOTB function to calculate the pca I get the following error.

rpc = link2GI::runOTB(pca, gili = otb, retRaster = TRUE, quiet = quiet) Error in if (otbCmdList$mode == "vector") { : argument is of length zero

In a place of your repository (here https://github.com/r-spatial/link2GI/blob/master/R/parseOTB.R) I found that fixed this error, although I can not decipher the reason for the error. Maybe the error expresses that the raster does not have a valid length?

Any help from you would be great :)

gisma commented 11 months ago

should be fixed

Runge123 commented 11 months ago

Dear Chris,

I fixed the problem in a - rustic - way, but it works as long as the OTB specifications are used.

Link OTB: For a windows version : otb_cli_path <- normalizePath("C:/OTB/bin/otbcli.bat") For a Linux version : otb_cli_path <- normalizePath("~/OTB/bin/otbcli.bat")

basic example example: https://www.orfeo-toolbox.org/CookBook/Applications/app_EdgeExtraction.html for (edges in edgeType) { message(":::: processing edge...", edges, " Kernelsize: ", k, "\n") out_edge_file <- file.path(R.utils::getAbsolutePath(envrmt$pathrun),paste0("PCA",edges,k,"",basename(fbFN))) otb_command_edges <- paste( shQuote(otb_cli_path), "EdgeExtraction", "-in", shQuote(fbFN), "-filter", edges, "-out", shQuote(out_edge_file), "-ram", "4096")

Still can't figure out the link to use linkOTB, but I'll try to figure it out.

Thanks Chris :)