I'm trying to call the geoprocessor from arcengine in c# code and I keep getting an error. I've used simple file and folder names, and the process works fine in ArcMap, but fails in arcengine. Here is the error message from the geoprocessor:
Zonal statistics program failed
Executing: ZonalStatisticsAsTable C:\testnes\subs.shp AREA_NAME C:\testnes\nonesurr C:\fortis\table6.dbf DATA
Start Time: Tue Sep 06 09:25:46 2011
An error was encountered while executing ZonalStatisticsAsTable.
("esriGeoAnalyst.GridEngine") Zonal statistics program failed
Error in executing grid expression
Failed to execute (ZonalStatisticsAsTable).
End Time: Tue Sep 06 09:25:51 2011 (Elapsed Time: 5.00 seconds)
And here is the source code:
GPHelper.GPZonalStats(@"C:\testnes\subs.shp", @"C:\testnes\nonesurr", "AREA_NAME", @"C:\fortis\table6.dbf");
GPHelper class functions:
public static bool GPZonalStats(string strZoneRaster, string strValueRaster, string strZoneField, string strTable)
{
Geoprocessor pGP = new Geoprocessor();
ZonalStatisticsAsTable zonalStats = new ZonalStatisticsAsTable();
zonalStats.in_zone_data = strZoneRaster;
zonalStats.in_value_raster = strValueRaster;
zonalStats.zone_field = strZoneField;
zonalStats.out_table = strTable;
return RunGP(pGP, zonalStats, null);
}
public static bool RunGP(Geoprocessor geoprocessor, IGPProcess process, ITrackCancel TC)
{
// Set the overwrite output option to true
//Debug.WriteLine(Convert.ToString(geoprocessor.GetEnvironmentValue("Workspace")));
geoprocessor.OverwriteOutput = true;
// Execute the tool
try
{
geoprocessor.Execute(process, null);
return ReturnMessages(geoprocessor);
}
catch (Exception err)
{
Console.WriteLine(err.Message);
return ReturnMessages(geoprocessor);
}
}
// Function for returning the tool messages.
private static bool ReturnMessages(Geoprocessor gp)
{
if (gp.MessageCount > 0)
{
string allMessages = null;
for (int Count = 0; Count <= gp.MessageCount - 1; Count++)
{
Console.WriteLine(gp.GetMessage(Count));
allMessages += gp.GetMessage(Count);
}
if (allMessages.Contains("successfully"))
{
return true;
}
else return false;
}
else return false;
}