AnsweredAssumed Answered

How to combine rasters with the RasterCalculator function ?

Question asked by heleneimpini on Apr 20, 2018

Dear all,

 

I have three imagery layers loaded and only one of them displayed on my map ; when the user clicks on a button in the app, I would like to apply a new renderingRule on the displayed layer, where I use the RasterCalculator function to combine the three rasters.

 

If I try to add the displayed raster to itself, it works, and a new output raster is displayed, with new values, but if I try to add the displayed layer to the other two rasters, I get the "Uncaught RangeError: Maximum call stack size exceeded" message.

 

What I have so far :

var layer1 = new ImageryLayer({
      url: "<url>",
      id: "layer1"
});
var layer2 = new ImageryLayer({
      url: "<url>",
      id: "layer2"
});
var displayedLayer = new ImageryLayer({
      url: "<url>",
      id:"displayedLayer"
});
map.layers.add(displayedLayer );


Click event :

displayedLayer.renderingRule = newOutput();

 

And the newOutput() function :

var newOutputRaster = new RasterFunction({
      functionName: "RasterCalculator",
      functionArguments: {
         inputNames: ["input1", "input2", "input3"],
         expression: "input1 + input2 + input3",
         rasters: ["$$", layer1, layer2] // doesn't work, but rasters: ["$$", "$$"], inputNames: ["input1", "input1"] and expression: "input1 + input1" does work !
      },
      outputPixelType: "U8"
});
return newOutputRaster;

 

Am I missing something ? I'm using the 4.6 version of the API. Thank you. 

Outcomes