karlsiemsen

ArcEngine 10 migration raises problems with RasterModel class.

Discussion created by karlsiemsen on Jun 15, 2011
I'm trying to migrate a standalone desktop application built on ArcEngine 9.3 to ArcEngine 10.

I've gone through all the migration steps to get to a working program. The core algorithm includes a number of map algebra operations run using the RasterModel class. Two different sets of these run and work fine, but the third, which uses the ouputs from the first set as inputs, creates a raster with max and min values of 3.4e10+38 and -3.4e10+38. This is, obviously, not the correct output from the map algebra. It displays as a gray field, and I can't query individual cell values because only my ArcEngine is version 10, the rasters are in personal geodatabases, and I can't open them with my ArcGIS 9.3.

The program works fine and produces correct outputs when run with ArcEnine 9.2 or 9.3, none of the functional code for the map algebra has changed with the migration, so I'm inclined to blame this on some previously undiscovered bug or incompatibility between 9.3 and 10 having to do either with the RasterModel or with saving and opening rasters from personal geodatabases. I'm open to any possibility though.

This is the map algebra statement:

[out1] = [input0] * 10 + [input1] * -1 + [input2] * 5 + [input3] * 10 + 0.0

The relevant code looks like this (I've edited out some irrelevant things for clarity, including try and catch blocks that should show any errors, none are being triggered):

  IRaster pRSOut1 = null;
                IRasterModel pRasModel = null;
                IRasterAnalysisEnvironment pEnv = null;

                int i;
                string sMAExpression, sInput;

                 //bind rasters
                 pRasModel = new RasterModelClass();
                 pEnv = (IRasterAnalysisEnvironment)pRasModel;
                 pEnv.OutWorkspace = ArcHelper.OpenWorkspace(ModelRBSELF.AppTempPath, DatabaseType.Raster);

                 sMAExpression = "[out1] = ";
                 for (i = 0; i < pInputRas.RasterCount; i++)
                 {
                     sInput = "input" + i.ToString();
                     pRasModel.BindRaster(pInputRas.Get(i), sInput);
                     sMAExpression += " [" + sInput + "] * " + pArray.GetValue(i).ToString() + " + ";
                 }
                 sMAExpression += "0.0";
                 pRasModel.Script = sMAExpression;
                 Console.WriteLine("Preference sMAExpression = " + sMAExpression);
                 try
                 {
                     pRasModel.Execute();
                 }
                 catch (COMException comE)
                 {
                     Debug.WriteLine("COM exceptions executing preference raster expression\n" + comE.Message);
                 }
                
                 pRSOut1 = pRasModel.get_BoundRaster("out1");
                
   //unbind input rasters
                 for (i = 0; i < pInputRas.RasterCount; i++)
                 {
                     sInput = "input" + i.ToString();
                     pRasModel.UnbindSymbol(sInput);
                 }

                 return pRSOut1;

The returned in memory raster is passed to a method that does this:

     IWorkspace pWS = null;
            ISaveAs Saveas = null;
            IClone pRasterClone = null;


            pWS = ArcHelper.OpenWorkspace(wsPath, wsType); //Utility method for workspace factories and such, works everywhere else.

            pRasterClone = (IClone)pRaster;
            Saveas = (ISaveAs)pRasterClone.Clone();

            Debug.WriteLine("Saving Raster: " + sRasName + " to Workspace: " + pWS.PathName);

            Saveas.SaveAs(sRasName, pWS, "GRID");

Outcomes