已经建立好GP模型,模拟可以生成等值线,现在在Silverlight客户端调用该GP工具时,提供模型输入参数要素集FeatureSet,但是输入参数中的Fields始终为null值,最终导致模型调用失败,无任何输出。 主要代码如下: 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) { 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("GP服务地址"); List<GPParameter> parameters = new List<GPParameter>(); parameters.Add(new GPFeatureRecordSetLayer("RainPoint",featureset)); //这里的featureSet的Fields为null值,就是输入参数没有模型中的字段,请问是怎么回事呢? 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_Kriging_Clip"); } 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()); //这里的gplayer.FeatureSet为null值,错误就出现在这里 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; } 调用的Utility.cs类代码如下: 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 将网格划分点添加到图层中 GraphicCollection graphicCollection = new GraphicCollection(); 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("OBJECTID",""); g.Attributes.Add("SHAPE","Point"); g.Attributes.Add("YL",evaluationpoint.YL); graphicCollection.Add(g); graphicslayer.Graphics.Add(g); } featureset = new FeatureSet(graphicCollection); #endregion } } 转自地信网:http://bbs.3s001.com/thread-108518-1-1.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。