knitr::opts_chunk$set(
  collapse = TRUE,
  fig.path = "man/figures/",
  comment = "#>"
)

R UDF service using base64 encoded string

This strategy also uses HTTP POST requests to transmit data to and from the UDF service, similar to the strategy using JSON arrays. In this case, however, the POST body contains a base64 encoded string of a ZIP file containing multiple binary GeoTIFF files. The semantics of these files (timestamps, band names etc.) are handled using a JSON array (currently of a JSON string) which is embedded in the POST body together with the string itself.

Overview of Strategy

knitr::include_graphics("../man/figures/strategy_3.png")

JSON structure

The JSON schema for this strategy is somewhat different from that of the that of Strategies 2A and 2B. A brief overview of it is shown below

{
    "legend": ["[
                  {\"X1\":1,\"filename\":\"disk/t_1/b_1.tif\",\"time_index\":1,\"timestamp\":\"2016-12-12 08:23:32\",\"band_index\":1,\"band\":\"1\"}, 
                  {\"X1\":2,\"filename\":\"disk/t_1/b_2.tif\",\"time_index\":1,\"timestamp\":\"2016-12-12 08:23:32\",\"band_index\":2,\"band\":\"2\"},
                  ...
                ]"
               ],
    "code": {
             "code": {
                          "language": ["r"],
                          "source": ["function(obj){library(dplyr)\nb4 = slice(obj, 'band', 4)\nb8 = slice(obj, 'band', 8)\nndvi = (b8 - b4)/(b8 + b4)}"],
                          "alt_dim": ["time"]
                     }
            },
     "base64str": ["UEsDBBQAAAAIAJihZk3HyJPn82wBAP13AQALAAAAdF8x ... =="]
}

One of the reason for keeping "language" as an array is because it the ZIP file might contain sources of files in multiple languages in the future. The "alt_dim" is also kept as an array since multiple dimensions might change (or added) and for compatibility with Strategies 2A and 2B (but has no particular use currently). The example above calculates NDVI for each of the timesteps in the input data.

Testing

Testing of this endpoint (/udf/binary) could be done in a similar manner as Strategies 2A and 2B by sending a HTTP POST request. Using curl, that should look like

curl -H "application/json" -d @"udf_binary_file.json" http://127.0.0.1:5384/udf/binary

In this examples, the -d flag can be used to point to the location of the appropriate JSON file on disk which would be used as the body to the POST request. Of course, any server and port hosting the service could be used instead of the one in the example (http://127.0.0.1 and 5384 respectively).



pramitghosh/OpenEO.R.UDF documentation built on Dec. 4, 2019, 4:58 a.m.