IZonalOp.ZonalStatisticsAsTable C#

296
2
12-19-2011 06:55 AM
MarilynGambone
New Contributor
Hi,

I'm trying to follow the ArcObject sample codes for calculating zonal statistics as table. I'm not getting an error but at the same time, there is no output.  I notice the difference between this SpatialAnalyst ArcObject and the SpatialAnalystTool's ZonalStatisticsAsTable: The ArcObject version is missing the output table name. I don't know where to specify this in the ArcObject version.  Here's a snippet of my code:

//Create a Feature Class Descriptor object for input shapefile zones
IFeatureClassDescriptor aoiDesc = new FeatureClassDescriptorClass();
string zoneField = "HydroID";
IFeatureClass aoiFc = OpenFeatureClassFromShapefiile(polygonPath, polygonName);
IGeoDataset aoiGds = (IGeoDataset)aoiFc;
aoiDesc.Create(aoiFc, null, zoneField);
aoiGds = (IGeoDataset)aoiDesc;

//Create a Raster Descriptor object for input raster values
IRaster ras = new RasterClass();
ras = OpenRasterDataset(exprasPath, exprasName).CreateDefaultRaster();
IRasterDescriptor rasDesc = new RasterDescriptorClass();
string rasValue = "VALUE";
rasDesc.Create(ras, null, rasValue);
IGeoDataset rasGds = (IGeoDataset)rasDesc;

//Create an instance of the output table object
ITable stats = null;

//Initialize an IZonalOp object
ESRI.ArcGIS.SpatialAnalyst.IZonalOp zoneOp = new ESRI.ArcGIS.SpatialAnalyst.RasterZonalOpClass();

//Perform spatial operation
stats = zoneOp.ZonalStatisticsAsTable(aoiGds, rasGds, true);



Appreciate any suggestion on how to get this to work.
0 Kudos
2 Replies
curtvprice
MVP Esteemed Contributor
Have you considered using the geoprocessor? In general it is a lot less painful to create a geoprocessor object and throw the tool at it.
0 Kudos
MarilynGambone
New Contributor
Hi,

Yes. That's what I ended up doing.  Just wondering if the ESRI guys know there's something wrong with this ArcObject function.

Thanks...
0 Kudos