Raster Calculator Expression in C#

1092
2
07-29-2013 11:47 AM
LynneBridgford
New Contributor
I'm trying to use the RasterCalculator in C# (I'm not using python)

            string slopeRadiansRasterFilePath = Path.Combine(_options.OutputTmpWorkspaceName, "SlopeRadians");
            string formula = ('C:\Workspace\ForestGrids\R03\0310_SantaFe_smallTest\test\NnDemRasters.gdb\Elev' * 1.570796) / 90;

            RasterCalculator rasterCalc = new RasterCalculator();
            rasterCalc.expression = formula;
            rasterCalc.output_raster = slopeRadiansRasterFilePath;

Every time I run it I get a HRESULT error.

I can use the GP tool menu interface with the same raster and formula and it works fine.  Any ideas on what the format of the expression should be?  I've tried several different variations with single quotes, double quotes, square brackets, etc.
0 Kudos
2 Replies
sameerpuppal
Occasional Contributor
I'm trying to use the RasterCalculator in C# (I'm not using python)

            string slopeRadiansRasterFilePath = Path.Combine(_options.OutputTmpWorkspaceName, "SlopeRadians");
            string formula = ('C:\Workspace\ForestGrids\R03\0310_SantaFe_smallTest\test\NnDemRasters.gdb\Elev' * 1.570796) / 90;

            RasterCalculator rasterCalc = new RasterCalculator();
            rasterCalc.expression = formula;
            rasterCalc.output_raster = slopeRadiansRasterFilePath;

Every time I run it I get a HRESULT error.

I can use the GP tool menu interface with the same raster and formula and it works fine.  Any ideas on what the format of the expression should be?  I've tried several different variations with single quotes, double quotes, square brackets, etc.


did you get any solution to this?
0 Kudos
LynneBridgford
New Contributor
I have not found a solution yet but I'm still looking.
0 Kudos