[arcengine][栅格]裁剪栅格


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

/// <summary>
        /// 裁剪栅格图层
        /// </summary>
        /// <param name="pRasterLayer">栅格图层</param>
        /// <param name="clipGeo">裁剪范围</param>
        /// <param name="fileName"></param>
        /// <returns>IRaster</returns>
        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;
        }

转载自:https://blog.csdn.net/gis_zss/article/details/51577976

You may also like...

退出移动版