silverlight调用GP服务实现缓冲区

silverlight调用GP服务实现缓冲区,第1张

概述  启发来源于http://blog.csdn.net/qq364981997/article/details/8769388 http://www.cnblogs.com/potential/archive/2012/11/03/2752289.html   写代码之前制作模型,这里使用的是ArcTutor\GP Service Examples\BufferPoints。 也可以根据http:

 

启发来源于http://blog.csdn.net/qq364981997/article/details/8769388

http://www.cnblogs.com/potential/archive/2012/11/03/2752289.html

 

写代码之前制作模型,这里使用的是ArcTutor\GP Service Examples\BufferPoints。

也可以根据http://help.arcgis.com/zh-cn/arcgisdesktop/10.0/help/index.html#//002v00000014000000自己做数据。做完之后测试一下。

前端代码:

<UserControl x:Class="GPBuffer.MainPage"    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:esri="http://schemas.esri.com/arcgis/clIEnt/2009"    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    mc:Ignorable="d"    d:DesignHeight="300" d:DesignWIDth="400">    <GrID x:name="LayoutRoot" Background="White">        <GrID.Resources>            <esri:PictureMarkerSymbol x:Key="DefaultClickSymbol" OffsetX="11" OffsetY="39" Source="/car-red-16x16.png" />            <esri:SimpleFillSymbol x:Key="DefaultBufferSymbol" Fill="#660000FF" borderBrush="Blue" borderThickness="2"  />        </GrID.Resources>        <esri:Map x:name="MyMap" Background="White"            MouseClick="MyMap_MouseClick" >            <esri:ArcGISDynamicMapServiceLayer ID="buffer"                                               Url="http://localhost/arcgis/rest/services/bufferpoint/MapServer"/>            <esri:Graphicslayer ID="MyGraphicslayer">            </esri:Graphicslayer>        </esri:Map>        <GrID HorizontalAlignment="Right" VerticalAlignment="top" margin="0,15,0" >            <Rectangle Fill="#77919191" stroke="Gray"  RadiusX="10" RadiusY="10" margin="0,5" >                <Rectangle.Effect>                    <DropShadowEffect/>                </Rectangle.Effect>            </Rectangle>            <Rectangle Fill="#FFFFFFFF" stroke="DarkGray" RadiusX="5" RadiusY="5" margin="10,10,15" />            <TextBlock x:name="informationText" Text="Click on map to set a location. A buffer of 1000 meters will be displayed."                 WIDth="200" margin="30,20,30,25" HorizontalAlignment="left" textwrapPing="Wrap" />        </GrID>    </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.Tasks;
using ESRI.ArcGIS.ClIEnt.Symbols;

namespace GPBuffer
{
    public partial class MainPage : UserControl
    {
        Geoprocessor _geoprocessorTask;
        public MainPage()
        {
            InitializeComponent();
            _geoprocessorTask = new Geoprocessor("http://localhost/arcgis/rest/services/bufferpoint/GPServer/Buffer%20Points");
            _geoprocessorTask.JobCompleted += new EventHandler<JobInfoEventArgs>(_geoprocessorTask_JobCompleted);
            _geoprocessorTask.GetResultDataCompleted += new EventHandler<GPParameterEventArgs>(_geoprocessorTask_GetResultDataCompleted);
            _geoprocessorTask.Failed += new EventHandler<TaskFailedEventArgs>(_geoprocessorTask_Failed);
        }

        voID _geoprocessorTask_Failed(object sender,TaskFailedEventArgs e)
        {
            MessageBox.Show("请求服务失败:" + e.Error.ToString());
        }

        voID _geoprocessorTask_GetResultDataCompleted(object sender,GPParameterEventArgs e)
        {
            Graphicslayer graphicslayer = new Graphicslayer();
            GPFeatureRecordSetLayer featuresetLayer = e.Parameter as GPFeatureRecordSetLayer;
            foreach (Graphic graphic in featuresetLayer.Featureset.Features)
            {
                graphic.Symbol = LayoutRoot.Resources["DefaultBufferSymbol"] as Symbol;
                graphicslayer.Graphics.Add(graphic);
            }
            MyMap.Layers.Add(graphicslayer);
            MessageBox.Show("********************");
        }

        voID _geoprocessorTask_JobCompleted(object sender,JobInfoEventArgs e)
        {
            if (e.JobInfo.JobStatus == esriJobStatus.esriJobFailed)
            {
                MessageBox.Show("请求服务失败:"+e.JobInfo.Messages.ToString());
                return;
            }
            httpWebRequest.RegisterPrefix("http://",System.Net.Browser.WebRequestCreator.ClientHttp);
            _geoprocessorTask.GetResultDataAsync(e.JobInfo.JobID,"Output_polygons");
        }
       
        private voID MyMap_MouseClick(object sender,ESRI.ArcGIS.ClIEnt.Map.MouseEventArgs e)
        {
            Graphicslayer graphicslayer = MyMap.Layers["MyGraphicslayer"] as Graphicslayer;
            graphicslayer.Cleargraphics();

            e.MapPoint.SpatialReference = MyMap.SpatialReference;
            Graphic graphic = new Graphic() {
                Geometry=e.MapPoint,
                Symbol=LayoutRoot.Resources["DefaultClickSymbol"] as Symbol
            };
           
            graphic.SetZIndex(1);
            graphicslayer.Graphics.Add(graphic);

            List<GPParameter> parameters = new List<GPParameter>();
            parameters.Add(new GPFeatureRecordSetLayer("input_Points",e.MapPoint));
            parameters.Add(new GPlinearUnit("distance",esriUnits.esriMeters,1000));

            _geoprocessorTask.submitJobAsync(parameters);
        }

        //voID _geoprocessorTask_Failed(object sender,TaskFailedEventArgs e)
        //{
        //    MessageBox.Show("Geoprocessing service Failed: " + e.Error);
        //}

        //voID _geoprocessorTask_ExecuteCompleted(object sender,GPExecuteCompleteEventArgs e)
        //{
        //    Graphicslayer graphicslayer = MyMap.Layers["MyGraphicslayer"] as Graphicslayer;

        //    foreach (GPParameter parameter in e.Results.OutParameters)
        //    {
        //        if (parameter is GPFeatureRecordSetLayer)
        //        {
        //            GPFeatureRecordSetLayer gpLayer = parameter as GPFeatureRecordSetLayer;

        //            foreach (Graphic graphic in gpLayer.Featureset.Features)
        //            {
        //                graphic.Symbol = LayoutRoot.Resources["DefaultBufferSymbol"] as Symbol;
        //                graphicslayer.Graphics.Add(graphic);
        //            }
        //        }
        //    }
        //}
    }
}

 

注释掉的是同步执行的方法,但是好像不管用

下图是Buffer  GP服务的详细信息。

结果:

总结

以上是内存溢出为你收集整理的silverlight调用GP服务实现缓冲区全部内容,希望文章能够帮你解决silverlight调用GP服务实现缓冲区所遇到的程序开发问题。

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

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

原文地址: http://outofmemory.cn/web/1019293.html

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

发表评论

登录后才能评论

评论列表(0条)

保存