10楼#
发布于:2004-05-25 08:58
嘿嘿,我知道了!
我用mcMap.TrackLine.Length获取的长度的单位是:Decimal Degrees,然后利用两个常量换算成Meters: Const INCH2METERS = 39.37 Const INCH2DEGREES = 4322893.46 这样就和ArcMap里测量得到的数值是一样的了!反而写的那些转换投影什么的搞复杂了!呵呵 <P>是在ESRI英文support网站中找到的提示,大家有时间也可以多去那里看看!</P><img src="images/post/smile/dvbbs/em03.gif" /><img src="images/post/smile/dvbbs/em07.gif" /> |
|
|
11楼#
发布于:2004-05-25 10:14
<P>恭喜,那里高手如过江之鲫</P>
|
|
|
12楼#
发布于:2004-05-25 12:09
不错。又学一着。<img src="images/post/smile/dvbbs/em02.gif" />
|
|
|
13楼#
发布于:2004-05-25 15:02
<img src="images/post/smile/dvbbs/em03.gif" />
|
|
|
14楼#
发布于:2004-11-10 16:56
<img src="images/post/smile/dvbbs/em05.gif" />
|
|
15楼#
发布于:2004-11-12 12:15
<P>'----------------测量距离时用到的三个事件-----------------------------
'----------------开始------------------------------------------------- Public Sub mapDistanceMouseDown(map As MapControl, x As Long, y As Long) If Not m_pPoint Is Nothing Then totalDistanceValue = 0 Set pFirstPoint = m_pPoint End If Set m_pPoint = map.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y) If pFeedbackLn Is Nothing Then Set pFeedbackLn = New NewLineFeedback Set pFeedbackLn.Display = map.ActiveView.ScreenDisplay 'pFeedbackLn.Constraint = esriLineConstraintsHorizontal pFeedbackLn.Start m_pPoint Else pFeedbackLn.addPoint m_pPoint End If If pFirstPoint Is Nothing Then totalDistanceValue = 0 Else totalDistanceValue = totalDistanceValue + map.ActiveView.FocusMap.ComputeDistance(pFirstPoint, m_pPoint) frmMain.ActiveBar.Bands("statusbar").Tools("lengthInfo").Caption = Str(Round(totalDistanceValue, 3)) End If End Sub</P><P>Public Sub mapDistanceMouseMove(map As MapControl, x As Long, y As Long) If Not pFeedbackLn Is Nothing Then Set pSecondPoint = map.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y) pFeedbackLn.MoveTo pSecondPoint currentDistanceValue = map.ActiveView.FocusMap.ComputeDistance(pSecondPoint, m_pPoint) frmMain.ActiveBar.Bands("statusbar").Tools("lengthInfo").Caption = "当前长度: " ; Str(Round(map.ActiveView.FocusMap.ComputeDistance(pSecondPoint, m_pPoint), 3)) ; " 总长度:" ; Str(Round(totalDistanceValue + currentDistanceValue, 3)) End If End Sub</P><P>Public Sub mapDistanceDoubleClick() If Not pFeedbackLn Is Nothing Then If Not pFirstPoint Is Nothing Then Dim pPolyLine As IPolyline Set pPolyLine = pFeedbackLn.Stop Dim totalLength As Double totalLength = pPolyLine.Length frmMain.ActiveBar.Bands("statusbar").Tools("lengthInfo").Caption = "测量总长度为: " ; Str(Round(totalLength, 3)) Else pFeedbackLn.Stop frmMain.ActiveBar.Bands("statusbar").Tools("lengthInfo").Caption = "测量总长度为: " End If Set pFeedbackLn = Nothing Set m_pPoint = Nothing Set pFirstPoint = Nothing Set pSecondPoint = Nothing totalDistanceValue = 0 End If End Sub '----------------------结束-------------------------- '----------------------------------------------------</P><P> '----------------------测量面积的三个事件---------------------------- '----------------------------开始------------------------------------ Public Sub mapAreaMouseDown(map As MapControl, x As Long, y As Long) If Not bIsMouseDown Then Set ptCollection = New Collection End If bIsMouseDown = True Set m_pPoint = map.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y) If ptCollection.Count > 0 Then ptCollection.Remove ptCollection.Count '////删除鼠标移动过程中的多余点 End If ptCollection.Add m_pPoint If pFeedbackPoly Is Nothing Then Set pFeedbackPoly = New NewPolygonFeedback Set pFeedbackPoly.Display = map.ActiveView.ScreenDisplay pFeedbackPoly.Start m_pPoint Else pFeedbackPoly.addPoint m_pPoint End If ptCollection.Add m_pPoint If ptCollection.Count >= 3 Then frmMain.ActiveBar.Bands("statusbar").Tools("lengthInfo").Caption = "测量面积为: " ; Str(Round(CalArea(ptCollection), 2)) Else frmMain.ActiveBar.Bands("statusbar").Tools("lengthInfo").Caption = "至少还需要三个点才可计算面积!" End If 'frmMain.ActiveBar.Bands("statusbar").Tools("companyInfo").Caption = ptCollection.Count End Sub Public Sub mapAreaMouseMove(map As MapControl, x As Long, y As Long) Set ptDisArea = map.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y) With frmMain.ActiveBar.Bands("statusbar").Tools("lengthInfo") If Not pFeedbackPoly Is Nothing Then ptCollection.Add ptDisArea '////放入计算出的面积代码 Select Case ptCollection.Count Case 1 .Caption = "至少还需要两个点才可计算面积!" Case 2 .Caption = "至少还需要一个点才可计算面积!" Case Else .Caption = "测量面积为: " ; Str(Round(CalArea(ptCollection), 2)) End Select ptCollection.Remove ptCollection.Count '////删除鼠标移动过程中的多余点 pFeedbackPoly.MoveTo ptDisArea 'frmMain.ActiveBar.Bands("statusbar").Tools("companyInfo").Caption = ptCollection.Count End If End With End Sub</P><P>Public Sub mapAreaDbl(map As MapControl) If Not pFeedbackPoly Is Nothing Then pFeedbackPoly.Stop End If If ptCollection.Count > 0 Then ptCollection.Remove ptCollection.Count '////删除鼠标移动过程中的多余点 End If Set pFeedbackPoly = Nothing bIsMouseDown = False Set ptCollection = Nothing Set ptDisArea = Nothing Set ptAreaFirst = Nothing Set m_pPoint = Nothing End Sub Private Function CalArea(col As Collection) As Double 'If col.Count < 3 Then Exit Function Dim j As Long j = 2 Dim k As Long k = 3 Dim i As Long i = 1 Dim firstPoint As IPoint Dim secondPoint As IPoint Dim thirdPoint As IPoint Set firstPoint = col.Item(1) CalArea = 0 For i = 2 To col.Count - 1 Set secondPoint = col.Item(i) Set thirdPoint = col.Item(i + 1) CalArea = CalArea + Abs((firstPoint.x * secondPoint.y + secondPoint.x * thirdPoint.y + thirdPoint.x * firstPoint.y - firstPoint.x * thirdPoint.y - secondPoint.x * firstPoint.y - thirdPoint.x * secondPoint.y) / 2) Next Set firstPoint = Nothing Set secondPoint = Nothing Set thirdPoint = Nothing End Function</P><P>'----------------------------------面积量算结束----------------------------------- '如果是多边形(凹凸均可)可以直接用叉积公式算出! '求一个逆时针给出顶点的三角形面积? '设顶点(x1,y1),(x2,y2),(x3,y3) 'S = (x1y2 + x2y3 + x3y1 - x1y3 - x2y1 - x3y2) / 2 '可以把一个凸多边形划分成许多互相不重叠的三角形,依次求出面积,再求和。 '但是凹多边形呢? '注意:S大小可能为负!这点很重要。 '我们可以发现,在凹多边形中,按照原来的求法(最后再取绝对值)结果仍然是对的! '反正先将点逆时针排序,然后确定一个顶点,依次按顺序枚举另外的两个点,对每次结果进行求和,最后取平均值。 '如上图,依次算ABC,ACD,ADE,AEF求和后取绝对值(点顺序算反影响结果)。</P> |
|
|
16楼#
发布于:2004-11-12 12:17
以上是我计算面积和距离的代码,仅供参考,有什么问题提出来互相讨论
|
|
|
上一页
下一页