#region 判断该多边形是否与栅格有覆盖,并统计裁剪的栅格的平均值、最大值、最小值
/// <summary>
/// 判断该多边形是否与栅格有覆盖
/// </summary>
/// <param name="MyReflectRstLyr"></param>
/// <param name="MyPolygon"></param>
/// <returns></returns>
private static bool GetCoverByPloygon(IRasterLayer MyReflectRstLyr, IPolygon MyPolygon)
{
//IExtractionOp pExtractionOp = new RasterExtractionOpClass();
//IGeoDataset pGeoOutput = pExtractionOp.Polygon(pGeoDataset, pPolygone, binside);
IRasterLayer pRasterLayer = MyReflectRstLyr as IRasterLayer;
IRaster pRaster = pRasterLayer.Raster;
IRasterProps pProps = pRaster as IRasterProps;
object cellSizeProvider = pProps.MeanCellSize().X;
IGeoDataset pInputDataset = pRaster as IGeoDataset;
IExtractionOp pExtractionOp = new RasterExtractionOpClass();
IRasterAnalysisEnvironment pRasterAnaEnvir = pExtractionOp as IRasterAnalysisEnvironment;
pRasterAnaEnvir.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref cellSizeProvider);
object extentProvider = MyPolygon.Envelope;
object snapRasterData = Type.Missing;
pRasterAnaEnvir.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref extentProvider, ref snapRasterData);
IGeoDataset pOutputDataset = pExtractionOp.Polygon(pInputDataset, MyPolygon as IPolygon, true);
IRaster clipRaster; //裁切后得到的IRaster
if (pOutputDataset is IRasterLayer)
{
IRasterLayer rasterLayer = pOutputDataset as IRasterLayer;
clipRaster = rasterLayer.Raster;
}
else if (pOutputDataset is IRasterDataset)
{
IRasterDataset rasterDataset = pOutputDataset as IRasterDataset;
clipRaster = rasterDataset.CreateDefaultRaster();
}
else if (pOutputDataset is IRaster)
{
clipRaster = pOutputDataset as IRaster;
}
else
{
return false;
}
//统计平均值
IRasterBandCollection pRasterBandCol;
pRasterBandCol = (IRasterBandCollection)clipRaster;
int aa;
aa = pRasterBandCol.Count;
IRasterBand pRasterBand;
pRasterBand = pRasterBandCol.Item(0);
pRasterBand.ComputeStatsAndHist();
IRasterStatistics pRasterStatistic;
pRasterStatistic = pRasterBand.Statistics;
double meanValue;
double MaxValue;
double MinValue;
meanValue = pRasterStatistic.Mean;
MaxValue = pRasterStatistic.Maximum;
MinValue = pRasterStatistic.Minimum;
if (meanValue >= 1.0)
{
return true;
}
else
{
return false;
}
}
#endregion