This sample demonstrates using a geometry service to generate query geometry. To use the sample, simply click on the map. The click point will be buffered and parcels that intersect the buffer will be retrieved and drawn.
In the code-behind, a GeometryService is used to generate the buffer from the click point. A QueryTask is then used to perform a query using the buffer geometry.
<UserControlx:Class="ArcGISWPFSDK.BufferQuery"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:esri="http://schemas.esri.com/arcgis/client/2009"><Gridx:Name="LayoutRoot"Background="White"><Grid.Resources><esri:PictureMarkerSymbolx:Key="DefaultMarkerSymbol"OffsetX="11"OffsetY="39"Source="/Assets/Images/i_pushpin.png"/><esri:SimpleFillSymbolx:Key="BufferSymbol"Fill="#66BB0000"BorderBrush="#88CC0000"BorderThickness="2"/><esri:SimpleFillSymbolx:Key="ParcelSymbol"Fill="#440000FF"BorderBrush="Blue"BorderThickness="2"/><LinearGradientBrushx:Key="PanelGradient"EndPoint="0.5,1"StartPoint="0.5,0"><LinearGradientBrush.RelativeTransform><TransformGroup><ScaleTransformCenterY="0.5"CenterX="0.5"/><SkewTransformCenterY="0.5"CenterX="0.5"/><RotateTransformAngle="176"CenterY="0.5"CenterX="0.5"/><TranslateTransform/></TransformGroup></LinearGradientBrush.RelativeTransform><GradientStopColor="#FF145787"Offset="0.16"/><GradientStopColor="#FF3D7FAC"Offset="0.502"/><GradientStopColor="#FF88C5EF"Offset="0.984"/></LinearGradientBrush></Grid.Resources><esri:Mapx:Name="MyMap"Background="White"WrapAround="True"Extent="-9270434.248,5246977.326,-9269261.417,5247569.712"MouseClick="MyMap_MouseClick"><esri:ArcGISTiledMapServiceLayerID="StreetMapLayer"Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/><esri:GraphicsLayerID="MyResultsGraphicsLayer"><esri:GraphicsLayer.MapTip><BorderBorderBrush="DarkGray"Background="Azure"CornerRadius="3"BorderThickness="1"Padding="3"><StackPanelOrientation="Vertical"><TextBlockText="Owner:"FontWeight="Bold"HorizontalAlignment="Left"VerticalAlignment="Center"Foreground="Black"/><TextBlockText="{Binding [OWNERNME1]}"HorizontalAlignment="Left"VerticalAlignment="Center"Foreground="Black"/></StackPanel></Border></esri:GraphicsLayer.MapTip></esri:GraphicsLayer><esri:GraphicsLayerID="MyGraphicsLayer"IsHitTestVisible="False"/></esri:Map><GridHorizontalAlignment="Right"VerticalAlignment="Top"Margin="0,15,15,0"><RectangleFill="{StaticResource PanelGradient}"Stroke="Gray"RadiusX="10"RadiusY="10"Margin="0,0,0,5"><Rectangle.Effect><DropShadowEffect/></Rectangle.Effect></Rectangle><RectangleFill="#FFFFFFFF"Stroke="DarkGray"RadiusX="5"RadiusY="5"Margin="10,10,10,15"/><TextBlockx:Name="InformationTextBlock"Text="Click on map to set a location. A buffer will used to display parcels within 100 meters of the location."Width="200"Margin="30,20,30,25"HorizontalAlignment="Left"TextWrapping="Wrap"Foreground="Black"/></Grid></Grid></UserControl>
using System.Windows;
using System.Windows.Controls;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Geometry;
using ESRI.ArcGIS.Client.Tasks;
namespace ArcGISWPFSDK
{
publicpartialclass BufferQuery : UserControl
{
GeometryService _geometryService;
QueryTask _queryTask;
GraphicsLayer _pointAndBufferGraphicsLayer;
GraphicsLayer _resultsGraphicsLayer;
public BufferQuery()
{
InitializeComponent();
_geometryService =
new GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
_geometryService.BufferCompleted += GeometryService_BufferCompleted;
_geometryService.Failed += GeometryService_Failed;
_queryTask = new QueryTask("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/BloomfieldHillsMichigan/Parcels/MapServer/2");
_queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted;
_queryTask.Failed += QueryTask_Failed;
_pointAndBufferGraphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
_resultsGraphicsLayer = MyMap.Layers["MyResultsGraphicsLayer"] as GraphicsLayer;
}
privatevoid MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
{
_geometryService.CancelAsync();
_queryTask.CancelAsync();
Graphic clickGraphic = new Graphic();
clickGraphic.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
clickGraphic.Geometry = e.MapPoint;
// Input spatial reference for buffer operation defined by first feature of input geometry array
clickGraphic.Geometry.SpatialReference = MyMap.SpatialReference;
_pointAndBufferGraphicsLayer.ClearGraphics();
_resultsGraphicsLayer.ClearGraphics();
clickGraphic.SetZIndex(2);
_pointAndBufferGraphicsLayer.Graphics.Add(clickGraphic);
// If buffer spatial reference is GCS and unit is linear, geometry service will do geodesic buffering
ESRI.ArcGIS.Client.Tasks.BufferParameters bufferParams = new ESRI.ArcGIS.Client.Tasks.BufferParameters()
{
BufferSpatialReference = new SpatialReference(4326),
OutSpatialReference = MyMap.SpatialReference,
Unit = LinearUnit.Meter,
};
bufferParams.Distances.Add(100);
bufferParams.Features.Add(clickGraphic);
_geometryService.BufferAsync(bufferParams);
}
void GeometryService_BufferCompleted(object sender, GraphicsEventArgs args)
{
Graphic bufferGraphic = new Graphic();
bufferGraphic.Geometry = args.Results[0].Geometry;
bufferGraphic.Symbol = LayoutRoot.Resources["BufferSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
bufferGraphic.SetZIndex(1);
_pointAndBufferGraphicsLayer.Graphics.Add(bufferGraphic);
ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query();
query.ReturnGeometry = true;
query.OutSpatialReference = MyMap.SpatialReference;
query.Geometry = bufferGraphic.Geometry;
query.OutFields.Add("OWNERNME1");
_queryTask.ExecuteAsync(query);
}
privatevoid QueryTask_ExecuteCompleted(object sender, QueryEventArgs args)
{
if (args.FeatureSet.Features.Count < 1)
{
MessageBox.Show("No features found");
return;
}
foreach (Graphic selectedGraphic in args.FeatureSet.Features)
{
selectedGraphic.Symbol = LayoutRoot.Resources["ParcelSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
_resultsGraphicsLayer.Graphics.Add(selectedGraphic);
}
}
privatevoid GeometryService_Failed(object sender, TaskFailedEventArgs args)
{
MessageBox.Show("Geometry service failed: " + args.Error);
}
privatevoid QueryTask_Failed(object sender, TaskFailedEventArgs args)
{
MessageBox.Show("Query failed: " + args.Error);
}
}
}
Imports System.Windows
Imports System.Windows.Controls
Imports ESRI.ArcGIS.Client
Imports ESRI.ArcGIS.Client.Geometry
Imports ESRI.ArcGIS.Client.Tasks
Namespace ArcGISWPFSDK
PartialPublicClass BufferQuery
Inherits UserControl
Private _geometryService As GeometryService
Private _queryTask As QueryTask
Private _pointAndBufferGraphicsLayer As GraphicsLayer
Private _resultsGraphicsLayer As GraphicsLayer
PublicSubNew()
InitializeComponent()
_geometryService = New GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer")
AddHandler _geometryService.BufferCompleted, AddressOf GeometryService_BufferCompleted
AddHandler _geometryService.Failed, AddressOf GeometryService_Failed
_queryTask = New QueryTask("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/BloomfieldHillsMichigan/Parcels/MapServer/2")
AddHandler _queryTask.ExecuteCompleted, AddressOf QueryTask_ExecuteCompleted
AddHandler _queryTask.Failed, AddressOf QueryTask_Failed
_pointAndBufferGraphicsLayer = TryCast(MyMap.Layers("MyGraphicsLayer"), GraphicsLayer)
_resultsGraphicsLayer = TryCast(MyMap.Layers("MyResultsGraphicsLayer"), GraphicsLayer)
EndSubPrivateSub MyMap_MouseClick(sender AsObject, e As ESRI.ArcGIS.Client.Map.MouseEventArgs)
_geometryService.CancelAsync()
_queryTask.CancelAsync()
Dim clickGraphic AsNew Graphic()
clickGraphic.Symbol = TryCast(LayoutRoot.Resources("DefaultMarkerSymbol"), ESRI.ArcGIS.Client.Symbols.Symbol)
clickGraphic.Geometry = e.MapPoint
' Input spatial reference for buffer operation defined by first feature of input geometry array
clickGraphic.Geometry.SpatialReference = MyMap.SpatialReference
_pointAndBufferGraphicsLayer.ClearGraphics()
_resultsGraphicsLayer.ClearGraphics()
clickGraphic.SetZIndex(2)
_pointAndBufferGraphicsLayer.Graphics.Add(clickGraphic)
' If buffer spatial reference is GCS and unit is linear, geometry service will do geodesic bufferingDim bufferParams AsNew ESRI.ArcGIS.Client.Tasks.BufferParameters() With { _
.BufferSpatialReference = New SpatialReference(4326), _
.OutSpatialReference = MyMap.SpatialReference, _
.Unit = LinearUnit.Meter _
}
bufferParams.Distances.Add(100)
bufferParams.Features.Add(clickGraphic)
_geometryService.BufferAsync(bufferParams)
EndSubPrivateSub GeometryService_BufferCompleted(sender AsObject, args As GraphicsEventArgs)
Dim bufferGraphic AsNew Graphic()
bufferGraphic.Geometry = args.Results(0).Geometry
bufferGraphic.Symbol = TryCast(LayoutRoot.Resources("BufferSymbol"), ESRI.ArcGIS.Client.Symbols.Symbol)
bufferGraphic.SetZIndex(1)
_pointAndBufferGraphicsLayer.Graphics.Add(bufferGraphic)
Dim query AsNew ESRI.ArcGIS.Client.Tasks.Query()
query.ReturnGeometry = True
query.OutSpatialReference = MyMap.SpatialReference
query.Geometry = bufferGraphic.Geometry
query.OutFields.Add("OWNERNME1")
_queryTask.ExecuteAsync(query)
EndSubPrivateSub QueryTask_ExecuteCompleted(sender AsObject, args As QueryEventArgs)
If args.FeatureSet.Features.Count < 1 Then
MessageBox.Show("No features found")
ReturnEndIfForEach selectedGraphic As Graphic In args.FeatureSet.Features
selectedGraphic.Symbol = TryCast(LayoutRoot.Resources("ParcelSymbol"), ESRI.ArcGIS.Client.Symbols.Symbol)
_resultsGraphicsLayer.Graphics.Add(selectedGraphic)
NextEndSubPrivateSub GeometryService_Failed(sender AsObject, args As TaskFailedEventArgs)
MessageBox.Show("Geometry service failed: " & Convert.ToString(args.[Error]))
EndSubPrivateSub QueryTask_Failed(sender AsObject, args As TaskFailedEventArgs)
MessageBox.Show("Query failed: " & Convert.ToString(args.[Error]))
EndSubEndClassEndNamespace