yushff

code the world。

导航

ISurfaceOp 接口生成等高线

Posted on 2014-09-18 23:54  yushff  阅读(1485)  评论(2编辑  收藏  举报

(1)ISurfaceOp.Contour 根据DEM生成等高线图层:

       private void button1_Click(object sender, EventArgs e)
        {
            //得到Raster
            ILayer tLayer=this.axMapControl1.get_Layer(0);
            IRasterLayer tRasterLayer=(IRasterLayer)tLayer;

            IFeatureClass tFeatureClass=null;
            IGeoDataset tGeodataset=null;
            //使用接口 参数(Raster,等高线间距,基值)
            ISurfaceOp tSurfaceop = new RasterSurfaceOpClass();
            object obj = 0;
            tGeodataset=tSurfaceop.Contour((IGeoDataset)tRasterLayer.Raster, 10, ref obj);
            //判断是否生成等高线层,如果生成,加载到Map中
            if (tGeodataset != null)
            {
                tFeatureClass = (IFeatureClass)tGeodataset;
                if (tFeatureClass != null)
                {
                    IFeatureLayer tFeatureLayer = new FeatureLayerClass();
                    tFeatureLayer.FeatureClass = tFeatureClass;
                    this.axMapControl1.AddLayer((ILayer)tFeatureLayer);
                    this.axMapControl1.Refresh();
                }
            }
        }

(2) ISurfaceOp.ContourAsPolyline 根据已知点,返回穿过改点的等高线和改点的高程

       private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
        {
            //通过鼠标获取点击的点坐标
            IPoint tPoint = new PointClass();
            tPoint.X = e.mapX;
            tPoint.Y = e.mapY;
            //得到Raster
            ILayer tLayer = this.axMapControl1.get_Layer(0);
            IRasterLayer tRasterLayer = (IRasterLayer)tLayer;
            

            ISurfaceOp tSurfaceop = new RasterSurfaceOpClass();

            //定义返回的线
            IPolyline tPolygline = new PolylineClass();
            //定义返回的高程点
            double tEve = 0;
            tSurfaceop.ContourAsPolyline((IGeoDataset)tRasterLayer.Raster, tPoint, out tPolygline, out tEve);//tSurfaceop.Contour((IGeoDataset)tRasterLayer.Raster, 10, ref obj);

            //把生成的等高线画到Map上
            ILineElement tLineElement = new LineElementClass();
            IElement tElement = (IElement)tLineElement;
            tElement.Geometry = tPolygline;
            this.axMapControl1.ActiveView.GraphicsContainer.AddElement(tElement, 0);
            //刷新Map
            this.axMapControl1.Refresh();
        }

作者: cglnet
本文版权归cglNet和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
 

(3)ISurfaceOp.ContourList 根据一系列高程点生成等高线图层:  

       private void button1_Click(object sender, EventArgs e)
        {

            //得到Raster
            ILayer tLayer = this.axMapControl1.get_Layer(0);
            IRasterLayer tRasterLayer = (IRasterLayer)tLayer;
            //定义高程点数组
            double[] tDouble = new double[] { 100, 120, 150, 200 };

            IFeatureClass tFeatureClass = null;
            IGeoDataset tGeodataset = null;
            //使用接口
            ISurfaceOp tSurfaceop = new RasterSurfaceOpClass();
            object obj = tDouble;

            tGeodataset = tSurfaceop.ContourList((IGeoDataset)tRasterLayer.Raster, ref obj);
            //判断是否生成等高线层,如果生成,加载到Map中
            if (tGeodataset != null)
            {
                tFeatureClass = (IFeatureClass)tGeodataset;
                if (tFeatureClass != null)
                {
                    IFeatureLayer tFeatureLayer = new FeatureLayerClass();
                    tFeatureLayer.FeatureClass = tFeatureClass;
                    this.axMapControl1.AddLayer((ILayer)tFeatureLayer);
                    this.axMapControl1.Refresh();
                }
            }
        }

(4)ISurfaceOp.ContoursAsPolylines根据一系列点生成多根等高线

        //定义点坐标集合
        IPointCollection _PointCollect = new MultipointClass();
        private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
        {
            //通过鼠标获取点击的点坐标集合
            IPoint tPoint = new PointClass();
            tPoint.X = e.mapX;
            tPoint.Y = e.mapY;
            object obj = Type.Missing;
            _PointCollect.AddPoint(tPoint, ref obj, ref obj);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //得到Raster
            ILayer tLayer = this.axMapControl1.get_Layer(0);
            IRasterLayer tRasterLayer = (IRasterLayer)tLayer;
            
            ISurfaceOp tSurfaceop = new RasterSurfaceOpClass();
            //定义返回的线集合
            IGeometryCollection tGeometryCollection;
            //定义返回的高程点集合
            IPointCollection tEveColl;
            tSurfaceop.ContoursAsPolylines((IGeoDataset)tRasterLayer.Raster, _PointCollect, out tGeometryCollection, out tEveColl);//tSurfaceop.Contour((IGeoDataset)tRasterLayer.Raster, 10, ref obj);
            if (tGeometryCollection!=null && tGeometryCollection.GeometryCount > 0)
            {
                //把生成的等高线画到Map上
                for (int i = 0; i < tGeometryCollection.GeometryCount; i++)
                {
                    IGeometry tGeometry = tGeometryCollection.get_Geometry(i);
                    ILineElement tLineElement = new LineElementClass();
                    IElement tElement = (IElement)tLineElement;
                    tElement.Geometry = tGeometry;
                    this.axMapControl1.ActiveView.GraphicsContainer.AddElement(tElement, 0);
                }
            }
            //刷新Map
            this.axMapControl1.Refresh();
        }

作者: cglnet
本文版权归cglNet和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
 
from:http://www.cnblogs.com/cglNet/archive/2011/03/03/1970061.html
http://www.cnblogs.com/cglNet/archive/2011/03/03/1970100.html