您的位置:首页 > 其它

ArcGIS API for Silverlight 调用GP服务加载等值线图层

2013-09-05 10:43 645 查看
 利用ArcGIS API for Silverlight实现GP服务调用,这里的雨量数据是通过一个WebService获取而来,主要信息是雨量站点的经纬度坐标值和某个时间段内的降雨量值三个主要字段。

  以下是核心代码部分:

<UserControl x:Class="TestDZX.MainPage2"

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:esri="http://schemas.esri.com/arcgis/client/2009"

mc:Ignorable="d"

d:DesignHeight="300" d:DesignWidth="400">

<Grid x:Name="LayoutRoot" Background="White">

<esri:Map x:Name="myMap" IsLogoVisible="False" ZoomDuration="0:00:00" PanDuration="0:00:00"

Extent="117.647738815324,29.4704217183843,118.446182957997,30.4124245048916">

<esri:Map.Layers>

<esri:ArcGISTiledMapServiceLayer ID="BaseLayer" Url="http://localhost/arcgis/rest/services/HSDQ/MapServer/"/>

<!--等值线图层-->

<esri:GraphicsLayer ID="GraphicsDZX">

</esri:GraphicsLayer>

</esri:Map.Layers>

</esri:Map>

</Grid>

</UserControl>

using 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;

using ESRI.ArcGIS.Client.Geometry;

using ESRI.ArcGIS.Client.Tasks;

using System.Net.Browser;

using ESRI.ArcGIS.Client.Symbols;

using TestDZX.ServiceReference1;

using System.Collections.ObjectModel;

namespace TestDZX

{

public partial class MainPage2 : UserControl

{

/******************GP参数* 2012-08-29***********************/

private Geoprocessor _ContourTask; //等值线GP

public struct EvaluationPointStruct

{

public double Latitute; //纬度

public double Longitute; //经度

public double YL; //雨量

};

public EvaluationPointStruct[] evaluatePoints;

private FeatureSet featureSet;//作为GP输入参数的要素集

/*********************************************************/

public MainPage2()

{

InitializeComponent();

getXQYJInfoSoapClient client = new getXQYJInfoSoapClient();

client.GetAllSHRainCompleted += new EventHandler<GetAllSHRainCompletedEventArgs>(client_GetAllSHRainCompleted);

client.GetAllSHRainAsync();

}

void client_GetAllSHRainCompleted(object sender, GetAllSHRainCompletedEventArgs e)

{

//获取到所有的山洪雨量点

ObservableCollection<RainFall> lists = e.Result;

int PointsNum = lists.Count;//点的个数

evaluatePoints = new EvaluationPointStruct[PointsNum];

int index = 0;

foreach (RainFall item in lists)

{

if (item.YL24 != 0)

{

evaluatePoints[index].Latitute = item.Latitute;

evaluatePoints[index].Longitute = item.Longitute;

evaluatePoints[index].YL = item.YL24;

index++;

}

}

Utility.AddPointToMapLayer(myMap, evaluatePoints, out featureSet);

AccessGPService(featureSet);

}

private void AccessGPService(FeatureSet featureset)

{

HttpWebRequest.RegisterPrefix("http://", System.Net.Browser.WebRequestCreator.ClientHttp);

_ContourTask = new Geoprocessor("http://localhost/arcgis/rest/services/ContourServiceTool/GPServer/Model");

List<GPParameter> parameters = new List<GPParameter>();

parameters.Add(new GPFeatureRecordSetLayer("RainPoint", featureset));

parameters.Add(new GPDouble("Contour_interval", 5));

_ContourTask.UpdateDelay = 10000;

_ContourTask.OutputSpatialReference = myMap.SpatialReference; //设置输出空间参考系

_ContourTask.JobCompleted += new EventHandler<JobInfoEventArgs>(geoprocessorTask_JobCompleted);

_ContourTask.Failed += new EventHandler<TaskFailedEventArgs>(geoprocessorTask_Failed);

_ContourTask.SubmitJobAsync(parameters);

}

/********************************事件处理程序段***************************************/

void geoprocessorTask_JobCompleted(object sender, JobInfoEventArgs e)

{

Geoprocessor gp = sender as Geoprocessor;

//注册前缀

HttpWebRequest.RegisterPrefix("http://", System.Net.Browser.WebRequestCreator.ClientHttp);

gp.GetResultDataCompleted += new EventHandler<GPParameterEventArgs>(gp_GetResultDataCompleted);

gp.GetResultDataAsync(e.JobInfo.JobId, "Contour_Kriging1_Clip_shp");

}

void gp_GetResultDataCompleted(object sender, GPParameterEventArgs e)

{

//找到显示等值线图层并清空,然后再次加载

GraphicsLayer layer = myMap.Layers["GraphicsDZX"] as GraphicsLayer;

layer.ClearGraphics();

GPFeatureRecordSetLayer gplayer = e.Parameter as GPFeatureRecordSetLayer;

MessageBox.Show("结果图层个数:" + gplayer.FeatureSet.Features.Count.ToString());

foreach (Graphic graphic in gplayer.FeatureSet.Features)

{

graphic.Symbol = new ESRI.ArcGIS.Client.Symbols.SimpleLineSymbol()

{

Style = ESRI.ArcGIS.Client.Symbols.SimpleLineSymbol.LineStyle.Solid,

Color = new SolidColorBrush(Colors.Blue),

Width = 3

};

layer.Graphics.Add(graphic);

}

}

void geoprocessorTask_Failed(object sender, TaskFailedEventArgs e)

{

MessageBox.Show(e.Error.ToString());

}

//分类渲染

public Symbol getSymbol(Graphic graphic)

{

//线符号

SimpleLineSymbol symbol = new SimpleLineSymbol();

double yl = double.Parse(graphic.Attributes["YL"].ToString());

if (yl > 10)

{

symbol.Color = new SolidColorBrush(Colors.Red);

}

else

{

symbol.Color = new SolidColorBrush(Colors.Blue);

}

return symbol;

}

}

}
  使用到的另一个cs类文件如下Utility.cs文件如下

