基于ArcEngine由散点生成featureclass,再生成tin
2015-12-10 11:05
393 查看
private void tinUDX2TinToolStripMenuItem_Click(object sender, EventArgs e) { //1、提取散点 //2、先由散点创建FeatureClass //3、由FeatureClass创建TIN IFeatureClass pFeatureClass = GetFeatureCLass(@"D:\Xge.UDX.ExchangeProjection\DATA\TinTest.xml"); IField pField = pFeatureClass.Fields.get_Field(pFeatureClass.FindField("elevation")); ITin pTin = CreateTin(pFeatureClass, pField, @"D:\Xge.UDX.ExchangeProjection\DATA\TinFromUDX"); ITinLayer pTinLayer = new TinLayerClass(); pTinLayer.Dataset = pTin; axMapControl1.Map.AddLayer(pTinLayer as ILayer); } //获取散点,生成FeatureClass public static IFeatureClass GetFeatureCLass(string UDXpath) { IWorkspaceFactory pWorkspaceFactory = new InMemoryWorkspaceFactoryClass(); IWorkspaceName pWorkspaceName = pWorkspaceFactory.Create("", "pWorkspace", null, 0); IName pName = (IName)pWorkspaceName; IWorkspace pWorkspace = (IWorkspace)pName.Open(); IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace; IFields pFields = new FieldsClass(); IFieldsEdit pFieldsEdit = pFields as IFieldsEdit; IField pField = new FieldClass(); IFieldEdit pFieldEdit = pField as IFieldEdit; pFieldEdit.Name_2 = "SHAPE"; pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; IGeometryDef pGeometryDef = new GeometryDefClass(); IGeometryDefEdit pGeometryDefEdit = pGeometryDef as IGeometryDefEdit; pGeometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint; //为FeatureClass赋参考系,不写会出错*************************************** ISpatialReferenceFactory pSpatialReferenceFactory = new SpatialReferenceEnvironmentClass(); ISpatialReference pSpatialReference = pSpatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984); pGeometryDefEdit.SpatialReference_2 = pSpatialReference; //************************************************************************ pFieldEdit.GeometryDef_2 = pGeometryDef; pFieldsEdit.AddField(pField); pField = new FieldClass();//不要省略写!容易出问题 pFieldEdit = pField as IFieldEdit; pFieldEdit.AliasName_2 = "高程"; pFieldEdit.Name_2 = "elevation"; pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble; pFieldsEdit.AddField(pField); IFeatureClass pFeatureClass = pFeatureWorkspace.CreateFeatureClass("TIN", pFields, null, null, esriFeatureType.esriFTSimple, "Shape", ""); //从UDX中获取散点值 Dictionary<int, IPoint> pointDictionary = new Dictionary<int, IPoint>(); WriteIn wi = new WriteIn(UDXpath, "TIN"); DTDataset sourceDT = wi.GetUDXFormXML(wi.filePath, wi.DTDatasetName); List<DTNode> vertexList = new List<DTNode>(); vertexList.AddRange(SelectNodeClass.SelectNodes(sourceDT, "Vertex")); for (int i = 0; i < vertexList.Count;i++ ) { IPoint pPoint=new PointClass(); pPoint.X = double.Parse(vertexList[i].Kernel.Value.ToString().Split(',')[0]); pPoint.Y = double.Parse(vertexList[i].Kernel.Value.ToString().Split(',')[1]); pPoint.Z = double.Parse(vertexList[i].Kernel.Value.ToString().Split(',')[2]); if (pPoint.Z.ToString() != "非数字") { pointDictionary.Add(i, pPoint); } } //插入到新建的FeatureClass中 IWorkspaceEdit pWorkspaceEdit = pWorkspace as IWorkspaceEdit; pWorkspaceEdit.StartEditing(true); pWorkspaceEdit.StartEditOperation(); IFeatureBuffer pFeatureBuffer = pFeatureClass.CreateFeatureBuffer(); IFeatureCursor pFeatureCursor = pFeatureClass.Insert(true); for (int featureNum = 4; featureNum < pointDictionary.Count;featureNum++ ) { pFeatureBuffer.Shape = pointDictionary[featureNum] as IPoint;//出错点,在于新建字段的错误 pFeatureBuffer.set_Value(pFeatureClass.Fields.FindField("elevation"), pointDictionary[featureNum].Z); pFeatureCursor.InsertFeature(pFeatureBuffer); } pFeatureCursor.Flush(); pWorkspaceEdit.StopEditOperation(); pWorkspaceEdit.StopEditing(true); return pFeatureClass; } public ITin CreateTin(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); pTinEdit.SaveAs(pPath, ref pObj); pTinEdit.Refresh(); return pTinEdit as ITin; }出处:http://www.cnblogs.com/zhuyuchen/archive/2013/01/14/2860475.html 原作者:小猪同学好东西大家可以很好借鉴,谢谢原作者的分享.
相关文章推荐
- 不让浏览器缓存js
- 10款基于HTML5+CSS3实现的超酷源码动画
- echarts 初始(一)
- controllers.js以及scope介绍
- 区别:DOM Core 与 HTML-DOM
- js 升幂降幂排序数组
- JSON序列化与反序列化一个字典
- 一些导航菜单样式设置的方法
- 详解JavaScript基于面向对象之创建对象(1)
- js 数组取出最大值最小值的2种方法
- HTML DOM Table 对象
- html DOM操作表格及样式
- 【实战Java高并发程序设计 3】带有时间戳的对象引用:AtomicStampedReference
- 前端知识体系
- HTML DOM - 修改 HTML 内容
- Jquery+json
- HTML DOM - 元素
- AngularJs实现ng1.3+表单验证
- [leetcode] 237. Delete Node in a Linked List
- HTML的16个全局属性