[arcengine][栅格]裁剪栅格

功能:通过面要素裁剪栅格图层
版本:10.2
注意:栅格和裁剪要素坐标统一

/// 
        /// 裁剪栅格图层
        /// 
        /// 栅格图层
        /// 裁剪范围
        /// 
        /// IRaster
        private IRaster RasterClip(IRasterLayer pRasterLayer, IPolygon clipGeo)
        {
            if (clipGeo == null) return null;

            IRaster clipRaster = null;

            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 = clipGeo.Envelope;
            object snapRasterData = Type.Missing;
            pRasterAnaEnvir.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref extentProvider, ref snapRasterData);
            IGeoDataset pOutputDataset = pExtractionOp.Polygon(pInputDataset, clipGeo as IPolygon, true);

            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;
            }

            return clipRaster;
        }

你可能感兴趣的:(ArcGIS,Engine,开发)