• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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 [email protected],参考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 [email protected]

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修改


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
c#空接合(??)运算符的运用发布时间:2022-07-10
下一篇:
C#同步网络时间的方法实例详解发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap