Select to view content in your preferred language

Raster Calculator Expression

925
3
12-29-2013 07:28 PM
SindhuA
New Contributor
Hi,
I wanted to add the height information of two rasters and create another raster using the raster calculator. In Desktop Raster Calculator Tool the expression for the Same is like this - "Raster1" + "Raster2".
I was trying to implement the same through coding in ArcGIS Engine using a Geoprocessing tool.

The code snippet is as follows:

Geoprocessor gp = new Geoprocessor();
gp.OverwriteOutput = true;
RasterCalculator rasterCalc = new RasterCalculator();
rasterCalc.expression = " '@D:\NewFolder:\Raster1.tif" + "+" + "@D:\NewFolder:\Raster2.tif' ";
rasterCalc.output_raster = "@D:\NewFolder:\Raster3.tif";
gp.Execute(rasterCalc,null);


This is not getting executed and throws an error: HRESULT E_FAIL has been returned from a call to a COM component.

I think there is something wrong with the syntax of the expression.

Thanks in Advance for the help!

Sindhu
0 Kudos
3 Replies
curtvprice
MVP Alum
Hi,
I wanted to add the height information of two rasters and create another raster using the raster calculator. In Desktop Raster Calculator Tool the expression for the Same is like this - "Raster1" + "Raster2".
I was trying to implement the same through coding in ArcGIS Engine using a Geoprocessing tool.

The code snippet is as follows:

Geoprocessor gp = new Geoprocessor();
gp.OverwriteOutput = true;
RasterCalculator rasterCalc = new RasterCalculator();
rasterCalc.expression = " '@D:\NewFolder:\Raster1.tif" + "+" + "@D:\NewFolder:\Raster2.tif' ";
rasterCalc.output_raster = "@D:\NewFolder:\Raster3.tif";
gp.Execute(rasterCalc,null);



This is not getting executed and throws an error: HRESULT E_FAIL has been returned from a call to a COM component.


Which version of ArcGIS?

Just from a cursory look I'm wondering if your paths should be:

rasterCalc.expression = "D:\NewFolder\Raster1.tif" + " + " + "D:\NewFolder\Raster2.tif";
rasterCalc.output_raster = "D:\NewFolder\Raster3.tif";


Your expression is simple enough you may want to use the Plus tool. That would likely avoid some complications from accessing this functionality from .NET.
0 Kudos
SindhuA
New Contributor
Which version of ArcGIS?

Just from a cursory look I'm wondering if your paths should be:

rasterCalc.expression = "D:\NewFolder\Raster1.tif" + " + " + "D:\NewFolder\Raster2.tif";
rasterCalc.output_raster = "D:\NewFolder\Raster3.tif";


Your expression is simple enough you may want to use the Plus tool. That would likely avoid some complications from accessing this functionality from .NET.



Hi curtvprice,

Thanks for the reply. I am using Arc Engine 10. I do not have Desktop SDK to use the PLUS tool. I tried using the paths you have mentioned, but I got the same error again.


Sindhu.
0 Kudos
curtvprice
MVP Alum
  I tried using the paths you have mentioned, but I got the same error again. 


Have you tried this example from the .NET help? It sure looks like an safer approach than using raw pathnames.

ArcObjects .NET Help: Executing a map algebra expression
0 Kudos