Arcengine,C#,影像数据的裁切和保存

using ESRI.ArcGIS.esriSystem;

using ESRI.ArcGIS.Controls;

using ESRI.ArcGIS.SystemUI;

using ESRI.ArcGIS.Carto;

using ESRI.ArcGIS.Geodatabase;

using ESRI.ArcGIS.DataSourcesGDB;

using ESRI.ArcGIS.Geometry;

using ESRI.ArcGIS.DataSourcesRaster;

using ESRI.ArcGIS.SpatialAnalyst;

using ESRI.ArcGIS.GeoAnalyst;

 

public class ArcGISRaster

    {

        //ArcGIS影像操作

        /// <summary>

        /// 影像切割by yl 2008.06.16 landgis@126.com,参考http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=28659&extra=&page=1修改

        /// </summary>

        /// <param name="pRasterLayer">//要裁切的影像图层</param>

        /// <param name="FileName">文件名为.img</param>

        public static void RasterClip(IRasterLayer pRasterLayer, IPolygon clipGeo, string FileName)

        {

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

            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;

            }

 

            //保存裁切后得到的clipRaster

 

            //如果直接保存为img影像文件

            IWorkspaceFactory pWKSF = new RasterWorkspaceFactoryClass();

            IWorkspace pWorkspace = pWKSF.OpenFromFile(System.IO.Path.GetDirectoryName(FileName), 0);

            ISaveAs pSaveAs = clipRaster as ISaveAs;

            pSaveAs.SaveAs(System.IO.Path.GetFileName(FileName), pWorkspace, "IMAGINE Image");

        }

    }

调用: //by yl 2008.06.16 landgis@126.com

private void mainMap_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)

        {

            IGeometry clipGeo = this.mainMap.TrackPolygon();  //

            ILayer layer = this.mainMap.get_Layer(0);   //要裁切的影像图层

            IRasterLayer pRasterLayer = layer as IRasterLayer;

            ArcGISPub.ArcGISRaster.RasterClip(pRasterLayer,clipGeo as IPolygon,@"c:/temp/yl.img");

}

参考http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=28659&extra=&page=1修改

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值