Hi adam,
I apologize in advance for a very long answer to your question. If I had more time, I would make it shorter. But in brief, yes, you can expose a scalar value in a local function and override it's default values via REST.
Now for the long answer. I'll explain how this works by way of example:
This function chain uses a Local function to divide the pixel values from the service data by a scalar value.
After the division, a stretch function is used to transform the result of the division to an unsigned 8-bit output (0-255). This is followed by a Colormap function to display the result and a ColorMapToRGB function to convert the output to RGB so it can be viewed in web maps and apps. But let's focus on the Local function, and how you pass in scalar values for the divisor via REST - the rest is window dressing.
Local functions configured with the Divide operater require two inputs: the data to be divided, which in this case are the pixels from the image service, and the scalar value to divide by. In this example, the default value for the divisor scalar is "1". Now let's take a look at the Variable Manager tab of the Local Function Properties window.
I assigned to the "Rasters" argument the variable name "Rasters" (although I could have assigned it any name I wanted). In order to override the default scalar value for the divisor, you need to know the name assigned to this argument. We'll get back to this in a moment.
I uploaded this template to an image service which contains a single raster dataset of the "normal" global rainfall for a particular month and year. Here is what the default service output looks like:
To invoke the raster function template with the default argument values, simply call the function by name (in this example "LocalFunctionScalarTest") by passing in the following JSON string as the Rendering Rule parameter of the Export Image operation.
{
"rasterFunction": "LocalFunctionScalarTest",
}
Now we can get back to your original question about how to override the default scalar values for arguments in the Local function. In this example, I divide the precipitation values by 0.1:
{
"rasterFunction": "LocalFunctionScalerTest",
"rasterFunctionArguments": { "Rasters": ["$$", 0.1 ] }
}
Note the variable name "Rasters" and the array of values following it. The first value in the array, "$$", is a "keyword" which represents the default pixel values from the service data. This is identical to the first item in the "Input Rasters" list in the Local tab of the function properties window. The second value, of course, is the new scalar value for the divisor. Here is the result:
I hope this helps. Here are some links to documentation for the REST API that might answer any further questions you have:
Export Image: ArcGIS REST API
Using Rasters in Rendering Rules: ArcGIS REST API
By the way, I'm the author of the article you mentioned in Update #2. I have only a small amount of experience developing with the ArcGIS Runtime, and it's been a while since I have worked in that space. But I'm not aware of any reason why you could not develop an app similar to that one using the ArcGIS Runtime. To build an application that interacts with image services and custom server functions, start with the back-end server part:
- publish your image service.
- build the function template using the Raster Function Template Editor in ArcMap. Assign unique variable names to each of the function arguments you want to override in your app (using the Variable Manager tabs of the functions in the template), and upload the template to the service.
- Test the function by passing in JSON strings into the rendering rule of the service REST endpoint to make sure you are getting the expected results.
After the back-end server part is working according to design, build a custom widget with the ArcGIS Runtime to override the default function arguments.
Good luck!
-dave