zoukankan      html  css  js  c++  java
  • 栅格数据切割

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

    }

  • 相关阅读:
    对Spring <context:annotation-config/>的理解
    Javascript this指针
    go 打造世界最快的go模板引擎gorazor 2.0
    swagger 部署(Mac )
    Ab测试
    Nginx tcp限制并发、IP、记日志
    Nginx proxy_protocol协议与realip模块
    数据结构之回溯
    数据结构之分治
    数据结构之二分查找
  • 原文地址:https://www.cnblogs.com/zhangjun1130/p/1745475.html
Copyright © 2011-2022 走看看