This sample demonstrates using an ESRI.ArcGIS.Client.Tasks GeometryService that takes an input polyline graphic that cuts across one on more boundaries of another polygon graphics layer to generate a new set of polygon graphics that are defined by the cutting polyline.
To use the sample, add a polyline to cut and thus subdivide intersecting parcel polygons.
<UserControlx:Class="ArcGISWPFSDK.Cut"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"><Grid.Resources><esri:SimpleLineSymbolx:Key="RedLineSymbol"Color="Red"Width="4"Style="Solid"/><esri:FillSymbolx:Key="BlueFillSymbol"><esri:FillSymbol.ControlTemplate><ControlTemplatex:Name="CustomPolygonTemplate"><Grid><VisualStateManager.VisualStateGroups><VisualStateGroupx:Name="CommonStates"><VisualStatex:Name="Normal"/><VisualStatex:Name="MouseOver"><Storyboard><ColorAnimationStoryboard.TargetName="Element"Storyboard.TargetProperty="(Fill).(Color)"To="#6600FFFF"Duration="0:0:0.1"/></Storyboard></VisualState></VisualStateGroup></VisualStateManager.VisualStateGroups><Pathx:Name="Element"Stroke="Red"Fill="#660000FF"StrokeStartLineCap="Round"StrokeThickness="2"StrokeLineJoin="Round"StrokeEndLineCap="Round"/></Grid></ControlTemplate></esri:FillSymbol.ControlTemplate></esri:FillSymbol><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"Extent="-83.3188395774275,42.61428312652851,-83.31295664068958,42.61670913269855"><esri:ArcGISTiledMapServiceLayerID="StreetMapLayer"Url="http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/><esri:GraphicsLayerID="ParcelsGraphicsLayer"/></esri:Map><GridHorizontalAlignment="Right"VerticalAlignment="Top"Margin="0,10,10,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="ResponseTextBlock"Text="Add a polyline to cut and thus subdivide intersecting parcel polygons."Width="200"TextAlignment="Left"Margin="30,20,20,30"TextWrapping="Wrap"Foreground="Black"/></Grid></Grid></UserControl>
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Tasks;
namespace ArcGISWPFSDK
{
publicpartialclass Cut : UserControl
{
private Draw MyDrawObject;
private GraphicsLayer parcelGraphicsLayer;
public Cut()
{
InitializeComponent();
MyMap.Layers.LayersInitialized += Layers_LayersInitialized;
MyMap.MinimumResolution = double.Epsilon;
MyDrawObject = new Draw(MyMap)
{
DrawMode = DrawMode.Polyline,
IsEnabled = false,
LineSymbol = LayoutRoot.Resources["RedLineSymbol"] as ESRI.ArcGIS.Client.Symbols.LineSymbol
};
MyDrawObject.DrawComplete += MyDrawObject_DrawComplete;
parcelGraphicsLayer = MyMap.Layers["ParcelsGraphicsLayer"] as GraphicsLayer;
}
void Layers_LayersInitialized(object sender, EventArgs args)
{
if (parcelGraphicsLayer != null && parcelGraphicsLayer.Graphics.Count == 0)
{
QueryTask queryTask =
new QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/TaxParcel/AssessorsParcelCharacteristics/MapServer/1");
Query query = new Query();
query.Geometry = MyMap.Extent;
query.ReturnGeometry = true;
queryTask.ExecuteCompleted += queryTask_ExecuteCompleted;
queryTask.Failed += queryTask_Failed;
queryTask.ExecuteAsync(query);
}
}
void queryTask_Failed(object sender, TaskFailedEventArgs e)
{
MessageBox.Show("Query error: " + e.Error);
}
void queryTask_ExecuteCompleted(object sender, QueryEventArgs e)
{
foreach (Graphic g in e.FeatureSet.Features)
{
g.Symbol = LayoutRoot.Resources["BlueFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
g.Geometry.SpatialReference = MyMap.SpatialReference;
parcelGraphicsLayer.Graphics.Add(g);
}
MyDrawObject.IsEnabled = true;
}
privatevoid MyDrawObject_DrawComplete(object sender, DrawEventArgs args)
{
MyDrawObject.IsEnabled = false;
ESRI.ArcGIS.Client.Geometry.Polyline polyline = args.Geometry as ESRI.ArcGIS.Client.Geometry.Polyline;
polyline.SpatialReference = MyMap.SpatialReference;
GeometryService geometryService =
new GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
geometryService.CutCompleted += GeometryService_CutCompleted;
geometryService.Failed += GeometryService_Failed;
geometryService.CutAsync(parcelGraphicsLayer.Graphics.ToList(), polyline);
}
void GeometryService_CutCompleted(object sender, CutEventArgs e)
{
parcelGraphicsLayer.ClearGraphics();
foreach (Graphic g in e.Results)
{
g.Symbol = LayoutRoot.Resources["BlueFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
parcelGraphicsLayer.Graphics.Add(g);
}
MyDrawObject.IsEnabled = true;
}
privatevoid GeometryService_Failed(object sender, TaskFailedEventArgs e)
{
MessageBox.Show("Geometry Service error: " + e.Error);
}
}
}
Imports System.Linq
Imports System.Windows
Imports System.Windows.Controls
Imports ESRI.ArcGIS.Client
Imports ESRI.ArcGIS.Client.Tasks
Namespace ArcGISWPFSDK
PartialPublicClass Cut
Inherits UserControl
Private MyDrawObject As Draw
Private parcelGraphicsLayer As GraphicsLayer
PublicSubNew()
InitializeComponent()
AddHandler MyMap.Layers.LayersInitialized, AddressOf Layers_LayersInitialized
MyMap.MinimumResolution = Double.Epsilon
MyDrawObject = New Draw(MyMap) With { _
.DrawMode = DrawMode.Polyline, _
.IsEnabled = False, _
.LineSymbol = TryCast(LayoutRoot.Resources("RedLineSymbol"), ESRI.ArcGIS.Client.Symbols.LineSymbol) _
}
AddHandler MyDrawObject.DrawComplete, AddressOf MyDrawObject_DrawComplete
parcelGraphicsLayer = TryCast(MyMap.Layers("ParcelsGraphicsLayer"), GraphicsLayer)
EndSubPrivateSub Layers_LayersInitialized(sender AsObject, args As EventArgs)
If parcelGraphicsLayer IsNotNothingAndAlso parcelGraphicsLayer.Graphics.Count = 0 ThenDim queryTask AsNew QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/TaxParcel/AssessorsParcelCharacteristics/MapServer/1")
Dim query AsNew Query()
query.Geometry = MyMap.Extent
query.ReturnGeometry = TrueAddHandler queryTask.ExecuteCompleted, AddressOf queryTask_ExecuteCompleted
AddHandler queryTask.Failed, AddressOf queryTask_Failed
queryTask.ExecuteAsync(query)
EndIfEndSubPrivateSub queryTask_Failed(sender AsObject, e As TaskFailedEventArgs)
MessageBox.Show("Query error: " & Convert.ToString(e.[Error]))
EndSubPrivateSub queryTask_ExecuteCompleted(sender AsObject, e As QueryEventArgs)
ForEach g As Graphic In e.FeatureSet.Features
g.Symbol = TryCast(LayoutRoot.Resources("BlueFillSymbol"), ESRI.ArcGIS.Client.Symbols.Symbol)
g.Geometry.SpatialReference = MyMap.SpatialReference
parcelGraphicsLayer.Graphics.Add(g)
Next
MyDrawObject.IsEnabled = TrueEndSubPrivateSub MyDrawObject_DrawComplete(sender AsObject, args As DrawEventArgs)
MyDrawObject.IsEnabled = FalseDim polyline As ESRI.ArcGIS.Client.Geometry.Polyline = TryCast(args.Geometry, ESRI.ArcGIS.Client.Geometry.Polyline)
polyline.SpatialReference = MyMap.SpatialReference
Dim geometryService AsNew GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer")
AddHandler geometryService.CutCompleted, AddressOf GeometryService_CutCompleted
AddHandler geometryService.Failed, AddressOf GeometryService_Failed
geometryService.CutAsync(parcelGraphicsLayer.Graphics.ToList(), polyline)
EndSubPrivateSub GeometryService_CutCompleted(sender AsObject, e As CutEventArgs)
parcelGraphicsLayer.ClearGraphics()
ForEach g As Graphic In e.Results
g.Symbol = TryCast(LayoutRoot.Resources("BlueFillSymbol"), ESRI.ArcGIS.Client.Symbols.Symbol)
parcelGraphicsLayer.Graphics.Add(g)
Next
MyDrawObject.IsEnabled = TrueEndSubPrivateSub GeometryService_Failed(sender AsObject, e As TaskFailedEventArgs)
MessageBox.Show("Geometry Service error: " & Convert.ToString(e.[Error]))
EndSubEndClassEndNamespace