I am writing an ArcMap extension where I need to do some raster manipulation. When I run my extension in ArcMap 9.3.1, everything is fine, but when I run it in ArcMap 10, I get the following errors from a call to RasterExtractionOpClass.Attribute():ERROR 010235: Returned error from MergeVAT.ERROR 010067: Error in executing grid expression.Here is the code that produces the error:
// NOTE: demRasterIn is initialized earlier.
IGeoDataset connectedRegion = null;
try
{
// Reclassify all negative values to 1
IReclassOp reclassOp = new RasterReclassOpClass();
INumberRemap remap = new NumberRemapClass();
remap.MapRange(-1000, 0, 1);
IGeoDataset singleValueRaster = reclassOp.ReclassByRemap(demRasterIn, (IRemap)remap, false);
// Convert to an integer raster (required for region group)
IMathOp mathOp = new RasterMathOpsClass();
IGeoDataset singleValueIntRaster = mathOp.Int(singleValueRaster);
// Group connected regions together
IGeneralizeOp generalizeOp = new RasterGeneralizeOpClass();
object missing = Type.Missing;
IGeoDataset clumpedValues = generalizeOp.RegionGroup(singleValueIntRaster, true, true, true, ref missing);
// Find the largest connected region
ESRI.ArcGIS.Geodatabase.ITable attributes = ((IRaster2)clumpedValues).AttributeTable;
ESRI.ArcGIS.Geodatabase.IQueryFilter queryFilter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass();
queryFilter.AddField("COUNT");
ESRI.ArcGIS.Geodatabase.ICursor cursor = attributes.Search(queryFilter, false);
int index = cursor.FindField("COUNT");
int maxCount = 0;
ESRI.ArcGIS.Geodatabase.IRow row = cursor.NextRow();
while (row != null)
{
int count = (int)row.get_Value(index);
if (count > maxCount)
{
maxCount = count;
}
row = cursor.NextRow();
}
// Extract the pixels from the largest connected area
IRasterDescriptor rasterDescriptor = new RasterDescriptorClass();
IQueryFilter rasterFilter = new QueryFilterClass();
rasterFilter.WhereClause = String.Format("\"COUNT\" = {0}", maxCount);
rasterDescriptor.Create((IRaster)clumpedValues, rasterFilter, "COUNT");
IExtractionOp extractionOp = new RasterExtractionOpClass();
connectedRegion = extractionOp.Attribute(rasterDescriptor); // <-- Exception thrown here
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
I added the clumpedValues raster to the map (in ArcMap 10) and looked at the attribute table. It contains a column called "COUNT" and the logic successfully gets the largest value. I tried removing the quotes from around COUNT in the rasterDescriptor.WhereClause, but that did not fix the problem.Does anyone know why this code succeeds in ArcMap 9.3.1 and fails in ArcMap 10? Our ArcGIS 10 installation has service pack 3 installed. Is there a Spatial Analyst service pack that is needed?Thanks,Bob