How to average two rasters in ArcGIS JS API?

1656
1
12-12-2016 05:36 PM
LJiang
by
New Contributor

Hello all,

I have two raster datasets (in arcgis image server) and I need to get an average of the two represented as one raster layer.  It can be easily achieved in ArcMap by "Spatial Analyst-->Map Algebra-->Raster Calculator" using "(Float(raster1) + Float(raster2))/2". And ArcPy can also do this using arcpy.sa module. I am wondering if it can be done in ArcGIS JavaScript API (Version 3.18).

It seems that the 'Local' function in Class: RasterFunction can do this, but I don‘t know how to do it. Any help please.

0 Kudos
1 Reply
LJiang
by
New Contributor

Here is my code, but it seems this doesn't work.  

var rf1 = new RasterFunction();
rf1.functionName = "Stretch";
rf1.functionArguments  = {
   "StretchType": 6, //6 = PercentClip
   "MinPercent": 0.5,
   "MaxPercent":0.5,
   "UseGamma":true,
   "Gamma" : [3.81464485861804, 3.81464485861804, 3.81464485861804],
   "DRA":true
};
var params1 = new ImageServiceParameters();
params1.renderingRule = rf1;

var rasterLayer1 =  new ArcGISImageServiceLayer(url1, {imageServiceParameters:params1});
map.addLayer(rasterLayer1);

var rf2 = new RasterFunction();
rf2.functionName = "Stretch";
rf2.functionArguments  = {
   "StretchType": 6, //6 = PercentClip
   "MinPercent": 0.5,
   "MaxPercent":0.5,
   "UseGamma":true,
   "Gamma" : [3.81464485861804, 3.81464485861804, 3.81464485861804],
   "DRA":true
};
var params2 = new ImageServiceParameters();
params2.renderingRule = rf2;

var rasterLayer2 =  new ArcGISImageServiceLayer(url2, {imageServiceParameters:params2});
       
function executeLocal(){
   var rfLocal = new RasterFunction();
   rfLocal.functionName = "Local";
   rfLocal.variableName = "Rasters";
   //int (1 = Plus, 2 = Minus, 3 = Times, ..., 40 = Mean )
   rfLocal.functionArguments = {
      "Operation" : 40,
      "Rasters":[rf1, rf2]
   };
   rasterLayer1.setRenderingRule(rfLocal);
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
0 Kudos