cl991036
管理员
管理员
  • 注册日期2003-07-25
  • 发帖数5917
  • QQ14265545
  • 铜币29669枚
  • 威望217点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • GIS帝国铁杆
阅读:1353回复:0

arcgis server(.net)中距离量算和面积量算code

楼主#
更多 发布于:2008-10-16 22:28
<P>看了esri自带的例子中量算面积和距离的代码,比较复杂,我实现了一种比较土的方法,适合新手使用的,其实arcgis server中的量算都是用最基本的点坐标实现的,基本原理就是获得客户端的点坐标后转化为地理坐标,而后再算长度和面积,计算过程就是数学中的解析几何的问题了,用到的是向量那部分的内容</P>
<P>我的代码要先在前台的toolbar中加入两个tool,分别量算面积和长度,显然ClientAction属性必须一个是polyline,另一个是ploygon<BR>因为我的地图的地理坐标是m,就没有对坐标进行转化,如果是度的话要转化一下,esri自带的例子有转化的函数,这里有详细分析量算代码的</P>
<P><BR>量算距离的:</P>
<P><BR> 1    Public Sub ServerAction()Sub ServerAction(ByVal ToolArgs As ToolEventArgs) Implements IMapServerToolAction.ServerAction<BR> 2<BR> 3        Dim MapControl As Map = Nothing<BR> 4        MapControl = DirectCast(ToolArgs.Control, Map)<BR> 5<BR> 6        ' 强制类型转换<BR> 7        Dim MyPolylineArg As PolylineEventArgs = CType(ToolArgs, PolylineEventArgs)<BR> 8        Dim screen_points As System.Drawing.Point() = MyPolylineArg.Vectors<BR> 9<BR>10        Dim X1 As Double<BR>11        Dim Y1 As Double<BR>12        Dim X2 As Double<BR>13        Dim Y2 As Double<BR>14        Dim AllDis As Double = 0.0<BR>15        Dim TempDis As Double = 0.0<BR>16        Dim XD As Double = 0.0<BR>17        Dim YD As Double = 0.0<BR>18<BR>19        Dim i As Integer<BR>20        For i = 0 To screen_points.Length - 1<BR>21<BR>22            If i > 0 Then<BR>23                'second point is start<BR>24                Dim mappnt2 As ESRI.ArcGIS.ADF.Web.Geometry.Point = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screen_points(i), MapControl.Extent, CInt(MapControl.Width.Value), CInt(MapControl.Height.Value))<BR>25                X2 = mappnt2.X<BR>26                Y2 = mappnt2.Y<BR>27                '计算与上个x1y1之间的距离<BR>28                XD = Math.Abs(X1 - X2)<BR>29                YD = Math.Abs(Y1 - Y2)<BR>30                '计算2个坐标之间的距离<BR>31                TempDis = Math.Sqrt(Math.Pow(XD, 2) + Math.Pow(YD, 2))<BR>32                AllDis += TempDis<BR>33<BR>34            End If<BR>35<BR>36            Dim mappnt As ESRI.ArcGIS.ADF.Web.Geometry.Point = _<BR>37            ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screen_points(i), MapControl.Extent, _<BR>38            CInt(MapControl.Width.Value), CInt(MapControl.Height.Value))<BR>39            X1 = mappnt.X<BR>40            Y1 = mappnt.Y<BR>41<BR>42        Next<BR>43        '得到距离 AllDis<BR>44        AllDis = Math.Round(AllDis, 2)<BR>45        'Dim MyPage As System.Web.UI.Page = CType(System.Web.HttpContext.Current.Handler, System.Web.UI.Page)<BR>46        'Dim cs As ClientScriptManager = MyPage.ClientScript<BR>47<BR>48        'If Not cs.IsStartupScriptRegistered(Me.GetType(), "Measure_Distance") Then<BR>49<BR>50        '    Dim cstext1 As String = "alert('" + AllDis.ToString() + "');"<BR>51        '    cs.RegisterStartupScript(Me.GetType(), "Measure_Distance", cstext1, True)<BR>52        'End If<BR>53<BR>54        Dim jstext As String<BR>55        jstext = "alert('总计:" + AllDis.ToString() + "米');"<BR>56        Dim cr_lei As New CallbackResult(Nothing, Nothing, "javascript", jstext)<BR>57        MapControl.CallbackResults.Add(cr_lei)<BR>58      <BR>59<BR>60    End Sub</P>

<P><BR> 量算面积的:</P>

<P> 1 Public Sub ServerAction()Sub ServerAction(ByVal ToolArgs As ToolEventArgs) Implements IMapServerToolAction.ServerAction<BR> 2<BR> 3        Dim MapControl As Map = Nothing<BR> 4        MapControl = DirectCast(ToolArgs.Control, Map)<BR> 5<BR> 6<BR> 7        Dim MyPolygonArgs As PolygonEventArgs = CType(ToolArgs, PolygonEventArgs)<BR> 8<BR> 9        '多边形的顶点<BR>10        Dim PointArray As System.Drawing.Point() = MyPolygonArgs.Vectors<BR>11        Dim X1 As Double<BR>12        Dim Y1 As Double<BR>13        Dim X2 As Double<BR>14        Dim Y2 As Double<BR>15        Dim AllArea As Double = 0.0<BR>16        Dim TempArea As Double = 0.0<BR>17        Dim XD As Double = 0.0<BR>18        Dim YD As Double = 0.0<BR>19<BR>20        Dim i As Integer<BR>21        Dim Point2 As ESRI.ArcGIS.ADF.Web.Geometry.Point = New ESRI.ArcGIS.ADF.Web.Geometry.Point()<BR>22        Dim Point1 As ESRI.ArcGIS.ADF.Web.Geometry.Point = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(PointArray(0), MapControl.Extent, CInt(MapControl.Width.Value), CInt(MapControl.Height.Value))<BR>23        X1 = Point1.X<BR>24        Y1 = Point1.Y<BR>25<BR>26        For i = 1 To PointArray.Length - 1<BR>27<BR>28<BR>29            'second point is start<BR>30            Point2 = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(PointArray(i), MapControl.Extent, CInt(MapControl.Width.Value), CInt(MapControl.Height.Value))<BR>31            X2 = Point2.X<BR>32            Y2 = Point2.Y<BR>33<BR>34            '开始计算了<BR>35            XD = X2 - X1<BR>36            YD = Y2 - Y1<BR>37            TempArea = X1 * YD - Y1 * XD<BR>38            AllArea += TempArea<BR>39            '------------------------------------------------------------------------------<BR>40            Point1 = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(PointArray(i), MapControl.Extent, CInt(MapControl.Width.Value), CInt(MapControl.Height.Value))<BR>41            X1 = Point1.X<BR>42            Y1 = Point1.Y<BR>43<BR>44        Next<BR>45        AllArea = Math.Abs(AllArea) / 2<BR>46        AllArea = Math.Round(AllArea, 2)<BR>47<BR>48<BR>49        Dim jstext As String<BR>50        jstext = "alert('总计:" + AllArea.ToString() + "平方米');"<BR>51        Dim cr_lei As New CallbackResult(Nothing, Nothing, "javascript", jstext)<BR>52        MapControl.CallbackResults.Add(cr_lei)<BR>53<BR>54    End Sub</P>
喜欢0 评分0
没钱又丑,农村户口。头可断,发型一定不能乱。 邮箱:gisempire@qq.com
游客

返回顶部