1 理论基础与数据说明
1.1 要解决的问题及思路
对于点线矛盾的检查,精确的方法是建立不规则三角网;但是三角网的建立比较复杂,其质量的好坏直接决定检查结果的好坏
1.2 等高线的特性及数据成果介绍
基于上述分析,得出如下结论:
主要等高线的编码是以71开头的,因此在进行等高线点线矛盾检查时,要首先提取出TERL层中以71为开头的要素;
高程点层的GB码统一为720100
我们的数据检查要在这两个图层之间开展
2 由FeatureClass生成TIN
2.1 由点要素生成TIN代码
引文来源:ArcEngine由点生成TIN
根据高程点生成TIN的过程:
(1)根据高程点文件(Excel)生成点shapefile
(2)使用ITinEdit的AddFromFeatureClass方法生成TIN
2.1.1 数据说明
2.1.2 代码实现
#region 创建TIN private void button_ok_Click(object sender , EventArgs e) { try { strTinName=textBox_TINName.Text; outFolder=textBox_outpath.Text; if (strTinName=="") { MessageBox.Show("请输入TIN名称!"); } else if (outFolder=="") { MessageBox.Show("请选择TIN保存路径"); } else { //生成点shape Excel2Shape excel2shape = new Excel2Shape(textBox_point.Text); excel2shape.CreateShapeFromExcel(); //获取shapefile string path = excel2shape.path; string name = excel2shape.name; IWorkspaceFactory pWSFac = new ShapefileWorkspaceFactoryClass(); IFeatureWorkspace pFeatureWS = pWSFac.OpenFromFile(path , 0) as IFeatureWorkspace; IFeatureClass pFeatureClass = pFeatureWS.OpenFeatureClass(name); IField pField = pFeatureClass.Fields.get_Field(pFeatureClass.FindField("Z")); //创建TIN ITin pTin = Create_TIN(pFeatureClass , pField , outFolder); ITinLayer pTinlayer = new TinLayerClass(); pTinlayer.Dataset = pTin; pTinlayer.Name = strTinName; pSceneControl.SceneGraph.Scene.AddLayer(pTinlayer as ILayer , true); this.Close(); } } catch (System.Exception ex) { MessageBox.Show(ex.Message + "创建TIN失败!"); } } /// <summary> /// 创建TIN /// </summary> /// <param name="pFeatureClass">点要素类</param> /// <param name="pField">Z字段</param> /// <param name="pPath">路径</param> public ITin Create_TIN(IFeatureClass pFeatureClass , IField pField , string pPath) { IGeoDataset pGeoDataset = pFeatureClass as IGeoDataset; ITinEdit pTinEdit = new TinClass(); pTinEdit.InitNew(pGeoDataset.Extent); object pObj = Type.Missing; pTinEdit.AddFromFeatureClass(pFeatureClass , null , pField , null , esriTinSurfaceType.esriTinMassPoint , ref pObj); if (System.IO.File.Exists(pPath)) { _3DCampus.helper.FolderHelper.DeleteFolder(pPath); } pTinEdit.SaveAs(pPath , ref pObj); pTinEdit.Refresh(); return pTinEdit as ITin; } #endregion
2.2 TIN转Raster
未必能有,先放这里以供参考
public IRasterDataset tin2raster(string tempBathyTIN, string geoPath, string gridName) { string tinFolder = System.IO.Path.GetDirectoryName(tempBathyTIN); string tinName = System.IO.Path.GetFileName(tempBathyTIN); IRasterDataset rasterDataset = new RasterDatasetClass(); try { string rasterPath = System.IO.Path.GetDirectoryName(geoPath); IWorkspaceFactory TinWF = new TinWorkspaceFactory(); ITinWorkspace TinWK = TinWF.OpenFromFile(tinFolder, 0) as ITinWorkspace; ITinAdvanced2 tinAd = TinWK.OpenTin(tinName) as ITinAdvanced2; IEnvelope extent = tinAd.Extent; IPoint origin = extent.LowerLeft; origin.X = origin.X - (5 * 0.5); origin.Y = origin.Y - (5 * 0.5); int nCol = (int)Math.Round(extent.Width / 5) + 1; int nRow = (int)Math.Round(extent.Height / 5) + 1; ISpatialReference2 spatialRef = (ISpatialReference2)extent.SpatialReference; IWorkspaceFactory rasterWF = new RasterWorkspaceFactoryClass(); IRasterWorkspace2 workSpace = (IRasterWorkspace2)rasterWF.OpenFromFile(rasterPath, 0); rasterDataset = workSpace.CreateRasterDataset(gridName, "IMAGINE Image", origin, nCol, nRow, 5, 5, 1, ESRI.ArcGIS.Geodatabase.rstPixelType.PT_FLOAT, spatialRef, true); IRasterBandCollection bandColl = (IRasterBandCollection)rasterDataset; IRasterBand rasterBand = bandColl.Item(0); IRawPixels rawPixels = (IRawPixels)rasterBand; IPnt blockSize = new DblPntClass(); blockSize.X = nCol; blockSize.Y = nRow; IPixelBlock3 pixelBlock = (IPixelBlock3)rawPixels.CreatePixelBlock(blockSize); ITinSurface tinSurface = (ITinSurface)tinAd; IRasterProps rasterProps = (IRasterProps)rawPixels; object nodataFloat; //long nodataInt; object val = pixelBlock.get_PixelDataByRef(0); double cellsize = 5; origin.X = origin.X + (5 * 0.5); origin.Y = origin.Y + (5 * nRow) - (5 * 0.5); nodataFloat = Convert.ToSingle(rasterProps.NoDataValue.ToString()); tinSurface.QueryPixelBlock(origin.X, origin.Y, cellsize, cellsize, esriRasterizationType.esriElevationAsRaster, nodataFloat, val); IPnt offset = new DblPntClass(); offset.X = 0; offset.Y = 0; rawPixels.Write(offset, pixelBlock as IPixelBlock); } catch (Exception ex) { } return rasterDataset; }
2.3 读取TIN的代码
百度抄的,没有验证
/// <summary> /// 打开 TIN 文件 /// </summary> /// <param name="aFolderName">TIN文件夹 名</param> /// <param name="axMapControl">axMapControl(可已将其换为 Scene或 Globe 控件)</param> /// <returns></returns> public void OpenFile_TINFolder(string aFolderName, AxMapControl axMapControl) { string pathToWorkspace = System.IO.Path.GetDirectoryName(aFolderName); string tinName = System.IO.Path.GetFileName(aFolderName); IWorkspaceFactory pWorkspaceFactory = new TinWorkspaceFactoryClass(); IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(pathToWorkspace, 0); ITinWorkspace pTinWorkspace = pWorkspace as ITinWorkspace; ITinLayer pTinLayer = new TinLayerClass(); if (pTinWorkspace.get_IsTin(tinName)) { ITin pTin = pTinWorkspace.OpenTin(tinName); pTinLayer.Dataset = pTin; pTinLayer.ClearRenderers(); pTinLayer.Name = tinName; } axMapControl.AddLayer(pTinLayer); axMapControl.ActiveView.Refresh(); }
自己写的点线矛盾程序查看如下图公众号文章[ArcEngine等高线与高程点点线矛盾检查]