ArcEngine下一个TIN生成的轮廓

时间:2023-03-09 07:29:31
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功能说明参考帮助文档。

版权声明:本文博主原创文章,博客,未经同意,不得转载。