码迷,mamicode.com
首页 > 其他好文 > 详细

ArcEngine下TIN生成等高线

时间:2014-05-15 04:17:33      阅读:334      评论:0      收藏:0      [点我收藏+]

标签:3dgis   arcengine   scenecontrol   tin   等高线   

时间太晚了,直接附上源码:

    /// <summary>
        /// TIN生成等高线
        /// </summary>
        /// <param name="pInterval">等高线间距</param>
        public void Tin2Contour(string path_,string name_,double pInterval)
        {
            //获取TIN
            ITinLayer pTinlayer = GetLayerByName(pScene , comboBox_TIN.Text) as ITinLayer;
            ITin pTin = pTinlayer.Dataset as ITin;

            //创建Contour shape
            IWorkspaceFactory pWSFac = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace pFeatureWS = pWSFac.OpenFromFile(path_ , 0) as IFeatureWorkspace;
            if (System.IO.File.Exists(path_+"\\"+name_+".shp"))
            {
                System.IO.File.Delete(path_ + "\\" + name_ + ".shp");
                System.IO.File.Delete(path_ + "\\" + name_ + ".dbf");
                System.IO.File.Delete(path_ + "\\" + name_ + ".shx");
            }
            IFields pFields = CreateShapeFields(esriGeometryType.esriGeometryPolyline);
            pFeatureWS.CreateFeatureClass(name_ , pFields , null , null , esriFeatureType.esriFTSimple , "Shape" , null);
           
            IFeatureClass pContourFeatureClass = pFeatureWS.OpenFeatureClass(name_);
         
            //生成等高线
            ITinSurface pTinSurface = pTin as ITinSurface;
            pTinSurface.Contour(0 , pInterval , pContourFeatureClass , "Contour" , 0);

            //添加等高线图层
            IFeatureLayer pFeatureLayer = new FeatureLayerClass();
            pFeatureLayer.FeatureClass = pContourFeatureClass;
          
            IGeoFeatureLayer pGeoFeatureLayer = pFeatureLayer as IGeoFeatureLayer;
            pGeoFeatureLayer.DisplayAnnotation = true;
            pGeoFeatureLayer.DisplayField = "Contour";
            pGeoFeatureLayer.Name = pContourFeatureClass.AliasName + "_Contour";

            //设置线样式
            ILineSymbol pLineSymbol = new SimpleLineSymbolClass();
            pLineSymbol.Color = GetRGBColor(32 , 47 , 247);
            pLineSymbol.Width = 2;
            ISimpleRenderer pRender = pGeoFeatureLayer.Renderer as ISimpleRenderer;
            pRender.Symbol = pLineSymbol as ISymbol;

            pScene.AddLayer(pFeatureLayer as ILayer);

        }
      #region 创建几何字段

        /// <summary>
        /// 创建几何字段
        /// </summary>
        /// <param name="p_esriGeotype"></param>
        /// <returns></returns>
        public IFields CreateShapeFields(esriGeometryType p_esriGeotype)
        {

            IFields pFields = new FieldsClass();
            IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;

            IGeometryDef pGeoDef = new GeometryDefClass();
            IGeometryDefEdit pGeoDefEdit = pGeoDef as IGeometryDefEdit;
            pGeoDefEdit.GeometryType_2 = p_esriGeotype;
            pGeoDefEdit.SpatialReference_2 = (ISpatialReference) new UnknownCoordinateSystem();

            IField pFld = new FieldClass();
            IFieldEdit pFldEdit = pFld as IFieldEdit;
            pFldEdit.Name_2 = "shape";
            pFldEdit.IsNullable_2 = false;
            pFldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
            pFldEdit.GeometryDef_2 = pGeoDef;

            pFieldsEdit.AddField(pFld);

            return pFields;
        }

        #endregion
       
        #region 根据名称获取图层

        //根据名称获取图层
        public ILayer GetLayerByName(IScene scene , string strLayerName)
        {
            ILayer pLayer = null;
            for (int i = 0;i < scene.LayerCount;i++)
            {
                pLayer = scene.get_Layer(i);
                if (strLayerName == pLayer.Name)
                {
                    break;
                }
            }
            return pLayer;
        }
        #endregion

Contour函数说明参照帮助文档!

ArcEngine下TIN生成等高线,布布扣,bubuko.com

ArcEngine下TIN生成等高线

标签:3dgis   arcengine   scenecontrol   tin   等高线   

原文地址:http://blog.csdn.net/giser_whu/article/details/25750159

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!