开始之前的一段废话:
放假回家了也就没有写博客了,家里没有网,偶尔也只能用手机上一上,看一看是否有新的评论和回复,是否有和我研究相关的博文和动态。今天是三月一号,学校的校园网帐号解封了,于是便把寒假部分的工作内容总结一下,在此也和大家一起分享我的心得,希望对各位读者能有所帮助。
本文的例子是我帮一位兄弟做的,算起还是我的学长,只不过不同学校,具体的要求如下:
http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=124221&extra=page%3D1
于是假期的时候便做了一个该功能的例子,然后还加了一点小功能。后面的文章中将会详细介绍,下面就进入正题吧!
一、本文实现的功能
1.1 要素查询功能
根据要素属性,查询出相应的要素
1.2 栅格数据的像元统计
例如输入一个几何图形(点,线,面)可以计算出该图像范围内栅格数据的像元信息,如:像元最大值,最小值,以及平均值等,具体如下图所示:
1.3 绘制地形剖面图
该功能和官网的这个例子差不多:
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#SurfaceProfile
(不知道为什么,我这里查看不了这里例子)
效果如下图所示:
二、使用到的数据和知识
2.1地图数据
本例的地形高程数据来自于国际科学数据服务平台,下载网址:
http://datamirror.csdb.cn/index.jsp
本例的各区县要素数据来自于国家基础地理信息中心,下载网址:
http://nfgis.nsdi.gov.cn/nfgis/chinese/c_xz.htm
上面的地图是我自己在ArcMap中制作的一张地图,外加了一点地形阴影效果,这是在ArcMap中的图层列表
各县面要素图层
最后通过以上数据得到了本文使用的底图。在查询部分中,实际上查询的就是各区县的面要素,可通过输入曲线的民称或编号来查询出相对应的县,然后再通过调研像元统计的GP服务工具,即可实现像元统计,得到对应区县范围内像元的最大值,最小值等信息,实际上这里的值也就是对应区县的海拔(准确度由下载的高程数据所决定),最后的地图:
2.2 使用到如下的知识:
2.2.1 要素的属性查询
2.2.2 GP服务的调用
2.2.3 通过开源的Silverlight图表控件:OxyPlot
以上前两部分内容都在之前的博文中讲过,所以不是本文的重点。关于OxyPlot图表控件也很简单,这里不会过多的解释说明。官网有很好的帮助文档。
三、实现过程
3.1 查询(要素属性查询和空间查询)
可参考之前的博文:
http://www.cnblogs.com/potential/archive/2013/01/31/2882244.html
3.2 根据查询得到的面要素,计算出面要素对应区域内的像元信息。
3.2.1 发布像元统计的GP服务
这里主要用到的就是GP服务。下面是本文的GP服务模型:
其中Zonefiled就是统计字段,inputFeature为输入的要素,ZonalRaster为统计的删格数据
提醒:在10.1中可以将栅格数据作为输入参数。在10.0中不可以,如果您是10.0版本的,那么这里你只能在建模的时候指定栅格数据,然后去掉设置为模型参数。在10.1中如果你有可数的几个不同栅格数据,那么你可以将其添加到ArcMap中,在发布GP服务的时候,会提示你从列表选择还是自定义栅格数据,这个时候你可以选择从列表选择。然后你可以将ArcMap中的删格数据图层添加到选择列表中,最后在Web端调用的时候,你只需要输入栅格数据列表中对于栅格数据的名称即可,例如本文的列表如下:
这里可以看出只有一个栅格数据选项:hunandata。
3.2.2 Web端调用GP服务
调用GP服务的过程之前的博文也有讲到,可参考这里:
http://www.cnblogs.com/potential/archive/2012/11/03/2752289.html
下面是本文的调用代码:
private voID AccessGPService(Featureset featureset) { List<GPParameter> gppara = new List<GPParameter>(); //输入GP服务的参数 gppara.Add(new GPString("Zonefiled","OBJECTID")); gppara.Add(new GPFeatureRecordSetLayer("inputFeature",featureset)); gppara.Add(new GPString("ZonalRaster","hunandata")); _geoprocessor.submitJobAsync(gppara); } private voID _geoprocessor_JobCompleted(object sender,JobInfoEventArgs e) { httpWebRequest.RegisterPrefix("http://",System.Net.browser.WebRequestCreator.ClIEnthttp); Geoprocessor gp = sender as Geoprocessor; //请求GP服务的结果 gp.GetResultDataAsync(e.JobInfo.JobID,"Resulttable"); } private voID _geoprocessor_GetResultDataCompleted(object sender,GPParameterEventArgs e) { MyDataGrID.ItemsSource = null; GPRecordSet gpr = e.Parameter as GPRecordSet; if (gpr.Featureset != null) { for (int i = 0; i < gpr.Featureset.Features.Count; i++) { for (int j = 2; j < gpr.Featureset.Features[i].Attributes.Count; j++) { //这里本文有个BUG,就是当FeatureDataGrID绑定到Graphicslayer后, //如果修改GrAPIcslayer的属性(增加或者删除)会报错,以下代码不能通过,所以这里选择了先修改再绑定 List<string> keyList = gpr.Featureset.Features[i].Attributes.Keys.ToList<string>(); List<object> valueList = gpr.Featureset.Features[i].Attributes.Values.ToList(); graphicslayer.Graphics[i].Attributes.Add(keyList[j],valueList[j]); } } //在此绑定DataGrID,不然会出现异常 MyDataGrID.Graphicslayer = graphicslayer; MyDataGrID.Visibility = Visibility.Visible; //绘制地形图 if (createPlot == true) { CreatePlot(); Terrainborder.Visibility = Visibility.Visible; } featureset.Features.Clear(); } //等待过程 BusyRectangle.Visibility = Visibility.Collapsed; busyIndicator.IsBusy = false; } private voID _geoprocessor_Failed(object sender,TaskFailedEventArgs e) { MessageBox.Show(e.Error.ToString()); }
以上是调用GP服务的代码,这里有个BUG。
最后的统计结果如下所示:
3.2.3 Web客户端绘制地形图
这里借助的是开源的图表控件:OxyPlot。感觉绘制图表很强大,而且开源啊。
绘制地形剖面图的功能大致上的过程如下:
首先在地图上绘制一条线,然后等分这条线,例如一百份,然后得到这一百个点的像元统计值(最后的值就是海拔值,这里数据的准确度和提供的高程数据经度有关,高程数据经度越高,结果也就越准确),得到一百个点的高程数据之后,就通过OxyPlot绘图了。
具体代码:
a.OxyPlot绘图
声明一个PlotModel,PlotModel代表绘制图表的类型。
PlotModel plotModel = null;
在构造函数中初始化:
var linearaxis1 = new linearaxis(Axisposition.Bottom) { IsZoomEnabled=false,Title="距离"}; plotModel.Axes.Add(linearaxis1); var linearaxis2 = new linearaxis(Axisposition.left) { IsZoomEnabled=false,Title="海拔"}; plotModel.Axes.Add(linearaxis2); areaSerIEs1 = new AreaSerIEs { Fill=Oxycolors.DarkOrange,datafieldX="距离",datafieldY="最高海拔",datafieldX2 = "距离",datafieldY2 = "最低海拔",color=Oxycolors.Red,strokeThickness=0,MarkerFill=Oxycolors.transparent,};
b.然后绘制一条直线并构造点:
private voID CreatPoint(ESRI.ArcGIS.ClIEnt.Geometry.polyline polyline,int count) { //默认沿直线构造一百个点 double xStep = (polyline.Paths[0][1].X - polyline.Paths[0][0].X) / count; double yStep = (polyline.Paths[0][1].Y - polyline.Paths[0][0].Y) / count; interval = Math.Sqrt(xStep * xStep + yStep * yStep); //清空Featureset便于之后的GP服务调用 if (featureset.Features.Count > 0) { featureset.Features.Clear(); } for (int i = 0; i < count; i++) { MapPoint mp = new MapPoint(polyline.Paths[0][0].X + i*xStep,polyline.Paths[0][0].Y + i*yStep); mp.SpatialReference = map1.SpatialReference; Graphic gPoint = new Graphic() { Symbol = new SimpleMarkerSymbol() { color=new SolIDcolorBrush(colors.Blue),Size=8,Style=SimpleMarkerSymbol.SimpleMarkerStyle.Circle },Geometry=mp,}; featureset.Features.Add(gPoint); graphicslayer.Graphics.Add(gPoint); } }
c.调用GP服务统计像元值(代码如上)
d.根据统计值绘制图表,这里Graphic的MAX属性表示的即为最高海拔,对于点要素MAX和MIN值是一样的。
private voID CreatePlot() { areaSerIEs1.Points.Clear(); areaSerIEs1.Points2.Clear(); plotModel.SerIEs.Clear(); for (int i = 0; i < graphicslayer.Graphics.Count; i++) { areaSerIEs1.Points.Add(new DataPoint(interval * i,Convert.Todouble(graphicslayer.Graphics[i].Attributes["MAX"]))); areaSerIEs1.Points2.Add(new DataPoint(interval * i,0)); } plotModel.SerIEs.Add(areaSerIEs1); areaSerIEs1.Title = "海拔"; Myplot.Model = plotModel; createPlot = false; }
最后的MainPage.cs代码:
VIEw Codeusing System; using System.Collections.Generic; using System.linq; using System.Net; using System.windows; using System.windows.Controls; using System.windows.documents; using System.windows.input; using System.windows.Media; using System.windows.Media.Animation; using System.windows.Shapes; using ESRI.ArcGIS.ClIEnt.Symbols; using ESRI.ArcGIS.ClIEnt.Geometry; using ESRI.ArcGIS.ClIEnt.Tasks; using ESRI.ArcGIS.ClIEnt; using System.Text.RegularExpressions; using OxyPlot.Silverlight; using OxyPlot; namespace queryAndStatisticDemo { public partial class MainPage : UserControl { //用于查询的Task queryTask queryTask = new queryTask(); //声明一个Draw,用于绘制查询的区域,进行空间查询 Draw myDraw; //绘制的Geomotry ESRI.ArcGIS.ClIEnt.Geometry.Geometry drawGeometry; //查询sql字符串 string queryString; //选择查询结果中的Graphic Graphic selectedGraphic; //地理处理服务 Geoprocessor _geoprocessor = null; //输入要素集 Featureset featureset = new Featureset(); Graphicslayer graphicslayer; PlotModel plotModel = null; //Interval AreaSerIEs areaSerIEs1; double interval; bool createPlot = false; public MainPage() { InitializeComponent(); plotModel = new PlotModel("地形剖面图"); var linearaxis1 = new linearaxis(Axisposition.Bottom) { IsZoomEnabled=false,}; graphicslayer = map1.Layers["queryResultLayer"] as Graphicslayer; queryTask.Url = "http://qzj-pc:6080/arcgis/rest/services/Provinces_Map/HunanMap/MapServer/3"; queryTask.autonormalize = true; //很重要,否则出现查询成功和失败交替出现的现象 queryTask.disableClIEntCaching = true; queryTask.ExecuteCompleted += new EventHandler<queryEventArgs>(queryTask_ExecuteCompleted); queryTask.Failed += new EventHandler<TaskFailedEventArgs>(queryTask_Failed); _geoprocessor = new Geoprocessor("http://qzj-pc:6080/arcgis/rest/services/RasterStatisticServer/GPServer/DemStatisticsRaster"); _geoprocessor.JobCompleted += new EventHandler<JobInfoEventArgs>(_geoprocessor_JobCompleted); _geoprocessor.Failed += new EventHandler<TaskFailedEventArgs>(_geoprocessor_Failed); _geoprocessor.GetResultDataCompleted += new EventHandler<GPParameterEventArgs>(_geoprocessor_GetResultDataCompleted); myDraw = new Draw(map1); myDraw.DrawMode = DrawMode.polygon; myDraw.IsEnabled = false; myDraw.FillSymbol = new SimpleFillSymbol() { borderBrush = new SolIDcolorBrush(colors.Black),borderThickness = 3,Fill = new SolIDcolorBrush(colors.Red),}; myDraw.linesymbol = new linesymbol() { color=new SolIDcolorBrush(colors.Red),WIDth=3 }; myDraw.DrawComplete += new EventHandler<DrawEventArgs>(myDraw_DrawComplete); queryTypeComBox.ItemsSource = AttributeString.GraphicAttributesEnnameString; } private voID myDraw_DrawComplete(object sender,DrawEventArgs e) { graphicslayer.Graphics.Clear(); drawGeometry = e.Geometry; myDraw.IsEnabled = false; if (drawGeometry is ESRI.ArcGIS.ClIEnt.Geometry.polyline) { CreatPoint((ESRI.ArcGIS.ClIEnt.Geometry.polyline)drawGeometry,100); BusyRectangle.Visibility = Visibility.Visible; busyIndicator.IsBusy = true; AccessGPService(featureset); } else { StartqueryBySpatial(e.Geometry); } } private voID Expressionbutton_Click(object sender,RoutedEventArgs e) { string pattern = @"^[0-9]*$"; button button = sender as button; Match m = Regex.Match(button.Content.ToString(),pattern); if (m.Success) ExpressionTextBox.Text = string.Format("{0}{1}",ExpressionTextBox.Text,button.Content); else ExpressionTextBox.Text = string.Format("{0} {1} ",button.Content); } private voID Expressionquerybutton_Click(object sender,RoutedEventArgs e) { CreatqueryString(); StartqueryBysql(queryString); } private voID Spatialquerybutton_Click(object sender,RoutedEventArgs e) { ExpressionTextBox.Text = ""; myDraw.DrawMode = DrawMode.polygon; myDraw.IsEnabled = true; } private voID filedsComBox_SelectionChanged(object sender,SelectionChangedEventArgs e) { ComboBox comb = sender as ComboBox; if (comb.Selectedindex != -1) { int index = comb.Selectedindex; ExpressionTextBox.Text = string.Format("{0}{1}",comb.SelectedItem.ToString()); } comb.Selectedindex = -1; } private voID ExpressionTextBox_KeyDown(object sender,System.windows.input.KeyEventArgs e) { // 按了回车键就向服务端发送数据 if (e.Key == Key.Enter) { CreatqueryString(); StartqueryBysql(queryString); } } private voID Qoutbutton_Click(object sender,RoutedEventArgs e) { button button = sender as button; ExpressionTextBox.Text = string.Format("{0}{1}",button.Content); } private voID Nobutton_Click(object sender,RoutedEventArgs e) { button button = sender as button; ExpressionTextBox.Text = string.Format("{0} {1}",button.Content); } private voID Cleargraphicsbutton_Click(object sender,RoutedEventArgs e) { graphicslayer.Graphics.Clear(); } private voID Graphicslayer_MouseleftbuttonDown(object sender,GraphicMousebuttonEventArgs e) { if (selectedGraphic != null) { selectedGraphic.UnSelect(); selectedGraphic.Symbol = new SimpleFillSymbol() { borderBrush = new SolIDcolorBrush(colors.Red),borderThickness = 2,Fill = new SolIDcolorBrush(colors.Green) }; } e.Graphic.Select(); e.Graphic.Symbol = new SimpleFillSymbol() { Fill=new SolIDcolorBrush(colors.Red),borderBrush = new SolIDcolorBrush(colors.Yellow),borderThickness=3 }; if (e.Graphic.Selected&&MyDataGrID.Graphicslayer!=null) MyDataGrID.ScrollintoVIEw(e.Graphic,null); selectedGraphic = e.Graphic; } #region 查询失败几完成事件 private voID queryTask_ExecuteCompleted(object sender,queryEventArgs e) { graphicslayer.Cleargraphics(); if (e.Featureset.Features.Count > 0) { foreach (Graphic resultFeature in e.Featureset.Features) { if (drawGeometry != null) { //查询结果落在绘制的多边形之内 if (resultFeature.Geometry.Extent.XMax < drawGeometry.Extent.XMax && resultFeature.Geometry.Extent.XMin > drawGeometry.Extent.XMin && resultFeature.Geometry.Extent.YMax < drawGeometry.Extent.YMax && resultFeature.Geometry.Extent.YMin > drawGeometry.Extent.YMin) { resultFeature.Symbol = new SimpleFillSymbol() { borderBrush = new SolIDcolorBrush(colors.Red),Fill = new SolIDcolorBrush(colors.Green) }; featureset.Features.Add(resultFeature); graphicslayer.Graphics.Add(resultFeature); } } else { resultFeature.Symbol = new SimpleFillSymbol() { borderBrush = new SolIDcolorBrush(colors.Red),Fill = new SolIDcolorBrush(colors.Green) }; featureset.Features.Add(resultFeature); graphicslayer.Graphics.Add(resultFeature); } } if (graphicslayer.Graphics.Count < 1) MessageBox.Show("没有查询到目标要素!"); } else { MessageBox.Show("没有查询到目标要素!"); } drawGeometry = null; } private voID queryTask_Failed(object sender,TaskFailedEventArgs e) { MessageBox.Show("query Failed: " + e.Error); } #endregion #region 查询自定义方法 /// <summary> /// 条件查询 /// </summary> /// <param name="sqlString">查询SQL语句</param> private voID StartqueryBysql(string sqlString) { queryTask.CancelAsync(); if (ExpressionTextBox.Text == "") return; query query = new query(); query.ReturnGeometry = true; query.OutFIElds.AddRange(new string[] { "name99","ADCODE99" }); query.Where = sqlString; query.OutSpatialReference = map1.SpatialReference; queryTask.ExecuteAsync(query); } /// <summary> /// 空间查询 /// </summary> /// <param name="geometry">几何图形</param> private voID StartqueryBySpatial(ESRI.ArcGIS.ClIEnt.Geometry.Geometry geometry) { queryTask.CancelAsync(); query query = new query(); query.ReturnGeometry = true; query.OutFIElds.AddRange(new string[] { "name99","ADCODE99" }); query.Geometry = geometry; query.SpatialRelationship = SpatialRelationship.esriSpatialRelContains; query.OutSpatialReference = map1.SpatialReference; queryTask.ExecuteAsync(query); } /// <summary> /// 构造查询Where条件的SQL语句 /// </summary> private voID CreatqueryString() { if (queryTypeComBox.Selectedindex == 0) queryString =string.Format("name99 = '{0}'",ExpressionTextBox.Text); else if (queryTypeComBox.Selectedindex == 1) queryString = string.Format("ADCODE99 = '{0}'",ExpressionTextBox.Text); else return; } #endregion # region 调用GP服务进行栅格像元统计 private voID Statisticbutton_Click(object sender,RoutedEventArgs e) { if (featureset.Features.Count <= 0) return; BusyRectangle.Visibility = Visibility.Visible; busyIndicator.IsBusy = true; AccessGPService(featureset); } private voID AccessGPService(Featureset featureset) { List<GPParameter> gppara = new List<GPParameter>(); //输入GP服务的参数 gppara.Add(new GPString("Zonefiled",TaskFailedEventArgs e) { MessageBox.Show(e.Error.ToString()); } #endregion private voID terrainbutton_Click(object sender,RoutedEventArgs e) { myDraw.DrawMode = DrawMode.polyline; Terrainborder.Visibility = Visibility.Collapsed; myDraw.IsEnabled = true; createPlot = true; } private voID CreatPoint(ESRI.ArcGIS.ClIEnt.Geometry.polyline polyline,}; featureset.Features.Add(gPoint); graphicslayer.Graphics.Add(gPoint); } } private voID CreatePlot() { areaSerIEs1.Points.Clear(); areaSerIEs1.Points2.Clear(); plotModel.SerIEs.Clear(); for (int i = 0; i < graphicslayer.Graphics.Count; i++) { areaSerIEs1.Points.Add(new DataPoint(interval * i,0)); } plotModel.SerIEs.Add(areaSerIEs1); areaSerIEs1.Title = "海拔"; Myplot.Model = plotModel; createPlot = false; } private voID button_MouseEnter(object sender,System.windows.input.MouseEventArgs e) { // Todo: Add event handler implementation here. Busybutton.Content = "取消"; } private voID button_MouseLeave(object sender,System.windows.input.MouseEventArgs e) { // Todo: Add event handler implementation here. Busybutton.Content = "正在计算..."; } private voID Busybutton_Click(object sender,System.windows.RoutedEventArgs e) { // Todo: Add event handler implementation here. BusyRectangle.Visibility = Visibility.Collapsed; busyIndicator.IsBusy = false; } } }
最后的MainPage.xaml代码:
VIEw Code<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/Expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:oxy="clr-namespace:OxyPlot.Silverlight;assembly=OxyPlot.Silverlight" xmlns:esri="http://schemas.esri.com/arcgis/clIEnt/2009" xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" x:Class="queryAndStatisticDemo.MainPage" mc:Ignorable="d" d:DesignHeight="760" d:DesignWIDth="960" > <GrID x:name="LayoutRoot"> <GrID.Background> <linearGradIEntBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradIEntStop color="#FF65C0A5" Offset="0"/> <GradIEntStop color="#FF1E1E1F" Offset="1"/> <GradIEntStop color="#FF22555C" Offset="0.428"/> <GradIEntStop color="#FF596EA1" Offset="0.681"/> </linearGradIEntBrush> </GrID.Background> <GrID.RowDeFinitions> <RowDeFinition Height="120"/> <RowDeFinition Height="*"/> </GrID.RowDeFinitions> <!--Map--> <esri:Map x:name="map1" WrapAround="True" VerticalContentAlignment="Stretch" GrID.rowspan="2" margin="0"> <esri:Map.Layers> <esri:LayerCollection> <esri:ArcGISDynamicMapServiceLayer Url="http://qzj-pc:6080/arcgis/rest/services/Provinces_Map/HunanMap/MapServer" /> <esri:Graphicslayer ID="queryResultLayer" Opacity="0.8" MouseleftbuttonDown="Graphicslayer_MouseleftbuttonDown"/> </esri:LayerCollection> </esri:Map.Layers> </esri:Map> <!--queryborder--> <border borderBrush="Black" borderThickness="1" margin="8" CornerRadius="5" Background="#7F94BCE0"> <GrID> <StackPanel OrIEntation="Horizontal" HorizontalAlignment="Center"> <StackPanel VerticalAlignment="Center" HorizontalAlignment="left" margin="10,10,0"> <StackPanel OrIEntation="Horizontal" HorizontalAlignment="left"> <button x:name="Morethanbutton1" Content="1" Height="23" WIDth="48" Click="Expressionbutton_Click" /> <button x:name="Lessthanbutton2" Content="2" HorizontalAlignment="left" Height="23" WIDth="48" Click="Expressionbutton_Click" /> <button x:name="Equalbutton1" Content="3" Height="23" WIDth="43" Click="Expressionbutton_Click" /> </StackPanel> <StackPanel OrIEntation="Horizontal" HorizontalAlignment="left"> <button x:name="MoreOrEbutton1" Content="4" HorizontalAlignment="left" Height="23" WIDth="48" Click="Expressionbutton_Click" /> <button x:name="LessOrEqualbutton1" Content="5" HorizontalAlignment="left" Height="23" WIDth="48" Click="Expressionbutton_Click" /> <button x:name="LessAndMorebutton1" Content="6" Height="23" WIDth="43" HorizontalAlignment="left" Click="Expressionbutton_Click" /> </StackPanel> <StackPanel OrIEntation="Horizontal" HorizontalAlignment="left"> <button x:name="likebutton1" Content="7" HorizontalAlignment="left" Height="23" WIDth="48" Click="Expressionbutton_Click" /> <button x:name="Andbutton1" Content="8" HorizontalAlignment="left" Height="23" WIDth="48" Click="Expressionbutton_Click" /> <button x:name="Orbutton1" Content="9" Height="23" WIDth="43" Click="Expressionbutton_Click" /> </StackPanel> <StackPanel OrIEntation="Horizontal" HorizontalAlignment="left"> <button x:name="Notbutton1" Content="0" HorizontalAlignment="left" Height="23" WIDth="48" Click="Expressionbutton_Click" /> <button x:name="Qoutbutton" Content="'" HorizontalAlignment="left" Height="23" WIDth="48" tooltipService.tooltip="单引号" Click="Qoutbutton_Click" /> <button x:name="Nobutton" Content="!" Height="23" WIDth="43" tooltipService.tooltip="非运算" Click="Nobutton_Click" /> </StackPanel> </StackPanel> <StackPanel VerticalAlignment="top" HorizontalAlignment="Center" margin="0"> <StackPanel OrIEntation="Horizontal" margin="0,0"> <TextBlock textwrapPing="Wrap" Text="查询条件:" Height="18" margin="20,0" FontSize="14" FontWeight="Bold" Foreground="Red"/> <ComboBox x:name="queryTypeComBox" Height="23" WIDth="130" Selectedindex="0" margin="0,0"/> <TextBox x:name="ExpressionTextBox" textwrapPing="Wrap" Height="27" margin="0,5,0" WIDth="150" KeyDown="ExpressionTextBox_KeyDown"/> </StackPanel> <StackPanel OrIEntation="Horizontal" margin="0,0"> <button x:name="Expressionquerybutton" Content="条件查询" Height="30" WIDth="70" margin="20,0" Click="Expressionquerybutton_Click"/> <button x:name="Spatialquerybutton" Content="空间查询" Height="30" WIDth="70" Click="Spatialquerybutton_Click" margin="10,0" /> <button Content="绘制地形图" Height="30" x:name="terrainbutton" WIDth="75" margin="20,0" Click="terrainbutton_Click"/> </StackPanel> </StackPanel> <StackPanel VerticalAlignment="Center" HorizontalAlignment="left" margin="20,20,0"> <button WIDth="135" Height="23" x:name="Statisticbutton" Content="地形统计" margin="0,0" Click="Statisticbutton_Click" /> <button x:name="ClearExpressionbutton" Content="清空查询语句" Height="23" WIDth="135" Click="Spatialquerybutton_Click" margin="0,0" /> <button WIDth="135" Height="23" x:name="Cleargraphicsbutton" Content="清空图层" margin="0,0" Click="Cleargraphicsbutton_Click" /> </StackPanel> </StackPanel> </GrID> </border> <!--StatisticResultForm--> <esri:FeatureDataGrID x:name="MyDataGrID" HorizontalAlignment="Right" margin="0,20" VerticalAlignment="Bottom" Map="{Binding Elementname=map1}" WIDth="400" Height="200" GrID.Column="0" GrID.Row="1" SelectionMode="Single" VerticalGrIDlinesBrush="#FF31D8D8" HorizontalGrIDlinesBrush="#FF31B1B1" RowBackground="#AA3C8A99" Visibility="Collapsed" > <esri:FeatureDataGrID.Effect> <DropShadowEffect/> </esri:FeatureDataGrID.Effect> <esri:FeatureDataGrID.Background> <linearGradIEntBrush EndPoint="0.894,0.85" StartPoint="-0.076,-0.033"> <GradIEntStop color="#FF56585E"/> <GradIEntStop color="#FF1B8D85" Offset="1"/> </linearGradIEntBrush> </esri:FeatureDataGrID.Background> </esri:FeatureDataGrID> <border borderThickness="1" GrID.Row="1" Height="260" HorizontalAlignment="left" margin="20" x:name="Terrainborder" VerticalAlignment="Bottom" WIDth="400" CornerRadius="10" Visibility="Collapsed"> <border.Effect> <DropShadowEffect/> </border.Effect> <oxy:Plot x:name="Myplot" Foreground="#FFE9E5E5" > <oxy:Plot.Effect> <DropShadowEffect/> </oxy:Plot.Effect> <oxy:Plot.Background> <linearGradIEntBrush EndPoint="0.5,0"> <GradIEntStop color="#FF0F4549" Offset="0"/> <GradIEntStop color="#B266AABA" Offset="1"/> <GradIEntStop color="#DA8F9EA1" Offset="0.471"/> </linearGradIEntBrush> </oxy:Plot.Background> </oxy:Plot> </border> <Rectangle x:name="BusyRectangle" Fill="#FF454552" stroke="Black" GrID.rowspan="2" Opacity="0.5" Visibility="Collapsed"/> <toolkit:BusyIndicator x:name="busyIndicator" GrID.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center" IsBusy="False"> <toolkit:BusyIndicator.BusyContent> <GrID> <button x:name="Busybutton" Height="23" WIDth="199" Content="正在计算..." MouseEnter="button_MouseEnter" MouseLeave="button_MouseLeave" padding="3" Click="Busybutton_Click"/> </GrID> </toolkit:BusyIndicator.BusyContent> </toolkit:BusyIndicator> </GrID> </UserControl>
最终的效果:
按县区名称查询双峰县,结果如下图所示:
正在统计双峰县的像元信息
统计结果如下图所示:
绘制一条直线
通过直线得到构造点,并进行像元统计
最后的统计结果,及地下剖面图,根据直线经过的地方来看,地形图是正确的。
在图上可以查看剖面图的数据:
空间查询,并进行统计
总结:以上的过程大致上说了一下Web端区域像元统计的过程,其中涉及到了要素查询,GP服务,Web端栅格数据作为输入数据的处理问题,OxyPlot图表控件的使用,FeatureDataGrID的数据绑定等,有些内容进行了详细的说明,有些由于时间限制就没有进行细致的说明,在此还望谅解。有什么问题可以留言反映,我一定都会逐一回复。当然程序中还有很多BUG,也没有处理,程序的结构也不是很好,代码质量也不高,希望高手勿喷,欢迎您提出宝贵的意见和分享您的解决方法。
还有需要提醒一点的是本文使用的服务都是我自己发布的服务,所以您需要自己发布程序中用到的服务。
【源码下载】
总结以上是内存溢出为你收集整理的Silverlight客户端实现区域像元统计以及地形剖面图的绘制全部内容,希望文章能够帮你解决Silverlight客户端实现区域像元统计以及地形剖面图的绘制所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)