using System;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Ink;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

using ESRI.ArcGIS.Client.Geometry;

using ESRI.ArcGIS.Client;

using ESRI.ArcGIS.Client.Tasks;

using System;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Ink;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

using ESRI.ArcGIS.Client.Geometry;

using ESRI.ArcGIS.Client;

using ESRI.ArcGIS.Client.Tasks;

namespace TestDZX

{

public class Utility

{

public static void AddPointToMapLayer(ESRI.ArcGIS.Client.Map map, MainPage2.EvaluationPointStruct[] evaluatePoints, out ESRI.ArcGIS.Client.Tasks.FeatureSet featureset)

{

ESRI.ArcGIS.Client.Projection.WebMercator mercator = new ESRI.ArcGIS.Client.Projection.WebMercator();

#region 动态添加预测点图层

if (map.Layers["YLPointsLayer"] != null)

{

map.Layers.Remove(map.Layers["YLPointsLayer"]);

}

GraphicsLayer graphicslayer = new GraphicsLayer()

{

ID = "YLPointsLayer",

};

map.Layers.Add(graphicslayer);

#endregion

#region 将降雨量点添加到图层中

featureset = new FeatureSet();

foreach (MainPage2.EvaluationPointStruct evaluationpoint in evaluatePoints)

{

Graphic g = new Graphic()

{

Geometry = mercator.FromGeographic(new MapPoint(evaluationpoint.Latitute, evaluationpoint.Longitute)),

Symbol = new ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol()

{

Style = ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol.SimpleMarkerStyle.Circle,

Size = 9,

Color = new SolidColorBrush(Colors.Red)

}

};

g.Attributes.Add("YL", evaluationpoint.YL);

featureset.Features.Add(g);

graphicslayer.Graphics.Add(g);

}

#endregion

}

}

}
  本文来自taomanman的博客,原文地址:http://blog.csdn.net/taomanman/article/details/7937879
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