码迷,mamicode.com
首页 > 其他好文 > 详细

关于ArcGIS常用功能的实现

时间:2015-06-28 23:03:27      阅读:278      评论:0      收藏:0      [点我收藏+]

标签:

   关于ArcGIS中常见的一些功能的总结,一般首先在前台中放置地图,<esri:Map Grid.Row="0" Grid.Column="0" Grid.RowSpan="5" Grid.ColumnSpan="6"  x:Name="MyMap"  

WrapAround="True"  MouseClick="MyMap_MouseClick" ExtentChanged="MyMap_ExtentChanged" /> 放置了地图之后我们就可以进行相关的操作

  1  地图的放大与缩小:MyMap.Zoom(double param) 其中参数param>1,表示地图放大,例如param=2,表示放大到原来的两倍,param<1表示地图的缩小。

  2  地图范围发生变化时发生的事件,其中this.MyMap.Layers[0]表示图层  ArcGISLocalTiledLayer tpkLayer = new ArcGISLocalTiledLayer("GqyPgisData\\" +             

_ConfigInfo.TpkName + ".tpk"); MyMap.Layers.Add(tpkLayer);加载的是本地缓存地图图层,一般用作底图。

  当地图范围发生改变时,地图图层执行相应的改变。

  private void MyMap_ExtentChanged(object sender, ExtentEventArgs e)
        {
            ////需要判断是否已经有地图比例尺,有比例尺了表示定位完毕可以换算桌面坐标
           if (!_mapIntial)
            {
                Envelope env = this.MyMap.Layers[0].FullExtent;
                double x = (env.XMax + env.XMin) / 2.0;
                double y = (env.YMax + env.YMin) / 2.0;
                Envelope newEnv = new Envelope(x - env.Width / 16.0, y - env.Height / 16.0, x + env.Width / 16.0, y + env.Width / 16.0);
                this.MyMap.Extent = newEnv;

            }

        }

  3   测量折线距离

      下面直接贴出代码,并作出相应的解释。首先GeometryService 就是提供针对几何层级的服务,比如说Project,Simplify , Buffer,Areas And Lengths , Lengths 等,这个具体的解释请参考:http://help.arcgis.com/en/arcgisserver/10.0/apis/rest/geometryserver.html官方的解释。LocalGeometryService表示本地几何层级的服务。

      public void MapMeasureDistance()
        {
            //清除测量图层
            ClearMyGraphicsLayerMeasure();

            //设置测量信息区域可见
            gMapInfo.Visibility = Visibility.Visible;
            gMapInfo.lblInfo.Content = "请在地图中点击画折线,计算长度!";

            _GeometryServiceMeasure = new GeometryService();
             LocalGeometryService lgs = LocalGeometryService.GetService();
            _GeometryServiceMeasure.Url = lgs.UrlGeometryService;
            _GeometryServiceMeasure.LengthsCompleted += _GeometryServiceMeasure_LengthsCompleted;
            _GeometryServiceMeasure.Failed += _GeometryServiceMeasure_Failed;
            MyMap.IsEnabled = true;

            //实例化一个Draw对象,开始画图操作

            _DrawMeasure = new Draw(MyMap)
            {
                DrawMode = DrawMode.Polyline,
                IsEnabled = true,

                //这里是前台定义的资源,即画线的样式
                LineSymbol = Root.Resources["SelectLineSymbol"] as LineSymbol
            };

            _DrawMeasure.DrawBegin += _DrawMeasure_Begin;
            _DrawMeasure.DrawComplete += _DrawMeasure_MeasureLengthsComplete;
        }      

        /// <summary>
        /// 开始画
        /// </summary>
        void _DrawMeasure_Begin(object sender, EventArgs args)
        {
            //ClearMyGraphicsLayerMeasure();
        }

        /// <summary>
        /// 完成画长度
        /// </summary>
        void _DrawMeasure_MeasureLengthsComplete(object sender, DrawEventArgs args)
        {
            Polyline _Polyline = args.Geometry as Polyline;

            if (_Polyline.Paths[0].Count > 1)
            {
                XmlDocument xmlDoc = GISUDPClient.Instance.CreateXmlDocument("GQYPGIS.Xml.Action.ActionMeasureLine.xml");
                XmlNode xmlNode = xmlDoc.SelectSingleNode("Action/MapPoints");

                //发送直线测量图形命令(点选)
                foreach (MapPoint mp in _Polyline.Paths[0])
                {

                    XmlElement xmlElement = xmlDoc.CreateElement("MapPoint");
                    XmlAttribute xmlAttr = xmlDoc.CreateAttribute("X");
                    xmlAttr.Value = mp.X.ToString();
                    xmlElement.Attributes.Append(xmlAttr);
                    xmlAttr = xmlDoc.CreateAttribute("Y");
                    xmlAttr.Value = mp.Y.ToString();
                    xmlElement.Attributes.Append(xmlAttr);

                    xmlNode.AppendChild(xmlElement);

                }
                GISUDPClient.Instance.SendTo(xmlDoc);
            }

            _Polyline.SpatialReference = MyMap.SpatialReference;

            Graphic _Graphic = new Graphic()
            {
                Symbol = Root.Resources["CompleteLineSymbol"] as Symbol,
                Geometry = _Polyline
            };

            GraphicsLayer _GraphicsLayer = MyMap.Layers["MyGraphicsLayerMeasure"] as GraphicsLayer;
            _GraphicsLayer.Graphics.Add(_Graphic);

            //开始计算长度
            _GeometryServiceMeasure.LengthsAsync(_GraphicsLayer.Graphics, LinearUnit.Kilometer, CalculationType.Geodesic, null);

            _DrawMeasure.DrawMode = DrawMode.None;
         }

    4   /// <summary>
        /// 完成画长度
        /// </summary>
        void _DrawMeasure_MeasureLengthsComplete(object sender, DrawEventArgs args)
        {
            Polyline _Polyline = args.Geometry as Polyline;

            if (_Polyline.Paths[0].Count > 1)
            {
                XmlDocument xmlDoc = GISUDPClient.Instance.CreateXmlDocument("GQYPGIS.Xml.Action.ActionMeasureLine.xml");
                XmlNode xmlNode = xmlDoc.SelectSingleNode("Action/MapPoints");

                //发送直线测量图形命令(点选)
                foreach (MapPoint mp in _Polyline.Paths[0])
                {

                    XmlElement xmlElement = xmlDoc.CreateElement("MapPoint");
                    XmlAttribute xmlAttr = xmlDoc.CreateAttribute("X");
                    xmlAttr.Value = mp.X.ToString();
                    xmlElement.Attributes.Append(xmlAttr);


                    xmlAttr = xmlDoc.CreateAttribute("Y");
                    xmlAttr.Value = mp.Y.ToString();
                    xmlElement.Attributes.Append(xmlAttr);

                    xmlNode.AppendChild(xmlElement);

                }
                GISUDPClient.Instance.SendTo(xmlDoc);
            }

            _Polyline.SpatialReference = MyMap.SpatialReference;

            Graphic _Graphic = new Graphic()
            {
                Symbol = Root.Resources["CompleteLineSymbol"] as Symbol,
                Geometry = _Polyline
            };

            GraphicsLayer _GraphicsLayer = MyMap.Layers["MyGraphicsLayerMeasure"] as GraphicsLayer;
            _GraphicsLayer.Graphics.Add(_Graphic);

            //开始计算长度
            _GeometryServiceMeasure.LengthsAsync(_GraphicsLayer.Graphics, LinearUnit.Kilometer, CalculationType.Geodesic, null);

            _DrawMeasure.DrawMode = DrawMode.None;
        }

       
   5   几何服务长度计算完成      
        void _GeometryServiceMeasure_LengthsCompleted(object sender, LengthsEventArgs args)
        {
            gMapInfo.lblInfo.Content = String.Format("折线的长度:{0} 公里", Math.Round(args.Results[0], 3));
        }

        /// <summary>
        /// 几何服务计算周长面积完成
        /// </summary>
        void _GeometryServiceMeasure_AreasAndLengthsCompleted(object sender, AreasAndLengthsEventArgs args)
        {
            double kms = args.Results.Lengths[0] * 0.001;
            double sqkm = Math.Abs(args.Results.Areas[0]) * 0.001 * 0.001;
            //double kms = args.Results.Lengths[0] * 100;
            //double miles = args.Results.Lengths[0] * 0.0006213700922;
            //double sqkm = Math.Abs(args.Results.Areas[0]) * 10000;
            //double sqmi = Math.Abs(args.Results.Areas[0]) * 0.0000003861003;
            gMapInfo.lblInfo.Content = String.Format("多边形周长: {1} 公里\r\n多边形面积: {0} 平方公里", Math.Round(sqkm, 3), Math.Round(kms, 3));
        }

        ///<summary>  
        /// 几何服务失败
        ///</summary>
        void _GeometryServiceMeasure_Failed(object sender, TaskFailedEventArgs e)
        {
            //throw new NotImplementedException();
        }

 

   

关于ArcGIS常用功能的实现

标签:

原文地址:http://www.cnblogs.com/seekdream/p/4606238.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!