C#+ ArcEngine 调用GP栅格计算器工具示例
时间: 2024-12-20 09:19:14 浏览: 44
在C#中使用ArcGIS Engine(现在被称为ArcObjects)调用地理处理(Geoprocessing)工具,如栅格计算器(Raster Calculator),通常需要通过Esri.ArcGISDesktopRuntime.Data.RasterDataset和Esri.Geoprocessing.ArcToolbox.GeoProcessor类。下面是一个简单的示例:
```csharp
using Esri.ArcGISRuntime;
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Layers;
using Esri.ArcGISRuntime.Tasks.Geoprocessing;
// 创建GeoProcessor实例
IGeoProcessor geoProcessor = new GeoProcessor();
// 定义栅格数据集路径
string inputRasterPath = @"C:\path\to\input\raster.tif";
string outputRasterPath = @"C:\path\to\output\raster.tif";
// 根据需要定义栅格计算器表达式,例如计算两层 raster 的加法
string calculatorExpression = "ras1 + ras2";
// 使用GeoProcessor运行栅格计算器任务
IGeoProcessingResult result = await geoProcessor.ExecuteAsync(new ProcessTaskDefinition("Raster Calculator", new RasterCalculatorJob(inputRasterPath, calculatorExpression, outputRasterPath)));
// 检查结果是否成功
if (result.Succeeded)
{
Console.WriteLine("Raster Calculator task executed successfully.");
}
else
{
Console.WriteLine($"Error executing task: {result.Error.Message}");
}
阅读全文