首页 > 代码库 > ArcEngine下TIN生成等高线
ArcEngine下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函数说明参照帮助文档!
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。