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

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

概述 利用ArcGIS API for Silverlight实现GP服务调用,这里的雨量数据是通过一个WebService获取而来,主要信息是雨量站点的经纬度坐标值和某个时间段内的降雨量值三个主要字段。   以下是核心代码部分: < UserControl x:Class= "TestDZX.MainPage2"     xmlns= "http://schemas.microsoft.com/wi

 利用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

总结

以上是内存溢出为你收集整理的ArcGIS API for Silverlight 调用GP服务加载等值线图层全部内容,希望文章能够帮你解决ArcGIS API for Silverlight 调用GP服务加载等值线图层所遇到的程序开发问题。

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

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1017210.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存