silverlight   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了西南大学校园GIS平台大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

     系统架构是B/S,开发语言是C#、silverlight,开发平台是.NET,数据库为sqlserver,这是我读研究生时候自己做的作品,以自己的母校为地图,进行GIS相关的功能分析,核心的模块有:空间查询、GPS定位模拟、搜索模块、统计分析;其中说的不足之处,望各位指点出来。      一、空间查询           整体思路:空间查询是用户在地图上框选一定范围,然后根据框选范围Ge

     系统架构是B/S,开发语言是C#、silverlight,开发平台是.NET,数据库sqlserver,这是我读研究生时候自己做的作品,以自己的母校为地图,进行GIS相关的功能分析,核心的模块有:空间查询、GPS定位模拟、搜索模块、统计分析;其中说的不足之处,望各位指点出来。

     一、空间查询     

西南大学校园GIS平台

     整体思路:空间查询用户在地图上框选一定范围,然后根据框选范围Geometry来进行query查询。框选利用Draw工具有多边形、矩形、圆线等方式。实现方式,前台界面设计:

                <!--Toolbar工具栏-->
                <Grid x:Name="ToolbarGrid" HorizontalAlignment="Left"  VerticalAlignment="Top"  Width="600" Height="0" RenderTransformOrigin="0.5,0.5">
                        <Grid.RenderTransform>
                            <ScaleTransform x:Name="ToolbarGridScaleTransform" ScaleX="0" ScaleY="0" />
                        </Grid.RenderTransform>
                        <StackPanel Orientation="Vertical">
                        <esriToolkit:Toolbar x:Name="myToolbar" MaxItemHeight="40" MaxItemWidth="40"
                           VerticalAlignment="Top" HorizontalAlignment="Left"
                           Loaded="myToolbar_Loaded"
                           ToolbarItemClicked="myToolbar_ToolbarItemClicked"
                           ToolbarIndexChanged="myToolbar_ToolbarIndexChanged"
                           Width="600" Height="40">
                            <esriToolkit:Toolbar.Items>
                                <esriToolkit:ToolbarItemCollection>
                                    <!--Zoom in-->
                                    <esriToolkit:ToolbarItem Text="放大">
                                        <esriToolkit:ToolbarItem.Content>
                                            <Image source="Images/i_zoomin.png" Stretch="UniformToFill" Margin="3" />
                                        </esriToolkit:ToolbarItem.Content>
                                    </esriToolkit:ToolbarItem>
                                    <!--Zoom out-->
                                    <esriToolkit:ToolbarItem Text="缩小">
                                        <esriToolkit:ToolbarItem.Content>
                                            <Image source="Images/i_zoomout.png" Stretch="UniformToFill" Margin="3" />
                                        </esriToolkit:ToolbarItem.Content>
                                    </esriToolkit:ToolbarItem>
                                    <!--PolygonQuery-->
                                    <esriToolkit:ToolbarItem Text="多边形查询">
                                        <esriToolkit:ToolbarItem.Content>
                                            <Image source="Images/DrawPolygon.png" Stretch="UniformToFill" Margin="5"/>
                                        </esriToolkit:ToolbarItem.Content>
                                    </esriToolkit:ToolbarItem>
                                    <!--Polyline-->
                                    <esriToolkit:ToolbarItem Text="线查询">
                                        <esriToolkit:ToolbarItem.Content>
                                            <Image source="Images/DrawPolyline.png" Stretch="UniformToFill" Margin="5"/>
                                        </esriToolkit:ToolbarItem.Content>
                                    </esriToolkit:ToolbarItem>
                                    <!--RectangleQuery-->
                                    <esriToolkit:ToolbarItem Text="矩形查询">
                                        <esriToolkit:ToolbarItem.Content>
                                            <Image source="Images/DrawRectangle.png" Stretch="UniformToFill" Margin="5"/>
                                        </esriToolkit:ToolbarItem.Content>
                                    </esriToolkit:ToolbarItem>
                                </esriToolkit:ToolbarItemCollection>
                            </esriToolkit:Toolbar.Items>
                        </esriToolkit:Toolbar>
                        <TextBlock x:Name="StatusTextBlock" FontWeight="Bold" HorizontalAlignment="Center"/>
                    </StackPanel>
                </Grid>

         这里只讲空间查询部分,其他的距离量算、面积量算等具体见源代码

          后台代码实现:

         public MainPageII() //构造函数初始化
         {

            //初始化MyDrawObject,draw工具
            MyDrawObject = new Draw(Mymap)
            {
                FillSymbol = DefaultFillSymbol,//初始化认的填充颜色
                Linesymbol = DefaultLinesymbol //初始化认的线颜色
            };

            R_530_11845@yDrawObject.DrawComplete += myDrawObject_DrawComplete; //draw完成触发函数,为了获取框选的范围geometry结果
            MyDrawObject.DrawBegin += myDrawObject_DrawBegin; //draw之前触发函数,设置一些画之前的动作

          }

         private void myDrawObject_DrawBegin(object sender,EventArgs args)
        {
            GraphicsLayer graphicsLayer = Mymap.Layers["MapTipGraphicsLayer"] as GraphicsLayer;//设置GraphicsLayer 
            graphicsLayer.ClearGraphics();//draw之前,清空所有的graphics
        }

       ////////////////////////下面是实现工具栏的功能
        private void myDrawObject_DrawComplete(object sender,DrawEventArgs args)
        {
            if (toolmode == "Rectangle_Query")//toolmode变量来判断是哪种模式框选,此处为矩形,其他框选模式原理是一样的,这里不再写出来
            {
                GraphicsLayer graphicsLayer = Mymap.Layers["MapTipGraphicsLayer"] as GraphicsLayer;
                ESRI.ArcGIs.CLIENt.Geometry.Envelope clickEnvelope = args.Geometry as Envelope;//获取几何范围geometry
                //先判断一下是矢量地图还是遥感地图
                if (rasterMap.Ischecked == truE)
                {
                    graphicsLayer.ClearGraphics();
                }
                else
                {
                    graphicsLayer.ClearGraphics();
                    ESRI.ArcGIs.CLIENt.Graphic graphic = new ESRI.ArcGIs.CLIENt.Graphic() //定义框选出来的矩形样式颜色
                    {
                        Geometry = clickEnvelope,
                        Symbol = DefaultFillSymbol
                    };
                    graphicsLayer.Graphics.Add(graphic);//添加框选出来的图形显示在地图上
                }
                QueryTask queryTask = new QueryTask("http://192.168.1.4/arcgis/rest/services/SWUMap/MapServer/9");//定义QueryTask
                queryTask.ExecuteCompleted += QueryTask1_ExecuteCompleted; //query查询结果

                queryTask.Failed += QueryTask_Failed;//query查询失败
                Query query = new ESRI.ArcGIs.CLIENt.Tasks.Query(); //定义query对象
                // Specify fields to return from query
                query.outFields.AddRange(new String[] { "ID","NAME","Area","Length","X","Y","ImagePath" });//设置query条件
                //query.outFields.Add("*");
                query.Where = "1=1";
                query.Geometry = args.Geometry;//几何条件
                query.ReturnGeometry = true;
                queryTask.ExecuteAsync(query);//执行query查询
                Binding resultFeaturesBinding = new Binding("LastResult");/query查询结果值获取,绑定在datagrid表格用
                resultFeaturesBinding.source = queryTask;
                Find_QueryDetailsDataGrid.SetBinding(DataGrid.ItemssourceProperty,resultFeaturesBinding);//获取查询结果值绑定在datagrid表格
                ShowFindQueryWindow.begin();
            }
        }

        /// <sumMary>
        /// 显示选择元素颜色
        /// </sumMary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void QueryTask1_ExecuteCompleted(object sender,ESRI.ArcGIs.CLIENt.Tasks.QueryEventArgs args)
        {
            FeatureSet Query_featureSet = args.FeatureSet;//获取查询结果集合
            GraphicsLayer graphicsLayer = Mymap.Layers["MapTipGraphicsLayer"] as GraphicsLayer;
            if (Query_featureSet == null || Query_featureSet.Features.Count < 1)
            {
                information.Text = "没有查询记录!";
                ShowImageRoot.begin();
                return;
            }
            if (Query_featureSet != null && Query_featureSet.Features.Count > 0)
            {
                foreach (Graphic feature in Query_featureSet.Features)
                {
                    //先判断一下是矢量地图还是遥感地图
                    if (rasterMap.Ischecked == truE)
                    {
                        feature.Symbol = LayoutRoot.resources["RemotePicture"] as ESRI.ArcGIs.CLIENt.Symbols.PictuREMARKerSymbol;//定义符号颜色样式
                        feature.Geometry = new MapPoint(Convert.ToDouble(feature.Attributes["X"]),Convert.ToDouble(feature.Attributes["Y"]));
                        graphicsLayer.Graphics.Add(featurE);
                        RemotePictureStoryboard.begin();
                    }
                    else
                    {
                        feature.Symbol = LayoutRoot.resources["ParcelSymbol"] as FillSymbol;//定义符号颜色样式
                        graphicsLayer.Graphics.Insert(0,featurE);//查询结果的几何图形显示在地图上
                    }
                }
            }
        }

@H_618_201@       二、搜索模块,主要包括路径搜索、关键字搜索、范围搜索

             

西南大学校园GIS平台

      1、关键字搜索,就是普通的query查询,其实应该用locator地理编码服务来实现的,当时自己水平有限,没能使用。把所有兴趣的信息集合在一个图层里面,然后发布地图服务,这样用query查询方式可以达到跟locator一样的目的。

      这里贴上核心后台代码好了,前台界面很简单就是一个文本框输入和按钮。

                QueryTask queryTask = new QueryTask("http://192.168.1.4/arcgis/rest/services/SWUMap/MapServer/9");//定义QueryTask
                queryTask.ExecuteCompleted += QueryTask2_ExecuteCompleted; //query查询结果

                Query query = new ESRI.ArcGIs.CLIENt.Tasks.Query(); //定义query对象
                query.outFields.AddRange(new String[] { "ID","ImagePath" });//设置query条件
                query.text =****;//文本框获取的文本值
                query.ReturnGeometry = true;
                queryTask.ExecuteAsync(query);//执行query查询

      很类似框选查询的query,不过是设置条件换了,geometry换为text,查询结果一样是在 queryTask.ExecuteCompleted里面获取获取到关键字查询的结果然后定位到其地理位置显示在地图上。

      2、范围搜索,这里用buffer分析方式来实现的,利用buffer获取到几何范围geometry,然后再利用query方式来实现,这里很类似空间查询部分的框选查询,不同的是获取geometry方式不太一样,一个是draw,一个是buffer。

            此处是用地图单击事件获取某点,然后利用某点为中心来buffer的,贴上buffer部分代码,后果query代码跟空间查询部分是一样的。

             Geometryservice _geometryservice;

            (1)初始化函数定义

             _geometryservice = new Geometryservice("http://192.168.1.4/arcgis/rest/services/Geometry/GeometryServer");
            _geometryservice.bufferCompleted += Geometryservice_BufferCompleted;
            _geometryservice.Failed += Geometryservice_Failed;        

            (2) 地图单击事件函数

                ////先判断一下,输入条件是否为空
                if (BuffertextBox.Text == "")
                { //messageBox.Show("请您输入范围搜索条件!");
                    information.Text = "请您输入范围搜索条件!";
                    ShowImageRoot.begin();
                  return;
                }
                GraphicsLayer graphicsLayer = Mymap.Layers["MapTipGraphicsLayer"] as GraphicsLayer;
                graphicsLayer.ClearGraphics();
                _geometryservice.CancelAsync();
                _queryTask.CancelAsync();
                Graphic stop = new Graphic();
                if (rasterMap.Ischecked == truE)
                {
                    stop.Symbol = RemotePicture1;
                }
                else
                {
                    stop.Symbol = StopSymbol;
                }
                stop.Geometry = e.MapPoint;//获取地图点坐标
                stop.Geometry.SpatialReference = Mymap.SpatialReference;
                stop.SetZIndex(2);
                graphicsLayer.Graphics.Add(stop);
                // Use a projection appropriate for your area of interest
                ESRI.ArcGIs.CLIENt.Tasks.bufferParameters bufferParams = new ESRI.ArcGIs.CLIENt.Tasks.bufferParameters()
                {
                    //BufferSpatialReference = new SpatialReference(4326),
                    BufferSpatialReference = new SpatialReference(32648),
                    OutSpatialReference = Mymap.SpatialReference,
                    Unit = LinearUnit.Meter//设置地图单位
                };
                double R = Convert.ToDouble(BuffertextBox.Text);//buffer半径
                bufferParams.Distances.Add(R);
                bufferParams.Features.Add(stop);
                _geometryservice.bufferAsync(bufferParams); //执行缓冲分析

             

               (3)获取buffer范围结果函数,然后利用geomerey来query查询

        private void Geometryservice_BufferCompleted(object sender,GraphicsEventArgs args)
        {
            Graphic bufferGraphic = new Graphic();
            bufferGraphic.Geometry = args.Results[0].Geometry;//获取buffer范围geometry
            bufferGraphic.Symbol = BufferSymbol;//定义buffer符号
            bufferGraphic.SetZIndex(1);
            GraphicsLayer graphicsLayer = Mymap.Layers["GLayer"] as GraphicsLayer;
            graphicsLayer.Graphics.Add(bufferGraphic);
            ESRI.ArcGIs.CLIENt.Tasks.Query query = new ESRI.ArcGIs.CLIENt.Tasks.Query();
            //query.outFields.Add("*");
            query.outFields.AddRange(new String[] { "DW","Shape","ID","ImagePath" });
            query.ReturnGeometry = true;
            query.Where = "1=1";
            query.Geometry = bufferGraphic.Geometry;
            _queryTask.ExecuteAsync(query);
            Binding resultFeaturesBinding = new Binding("LastResult.Features");
            resultFeaturesBinding.source = _queryTask;
            huanchongqujieguo.SetBinding(DataGrid.ItemssourceProperty,resultFeaturesBinding);
           // BufferResultWindow.IsOpen = true;
            //huanchongqujieguo.Visibility = Visibility.Visible;
            ShowBufferResultWindow.begin();
        }

      3、路径搜索,最短路径和最优路径,重点详细描述最短路径,最优路径是在最短的路径基础上改造的,这里篇数问题,不再讲。

           (1)最短路径,界面是两个文本框和查询按钮,这里不贴了,贴上核心代码

        //下面是实现路径添加障碍点网络分析
        MapPoint MapPointRoute1,MapPointRoute2;
        RouteTask _routeTask;
        List<Graphic> _stops = new List<Graphic>();
        List<Graphic> _barriers = new List<Graphic>();
        RouteParameters _routeParams = new RouteParameters();
        /////定义Direction
        Graphic _activeSegmentGraphic;
        DirectionsFeatureSet _directionsFeatureSet;

         /// <sumMary>
        /// 最短路径分析初始化
        /// </sumMary>
        private void MyShortPathtochoice()
        {
            _routeTask = new RouteTask("http://192.168.1.4/arcgis/rest/services/SWUMap/NAServer/Route");
            _routeTask.solveCompleted += routeTask_SolveCompleted;
            _routeTask.Failed += routeTask_Failed;
            _routeParams.Stops = _stops;
            _routeParams.barriers = _barriers;
            _routeParamS.UseTimeWindows = false;
            ////定义Direction的
            _routeParams.ReturnRoutes = true;/////
            _routeParams.ReturnDirections = true;
            _routeParams.DirectionsLengthUnits = esriUnits.esriMiles;
        }

          ///////////////执行路径分析  

       if (_stops.Count > 1)
            {
               // GraphicsLayer stopsLayer = Mymap.Layers["MyStopsGraphicsLayer"] as GraphicsLayer;
                if (_routeTask.IsBusy)
                {
                    _routeTask.CancelAsync();
                    stopsLayer.Graphics.RemoveAt(stopsLayer.Graphics.Count - 1);
                }
                _routeTask.solveAsync(_routeParams);


            }

        ///////路径分析结果

       private void routeTask_SolveCompleted(object sender,RouteEventArgs E)
        {
            GraphicsLayer routeLayer = Mymap.Layers["MyRouteGraphicsLayer"] as GraphicsLayer;
            if (e.RouteResults.Count() > 0 && Which_Path1 == "ShortPath")
            {
                ////先清空DirectionsStackPanel
                DirectionsStackPanel.Children.Clear();
                RouteResult routeResult = e.RouteResults[0]
                ////定义Direction
                _directionsFeatureSet = routeResult.Directions;
                routeResult.Route.Geometry = _directionsFeatureSet.MergedGeometry;
                //routeResult.Route.Symbol = RouteSymbol;
                routeResult.Route.Symbol = LayoutRoot.resources["RouteSymbol"] as ESRI.ArcGIs.CLIENt.Symbols.Symbol;
                routeLayer.Graphics.Clear();
                Graphic lastRoute = routeResult.Route;
                //decimal totALLENgth = (decimal)lastRoute.Attributes["Shape_Length"];
                decimal totALLENgth = (decimal)lastRoute.Attributes["@R_903_10586@l_Length"];
                String length = String.Format("{0} Meters",totALLENgth.ToString("#0.000"));
                @R_903_10586@l_Length.Text = length;
                //decimal @R_903_10586@lTime = (decimal)lastRoute.Attributes["@R_903_10586@l_Time"];
                String tip = String.Format("{0} minutes",(totALLENgth/100).ToString("#0.000"));
                @R_903_10586@l_Time.Text = tip;
                routeLayer.Graphics.Add(lastRoutE);
                ////Direction
                int i = 1;
                foreach (Graphic graphic in _directionsFeatureSet.Features)
                {
                    System.Text.StringBuilder text = new System.Text.StringBuilder();
                    TEXT.AppendFormat("{0}. {1}",i,graphic.Attributes["text"]);
                    if (i > 1 && i < _directionsFeatureSet.Features.Count)
                    {
                        String distance = (Convert.ToDouble(graphic.Attributes["length"])*1609.329).ToString();
                       // String distance = graphic.Attributes["length"].ToString();
                       // String distance = graphic.Attributes["length"].ToString();
                        String time = null;
                        if (graphic.Attributes.ContainsKey("time"))
                        {
                            //time = FormatTime(Convert.ToDouble(graphic.Attributes["time"]));
                            time = graphic.Attributes["time"].ToString();
                        }
                        if (!String.IsNullOrEmpty(distancE) || !String.IsNullOrEmpty(timE))
                            text.Append(" (");
                        TEXT.Append(distancE);
                        if (!String.IsNullOrEmpty(distancE) && !String.IsNullOrEmpty(timE))
                            text.Append(",");
                        TEXT.Append(timE);
                        if (!String.IsNullOrEmpty(distancE) || !String.IsNullOrEmpty(timE))
                            text.Append(")");
                    }
                    TEXTBlock textBlock = new TextBlock() { Text = text.ToString(),Tag = graphic,Margin = new Thickness(4),cursor = cursors.Hand };
                    TEXTBlock.MouSELEftButtonDown += new MouseButtonEventHandler(directionsSegment_MouSELEftButtonDown);
                    DirectionsStackPanel.Children.Add(textBlock);
                    i++;
                }
                Mymap.ZoomTo(Expand(_directionsFeatureSet.Extent));
            }                 
        }  

     private void directionsSegment_MouSELEftButtonDown(object sender,MouseButtonEventArgs E)
        {
            TEXTBlock textBlock = sender as TextBlock;
            Graphic feature = textBlock.Tag as Graphic;
            Mymap.ZoomTo(Expand(feature.Geometry.Extent));
            if (_activeSegmentGraphic == null)
            {
                _activeSegmentGraphic = new Graphic() { Symbol = LayoutRoot.resources["SegmentSymbol"] as ESRI.ArcGIs.CLIENt.Symbols.Symbol };
                GraphicsLayer graphicsLayer = Mymap.Layers["MyRouteGraphicsLayer"] as GraphicsLayer;
                graphicsLayer.Graphics.Add(_activeSegmentGraphic);
            }
            _activeSegmentGraphic.Geometry = feature.Geometry;
        }
        private void stackPanel_MouSELEftButtonDown(object sender,MouseButtonEventArgs E)
        {
            if (_directionsFeatureSet != null)
            {
                GraphicsLayer graphicsLayer = Mymap.Layers["MyRouteGraphicsLayer"] as GraphicsLayer;
                Mymap.ZoomTo(Expand(_directionsFeatureSet.Extent));1n
            }
        }
        private Envelope Expand(Envelope E)
        {
            double factor = 0.6;
            MapPoint centerMapPoint = e.GetCenter();
            return new Envelope(centerMapPoint.X - e.Width * factor,centerMapPoint.Y - e.Height * factor,
                centerMapPoint.X + e.Width * factor,centerMapPoint.Y + e.Height * factor);
        }  

       三、GPS模拟定位,这里说说思路好了,具体见源代码。主要是模拟校车每个时刻的地位Point,然后再描绘出来连接成线line,最后添加再地图上显示出来。应用到arcgis api的对象point、line、graphic、geometry、graphiclayer等等。

       统计分析,这里不描述了,具体见源代码

       备注:

       源代码下载:pan.baidu.com/s/1nt3JYDb

        密码:sb3j

       GIS技术交流QQ群:432512093

       GIS论坛:http://arcgis.c.ev123.com/vip_arcgis.html

@H_673_503@

大佬总结

以上是大佬教程为你收集整理的西南大学校园GIS平台全部内容,希望文章能够帮你解决西南大学校园GIS平台所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。