silverlight调用GP服务实现缓冲区
来源:互联网 发布:java开发图书管理系统 编辑:程序博客网 时间:2024/05/22 10:40
启发来源于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,15,0" > <Rectangle Fill="#77919191" Stroke="Gray" RadiusX="10" RadiusY="10" Margin="0,0,0,5" > <Rectangle.Effect> <DropShadowEffect/> </Rectangle.Effect> </Rectangle> <Rectangle Fill="#FFFFFFFF" Stroke="DarkGray" RadiusX="5" RadiusY="5" Margin="10,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调用Geometry服务实现缓冲区
- Silverlight调用GP服务第二篇之调用GP服务(Geoprocessing Service)过程详解
- Silverlight调用GP服务第二篇之调用GP服务(Geoprocessing Service)过程详解
- ArcGIS API for Silverlight 调用GP服务绘制等值面
- Silverlight 调用GP服务第一篇之发布GP服务(Geoprocessing Service)
- Silverlight 调用GP服务第一篇之发布GP服务(Geoprocessing Service)
- Silverlight 调用GP服务第一篇之发布GP服务(Geoprocessing Service)
- ArcGIS API for Silverlight 调用GP服务准备---GP模型建立、发布、测试
- ArcGIS API for Silverlight 调用GP服务准备---GP模型建立、发布、测试
- ArcGIS API for Silverlight 调用GP服务准备---GP模型建立、发布、测试
- 调用GP服务
- ArcGISServer Flex API 调用GP服务实现服务区分析
- ArcGIS API for Silverlight 调用GP服务加载等值线图层
- ArcGIS API for Silverlight 调用GP服务加载等值线图层
- ArcGIS API for Silverlight 调用GP服务加载等值线图层
- ArcGIS API for Silverlight 调用GP服务加载等值线图层
- ArcGIS Engine调用GP服务
- weblogic 10.3.5安装截图
- Ubuntu下配置samba实现文件夹共享
- C#大整数的阶乘
- Linux--线程编程
- WebKit介绍及总结(一)
- silverlight调用GP服务实现缓冲区
- Thinkphp 的CURD,增、删、读、写操作
- C++智能指针
- C#中的比较
- Android客户端缓存机制(文字缓存和多媒体文件缓存)
- WebKit介绍及总结(二)
- js获取table中的值
- POJ 2778 DNA Sequence (AC自动机)
- 巧用时间周期判定变盘