1

Is there a way to use the data from the R global environment object as input for an rsaga.geoprocessor alghoritm? And if yes, can be the output also saved as a same object? I am writing chain processes and the constant importing/exporting of results makes the whole process far from elegant, as you can see on the code below:

rsaga.geoprocessor("grid_filter", 15, env = env,
                    list(INPUT="AKV_mode_5.tif",
                    OUTPUT="AKV_OUTPUT.sdat",
                    MODE="Moore",
                    THRESHOLD=4,
                    ALL="single class",
                    CLASS=2))

AKV_2_3 <- raster('AKV_OUTPUT.sdat')

AKV_2_3_recl <- reclassify(AKV_2_3, cbind(NA, 3))

writeRaster(AKV_2_3_recl, 'AKV_OUTPUT_2.tif', options="COMPRESS=LZW") 

rsaga.geoprocessor("grid_filter", 15, env = env,
               list(INPUT="AKV_OUTPUT_2.tif",
                    OUTPUT="AKV_OUTPUT_3.sdat",
                    MODE="Moore",
                    THRESHOLD=4,
                    ALL="single class",
                    CLASS=3))
2

This is not possible in the RSAGA package without a massive restructuring.

RSAGA works by running an external saga_cmd command, which starts a new process that does input and output via files.

To do otherwise could be done, but it would require dynamically linking to the SAGA C++ code, and writing R to C++ wrappers (which would probably be best done using Rcpp). This is not a trivial task.

I think the Python SAGA API does this, so if file I/O is a real bottleneck problem you might consider rewriting your critical analysis code to use that instead of R.

  • Ok, I will do it in Python then, thank you @Spacedman! – mazinga Jun 11 at 7:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.