当前位置:甜馍馍地理信息网 >> 地理信息系统GIS >> 算法与数据结构 >> 正文 >>  [阅读资讯:如何把鼠标坐标转换为大地经纬度坐标代码]

如何把鼠标坐标转换为大地经纬度坐标代码

[ 来源:互联网 | 时间:2007年12月08日 | 收藏本文 ] 【

对于一款绘图软件或系统,无论如何都免不了鼠标位置坐标的处理,但是鼠标的位置坐标并不能直接用在地理系统里的大地经纬度坐标,因为他们的坐标系结构不一样。所以往往需要互相转化。那么本文就结合实际例子谈谈如何把鼠标坐标转化为大地经纬度坐标的方法并列举出用到的函数代码。

'运行此行程以前请将当前的地图属性下""Units""中的""display""设为用度分秒显示
Private Sub 实验按钮_MouseDown(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long)
Dim pDoc As IMxDocument
Dim I As Integer
Dim sLong As String '经度的字符串
Dim sLati As String '纬度的字符串
Dim iDD As Integer '度的符号所在位置
Dim iMM As Integer '分的符号所在的位置
Dim iSS As Integer '秒的符号所在的位置
Const sD = ""°""
Const sM = ""'""
Const sS = """"""""
Dim sStr As String
Dim iLongDegree As Integer '经度的度
Dim iLongMinute As Integer '经度的分
Dim dlongSecond As Double '经度的秒
Dim iLatitDegree As Integer '纬度的度
Dim iLatitMinute As Integer '纬度的分
Dim dLatitSecond As Double '纬度的秒


Set pDoc = ThisDocument
'设置前显示的坐标为经纬度坐标
Dim pScreenDisplay As IScreenDisplay
Set pScreenDisplay = pDoc.ActivatedView.ScreenDisplay
pDoc.ActiveView.Refresh
'With pScreenDisplay
' .StartDrawing pScreenDisplay.hdc, esriNoScreenCache
'.SetSymbol pLineSymbol
'.DrawPolyline pPolyLine
' .FinishDrawing
'End With
sStr = ThisDocument.Parent.StatusBar.Message(2)


'将经度与纬度分开
I = InStr(1, sStr, Space(1), vbTextCompare)
sLati = Right(sStr, I - 1)
sLong = Left(sStr, Len(sStr) - I)

'求纬度的DDMMSS
iDD = InStr(1, sLati, sD, vbTextCompare)
iMM = InStr(1, sLati, sM, vbTextCompare)
iSS = InStr(1, sLati, sS, vbTextCompare)
'MsgBox Right(sLong, 2)
iLatitDegree = Val(Left(sLati, (iDD - 1)))
iLatitMinute = Val(Mid(sLati, iDD + 1, 2))
dLatitSecond = Val(Mid(sLati, iMM + 1, (iSS - iMM - 1)))
MsgBox ""ilatitdegree="" & iLatitDegree & vbCrLf & ""ilatitminute="" & iLatitMinute & vbCrLf & ""ilatitsecond="" & dLatitSecond, vbCritical, """"

'求经度的DDMMSS
iDD = InStr(1, sLong, sD, vbTextCompare)
iMM = InStr(1, sLong, sM, vbTextCompare)
iSS = InStr(1, sLong, sS, vbTextCompare)
'MsgBox Right(sLong, 2)
iLongDegree = Val(Left(sLong, (iDD - 1)))
iLongMinute = Val(Mid(sLong, iDD + 1, 2))
dlongSecond = Val(Mid(sLong, iMM + 1, (iSS - iMM - 1)))
MsgBox ""ilongdegree="" & iLongDegree & vbCrLf & ""ilongminute="" & iLongMinute & vbCrLf & ""ilongsecond="" & dlongSecond, vbCritical, """"

End Sub"

 

【推荐本文】 【打印本页】 【返回顶部
最新文章
推荐文章