ArcEngine开发总结-(3)栅格平滑
行业应用中,插值得到的栅格图不是很美观,可以平滑去掉栅格小斑块以达到美观。对应arcmap中的focal statistics功能,基本原理是利用计算周围范围内的栅格标准差为最终栅格值,达到栅格的平滑效果。栅格范围 可以是矩形 圆形、环状、扇形、及其他高级形状(可查相关资料),以下程序提供 圆形范围平滑及利用递归实现设置平滑次数
/// <summary>
/// 模块编号:RasterSmooth
/// 作用:栅格平滑
/// 作者
/// 编写日期:2011-07-11
/// </summary>
class RasterSmooth
{
private IGeoDataset geoDataset;
private IRasterNeighborhood rasterNeighborhood;
private INeighborhoodOp neighborhoodOp;
private IRaster outRaster=null;
private int num;
/// <summary>
/// 栅格平滑
/// </summary>
/// <param name="raster">栅格</param>
/// <param name="width">象元数</param>
/// <param name="height">象元数</param>
/// <returns></returns>
public IRaster Smooth(IRaster raster,double width,int smooths)
{
num=smooths;
if(raster!=null)
{
geoDataset = raster as IGeoDataset;
rasterNeighborhood = new RasterNeighborhoodClass();
rasterNeighborhood.SetCircle(width, esriGeoAnalysisUnitsEnum.esriUnitsCells);
neighborhoodOp = new RasterNeighborhoodOpClass();
if (num > 0)
{
outRaster = neighborhoodOp.FocalStatistics(geoDataset, esriGeoAnalysisStatisticsEnum.esriGeoAnalysisStatsMean, rasterNeighborhood, true) as IRaster;
num = num - 1;
outRaster = Smooth(outRaster, width, num);
}
}
return outRaster;
}
}