Error returned from RasterExtractionOpClass.Attribute() method

480
5
05-10-2012 06:36 AM
BobCave
New Contributor
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
0 Kudos
5 Replies
ThaiTruong
Occasional Contributor II
Try:

ESRI.ArcGIS.Geodatabase.IGeoDataset connectedRegion = extractionOp.Attribute(rasterDescriptor);
0 Kudos
ThaiTruong
Occasional Contributor II
Try this:

    // Extract the pixels from the largest connected area
    ESRI.ArcGIS.SpatialAnalyst.IExtractionOp extractionOp = new ESRI.ArcGIS.SpatialAnalyst.RasterExtractionOpClass();
    ESRI.ArcGIS.GeoAnalyst.IRasterDescriptor rasterDescriptor = new ESRI.ArcGIS.GeoAnalyst.RasterDescriptorClass();
    ESRI.ArcGIS.Geodatabase.IQueryFilter rasterFilter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass();
    rasterFilter.WhereClause = String.Format("\"COUNT = {0}\"", maxCount);
    rasterDescriptor.Create((IRaster)clumpedValues, rasterFilter, "COUNT");
    ESRI.ArcGIS.Geodatabase.IGeoDataset connectedRegion = extractionOp.Attribute(rasterDescriptor);
0 Kudos
BobCave
New Contributor
Thanks for the suggestion, but that did not work.  Putting the quotes around the entire "COUNT = {0}" results in an "invalid SQL statement" error.  I have tried removing the escaped quotes, but that didn't help either.  I think I used the escaped quotes to get the statement to work in ArcMap 9.3.1 in the first place.

Can anyone shed some light on what these error messages mean, or if there is a way to get more detailed information?  The messages seem pretty generic.

ERROR 010235: Returned error from MergeVAT.
ERROR 010067: Error in executing grid expression.



Thanks,

Bob
0 Kudos
ThaiTruong
Occasional Contributor II
Hi Bob, Sorry it didn't work out for you! I wonder if you already declared the object for your input raster dataset somewhere above?!

rasterDescriptor.Create((IRaster)clumpedValues, rasterFilter, "COUNT");


Here is the decription for 010067 : Error in executing grid expression
0 Kudos
BobCave
New Contributor
The input raster is declared and created in the code above the statement where it is used.  This code works in ArcMap 9.3.1 but does not work in ArcMap 10 using the same data.  I am trying to find out what has changed between ArcGIS 9.3.1 and ArcGIS 10 with regards to the RasterExtractionOpClass.Attribute() method.  I looked at the documentation, and as far as I can tell, my input parameters are correct.

Thanks,

Bob
0 Kudos