项目中碰到要处理TIN数据地面高程问题,于是开发了个小工具,主要用AE的ITinLayer接口,实现获取任意坐标点的高程值,进一步扩展实用功能,如下:
鼠标点击获取高程值,根据TIN数据批量处理原始数据模板中的高程值,批量更新SDE 中管线数据地面高程,达到快速更新现状数据目的,客户反映满意。
主要实现如下:
1
Private
Sub Button1_Click()
Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
2 If Me.FolderBrowserDialog1.ShowDialog = DialogResult.OK Then
3 If Me.FolderBrowserDialog1.SelectedPath <> "" Then
4 Try
5 Dim Path As String = Me.FolderBrowserDialog1.SelectedPath
6 Dim FatherFolder, Folder As String
7 Dim pTinWorkspaceFactory As IWorkspaceFactory
8 Dim pTinWorkspace As ITinWorkspace
9
10 pTinWorkspaceFactory = New TinWorkspaceFactoryClass
11 FatherFolder = Path.Substring(0, Path.LastIndexOf("\"c) + 1)
12 pTinWorkspace = pTinWorkspaceFactory.OpenFromFile(FatherFolder, 0)
13
14 pTinLayer = New TinLayerClass
15 Dim pTin As ITin = New TinClass
16
17 Folder = Path.Substring(Path.LastIndexOf("\"c))
18 pTin = pTinWorkspace.OpenTin(Folder)
19 pTinLayer.Dataset = pTin
20 Me.AxMapControl1.Map.ClearLayers()
21 Me.AxMapControl1.Map.AddLayer(pTinLayer)
22 Catch ex As Exception
23 MessageBox.Show("打开TIN数据出现错误!" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Information)
24 End Try
25 End If
26 End If
27 End Sub
1
Private
Function ShowZ()
Function ShowZ(ByVal x As Double, ByVal y As Double, Optional ByVal OnlyReturn As Boolean = False) As String
2 Try
3 If Me.AxMapControl1.Map.LayerCount = 0 Then
4 MessageBox.Show("TIN数据未加载", "注意", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
5 Exit Function
6 End If
7 Dim pTinLayer As ITinLayer
8 Dim pFuncSurf As IFunctionalSurface
9 pTinLayer = Me.AxMapControl1.Map.Layer(0)
10 If pTinLayer Is Nothing Then
11 MessageBox.Show("TIN数据未加载", "注意", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
12 Exit Function
13 End If
14 pFuncSurf = pTinLayer.Dataset
15 Dim z As Double
16 z = pFuncSurf.Z(x, y)
17
18 If OnlyReturn = True Then
19 Return String2String(z.ToString())
20 End If
21
22 If z.ToString() = "非数字" Then
23 MessageBox.Show("坐标超出范围!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information)
24 Else
25 MessageBox.Show("该点高程值:" + String2String(z.ToString()), "", MessageBoxButtons.OK, MessageBoxIcon.Information)
26 End If
27 Catch ex As Exception
28 MessageBox.Show("出现异常 " + ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Information)
29 End Try
30 End Function
为了后期扩展,动态加载MDB结构处理Dll,定义处理接口如下:
1
Public
Interface InterfaceDoMDB
Interface InterfaceDoMDB
2 Function GetTableName()Function GetTableName() As String()
3 Function GetTableKey()Function GetTableKey(ByVal TableName As String) As TableKey
4End Interface
5
6
Public
Structure TableKey
Structure TableKey
7 Public TableName As String
8 Public X_FieldName As String
9 Public Y_FieldName As String
10 Public LevelFieldName As String
11End Structure
效果图如下: