西南大学校园GIS平台
系統(tǒng)架構是B/S,開發(fā)語言是C#、silverlight,開發(fā)平臺是.NET,數(shù)據庫為sqlserver,這是我讀研究生時候自己做的作品,以自己的母校為地圖,進行GIS相關的功能分析,核心的模塊有:空間查詢、GPS定位模擬、搜索模塊、統(tǒng)計分析;其中說的不足之處,望各位指點出來。
? ? ?一、空間查詢 ?? ?
? ? ?整體思路:空間查詢是用戶在地圖上框選一定范圍,然后根據框選范圍Geometry來進行query查詢。框選利用Draw工具有多邊形、矩形、圓線等方式。實現(xiàn)方式,前臺界面設計:
? ? ? ? ? ? ? ??<!--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>
? ? ? ? ?這里只講空間查詢部分,其他的距離量算、面積量算等具體見源代碼。
? ? ? ? ? 后臺代碼實現(xiàn):
? ? ? ? ?public MainPageII() //構造函數(shù)初始化
? ? ? ? ?{
? ? ? ? ? ??//初始化MyDrawObject,draw工具
? ? ? ? ? ? MyDrawObject = new Draw(MyMap)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? FillSymbol = DefaultFillSymbol, //初始化默認的填充顏色
? ? ? ? ? ? ? ? LineSymbol = DefaultLineSymbol //初始化默認的線顏色
? ? ? ? ? ? };
? ? ? ? ? ??MyDrawObject.DrawComplete += myDrawObject_DrawComplete; //draw完成觸發(fā)函數(shù),為了獲取框選的范圍geometry結果
? ? ? ? ? ? MyDrawObject.DrawBegin += myDrawObject_DrawBegin; //draw之前觸發(fā)函數(shù),設置一些畫之前的動作
? ? ? ? ? }
? ? ? ? ?private void myDrawObject_DrawBegin(object sender, EventArgs args)
? ? ? ? {
? ? ? ? ? ? GraphicsLayer graphicsLayer = MyMap.Layers["MapTipGraphicsLayer"] as GraphicsLayer;//設置GraphicsLayer?
? ? ? ? ? ? graphicsLayer.ClearGraphics();//draw之前,清空所有的graphics
? ? ? ? }
? ? ? ?下面是實現(xiàn)工具欄的功能
? ? ? ? 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);//執(zhí)行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);//查詢結果的幾何圖形顯示在地圖上
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? ???二、搜索模塊,主要包括路徑搜索、關鍵字搜索、范圍搜索
? ? ? ? ? ? ?
? ? ??1、關鍵字搜索,就是普通的query查詢,其實應該用locator地理編碼服務來實現(xiàn)的,當時自己水平有限,沒能使用。把所有興趣的信息集合在一個圖層里面,然后發(fā)布地圖服務,這樣用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", "NAME", "Area", "Length", "X", "Y", "ImagePath" });//設置query條件
? ? ? ? ? ? ? ? query.text =****;//文本框獲取的文本值
? ? ? ? ? ? ? ? query.ReturnGeometry = true;
? ? ? ? ? ? ? ? queryTask.ExecuteAsync(query);//執(zhí)行query查詢
? ? ? 很類似框選查詢的query,不過是設置條件換了,geometry換為text,查詢結果一樣是在?queryTask.ExecuteCompleted里面獲取,獲取到關鍵字查詢的結果然后定位到其地理位置顯示在地圖上。
? ??? 2、范圍搜索,這里用buffer分析方式來實現(xiàn)的,利用buffer獲取到幾何范圍geometry,然后再利用query方式來實現(xiàn),這里很類似空間查詢部分的框選查詢,不同的是獲取geometry方式不太一樣,一個是draw,一個是buffer。
? ? ? ? ? ? 此處是用地圖單擊事件獲取某點,然后利用某點為中心來buffer的,貼上buffer部分代碼,后果query代碼跟空間查詢部分是一樣的。
? ? ? ? ? ? ?GeometryService _geometryService;
? ? ? ? ? ??(1)初始化函數(shù)定義
? ? ? ? ??? ?_geometryService = new GeometryService("http://192.168.1.4/arcgis/rest/services/Geometry/GeometryServer");
? ? ? ? ? ? _geometryService.BufferCompleted += GeometryService_BufferCompleted;
? ? ? ? ? ? _geometryService.Failed += GeometryService_Failed;? ??? ??
?
? ? ? ? ??? (2)?地圖單擊事件函數(shù)
? ? ? ? ? ? ? ? 先判斷一下,輸入條件是否為空
? ? ? ? ? ? ? ? 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); //執(zhí)行緩沖分析
? ? ? ? ? ? ?
? ? ? ? ? ? ? ?(3)獲取buffer范圍結果函數(shù),然后利用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", "Area", "Length", "NAME","X","Y","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、路徑搜索,最短路徑和最優(yōu)路徑,重點詳細描述最短路徑,最優(yōu)路徑是在最短的路徑基礎上改造的,這里篇數(shù)問題,不再講。
? ? ? ? ? ?(1)最短路徑,界面是兩個文本框和查詢按鈕,這里不貼了,貼上核心代碼:
? ? ? ? //下面是實現(xiàn)路徑添加障礙點網絡分析
? ? ? ? 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;
? ? ? ? }
? ? ? ?? ?///執(zhí)行路徑分析 ?
?? ? ? 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["Total_Length"];
? ? ? ? ? ? ? ? string length = string.Format("{0} Meters", totalLength.ToString("#0.000"));
? ? ? ? ? ? ? ? Total_Length.Text = length;
? ? ? ? ? ? ? ? //decimal totalTime = (decimal)lastRoute.Attributes["Total_Time"];
? ? ? ? ? ? ? ? string tip = string.Format("{0} minutes", (totalLength/100).ToString("#0.000"));
? ? ? ? ? ? ? ? Total_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等等。
? ? ? ?四、統(tǒng)計分析,這里不描述了,具體見源代碼。
? ? ? ?備注:
? ? ? ?源代碼下載:pan.baidu.com/s/1nt3JYDb
? ? ? ? 密碼:sb3j
? ? ? ?GIS技術交流QQ群:432512093
總結
以上是生活随笔為你收集整理的西南大学校园GIS平台的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【网络流】【Dinic】【Next Ar
- 下一篇: 关于 java 实现 语音朗读