ArcGIS Runtime .NET SDK (Windows Desktop)

GeometryEngineIntersection Method |

Constructs the set-theoretic intersection between two geometries.

Syntax

- geometry1
- Type: Esri.ArcGISRuntime.GeometryGeometry

The first geometry. - geometry2
- Type: Esri.ArcGISRuntime.GeometryGeometry

The second geometry of dimension equal to or greater than the elements of the first geometry.

A geometry that represents the intersection of the two input geometries.

Remarks

GeometryEngine.Intersection returns those parts of the two input geometries that have things in common. This means that the
order of the input parameters of the GeometryEngine.Intersection is irrelevant. In a theoretical variable format
you can think of the GeometryEngine.Intersection equation like:

A (Intersection) B = C

B (Intersection) A = C

The following is a visual illustration of two polygon geometries and how the output result would be from the GeometryEngine.Intersection operation:

Examples

Demonstrates using the powerful GeometryEngine local process to perform the spatial analysis operations of Difference, Intersection, and Union on two input geometries.

XAML

<Window x:Class="GeometryEngine_Difference_Intersection_Union.MainWindow" 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/runtime/2013" Title="MainWindow" Height="600" Width="800"> <Grid> <StackPanel x:Name="StackPanel1" Orientation="Vertical"> <!-- TextBlock to hold the instructions on how to use the sample code. --> <TextBlock Height="74" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="775" TextWrapping="Wrap" Margin="7,0,0,0" /> <!-- Add 2 MapViews each with a GraphicsLayer. --> <StackPanel x:Name="StackPanel_Maps" Orientation="Horizontal"> <esri:MapView x:Name="MapView1" Height="390" Width="390" BorderBrush="Black" BorderThickness="2"> <esri:Map > <esri:GraphicsLayer x:Name="MyPolygonGraphicsLayer1" /> </esri:Map> </esri:MapView> <esri:MapView x:Name="MapView2" Height="390" Width="390" BorderBrush="Black" BorderThickness="2"> <esri:Map > <esri:GraphicsLayer x:Name="MyPolygonGraphicsLayer2" /> </esri:Map> </esri:MapView> </StackPanel> <!-- Add another StackPanel for the buttons a user can push to demonstrate using various GeometryEngine operations (Difference, Intersection, Union). --> <StackPanel x:Name="StackPanel2" Orientation="Horizontal" HorizontalAlignment="Center"> <Button x:Name="Button_Difference" Content="Difference" Click="Button_Difference_Click" Margin="3,3" FontSize="18" Foreground="Red" FontWeight="Bold"/> <Button x:Name="Button_Intersection" Content="Intersection" Click="Button_Intersection_Click" Margin="3,3" FontSize="18" Foreground="Green" FontWeight="Bold"/> <Button x:Name="Button_Union" Content="Union" Click="Button_Union_Click" Margin="3,3" FontSize="18" Foreground="Black" FontWeight="Bold"/> </StackPanel> </StackPanel> </Grid> </Window>

**SPECIAL NOTE:** The XAML displayed above comes from a C# project. If you are a VB.NET developer,
you will need to modify the text for the x:Class namespace from "GeometryEngine_Difference_Intersection_Union.MainWindow" to be just "MainWindow".

namespace GeometryEngine_Difference_Intersection_Union { public partial class MainWindow : System.Windows.Window { public MainWindow() { InitializeComponent(); // Add instructions on how to use the sample. TextBlock1.Text = "When the application loads two polygon geometries will be drawn that overlap in the left MapView. Click the various buttons" + " to see effect of the various GeometryEngine Methods (Difference, Intersection, and Union) that will be displayed in the right MapView."; // Define a fictitious initial extent for the two Map's. Esri.ArcGISRuntime.Geometry.Envelope myEnvelope = new Esri.ArcGISRuntime.Geometry.Envelope(0, 0, 10, 10); MapView1.Map.InitialViewpoint = new Esri.ArcGISRuntime.Controls.Viewpoint(myEnvelope); MapView2.Map.InitialViewpoint = new Esri.ArcGISRuntime.Controls.Viewpoint(myEnvelope); // The Map control typically gets it's SpatialReference from the 1st layer that is added to the Map's LayerCollection. // In this unique case, only an empty GraphicsLayer (without any defined SpatialReference) was added to the Map's // LayerCollection and hence the Map controls did not have any SpatialReference set. We will manually set the Map's // SpatialReference with the next line of code, so that graphics can be drawn. MapView1.Map.SpatialReference = Esri.ArcGISRuntime.Geometry.SpatialReferences.WebMercator; MapView2.Map.SpatialReference = Esri.ArcGISRuntime.Geometry.SpatialReferences.WebMercator; // Draw the 1st polygon graphic in MapView1. // ----------------------------------------- //Define a list of MapPoint's (the basic building blocks of a polygons shape). System.Collections.Generic.List<Esri.ArcGISRuntime.Geometry.MapPoint> myListOfMapPoints = new System.Collections.Generic.List<Esri.ArcGISRuntime.Geometry.MapPoint>(); myListOfMapPoints.Add(new Esri.ArcGISRuntime.Geometry.MapPoint(3, 3)); myListOfMapPoints.Add(new Esri.ArcGISRuntime.Geometry.MapPoint(5, 6.25)); myListOfMapPoints.Add(new Esri.ArcGISRuntime.Geometry.MapPoint(7, 3)); // Create a new Polygon geometry using the List of MapPoints in the defined SpatialReference as the map control. Esri.ArcGISRuntime.Geometry.Polygon myPolygon = new Esri.ArcGISRuntime.Geometry.Polygon(myListOfMapPoints, new Esri.ArcGISRuntime.Geometry.SpatialReference(102100)); // Define a basic fill symbol for the polygon. Esri.ArcGISRuntime.Symbology.SimpleFillSymbol myFillSymbol = new Esri.ArcGISRuntime.Symbology.SimpleFillSymbol(); myFillSymbol.Style = Esri.ArcGISRuntime.Symbology.SimpleFillStyle.Null; Esri.ArcGISRuntime.Symbology.SimpleLineSymbol myOutline = new Esri.ArcGISRuntime.Symbology.SimpleLineSymbol(); myOutline.Color = System.Windows.Media.Colors.Blue; myOutline.Style = Esri.ArcGISRuntime.Symbology.SimpleLineStyle.Solid; myOutline.Width = 2; myFillSymbol.Outline = myOutline; // Create a new graphic and set it's geometry and symbol. Esri.ArcGISRuntime.Layers.Graphic myGraphic = new Esri.ArcGISRuntime.Layers.Graphic(); myGraphic.Geometry = myPolygon; myGraphic.Symbol = myFillSymbol; // Add the graphic to the graphics collection. This will cause the graphic to draw in the map. MyPolygonGraphicsLayer1.Graphics.Add(myGraphic); // Draw the 2nd polygon graphic in MapView1. // ----------------------------------------- //Define a list of MapPoint's (the basic building blocks of a polygons shape). System.Collections.Generic.List<Esri.ArcGISRuntime.Geometry.MapPoint> myListOfMapPoints2 = new System.Collections.Generic.List<Esri.ArcGISRuntime.Geometry.MapPoint>(); myListOfMapPoints2.Add(new Esri.ArcGISRuntime.Geometry.MapPoint(3, 5)); myListOfMapPoints2.Add(new Esri.ArcGISRuntime.Geometry.MapPoint(7, 5)); myListOfMapPoints2.Add(new Esri.ArcGISRuntime.Geometry.MapPoint(5, 1.75)); // Create a new Polygon geometry using the List of MapPoints in the defined SpatialReference as the map control. Esri.ArcGISRuntime.Geometry.Polygon myPolygon2 = new Esri.ArcGISRuntime.Geometry.Polygon(myListOfMapPoints2, new Esri.ArcGISRuntime.Geometry.SpatialReference(102100)); // Define a basic fill symbol for the polygon. Esri.ArcGISRuntime.Symbology.SimpleFillSymbol myFillSymbol2 = new Esri.ArcGISRuntime.Symbology.SimpleFillSymbol(); myFillSymbol2.Style = Esri.ArcGISRuntime.Symbology.SimpleFillStyle.Null; Esri.ArcGISRuntime.Symbology.SimpleLineSymbol myOutline2 = new Esri.ArcGISRuntime.Symbology.SimpleLineSymbol(); myOutline2.Color = System.Windows.Media.Colors.Cyan; myOutline2.Style = Esri.ArcGISRuntime.Symbology.SimpleLineStyle.Solid; myOutline2.Width = 2; myFillSymbol2.Outline = myOutline2; // Create a new graphic and set it's geometry and symbol. Esri.ArcGISRuntime.Layers.Graphic myGraphic2 = new Esri.ArcGISRuntime.Layers.Graphic(); myGraphic2.Geometry = myPolygon2; myGraphic2.Symbol = myFillSymbol2; // Add the graphic to the graphics collection. This will cause the graphic to draw in the map. MyPolygonGraphicsLayer1.Graphics.Add(myGraphic2); } private void Button_Difference_Click(object sender, System.Windows.RoutedEventArgs e) { DrawGeometry("Difference", System.Windows.Media.Colors.Red); } private void Button_Intersection_Click(object sender, System.Windows.RoutedEventArgs e) { DrawGeometry("Intersection", System.Windows.Media.Colors.Green); } private void Button_Union_Click(object sender, System.Windows.RoutedEventArgs e) { DrawGeometry("Union", System.Windows.Media.Colors.Black); } public void DrawGeometry(string theSpatialOperation, System.Windows.Media.Color theColor) { // A custom function to perform various GeometryEngine spatial operations (Difference, Intersection, Union) and draw the result in the 2nd MapView. // Clear out any graphics in the 2nd MapView. MyPolygonGraphicsLayer2.Graphics.Clear(); // Get the graphics in MapView1. Esri.ArcGISRuntime.Layers.GraphicCollection myGraphicCollection = MyPolygonGraphicsLayer1.Graphics; // Get the 1st graphic and geometry from the GraphicCollection. Esri.ArcGISRuntime.Layers.Graphic Graphic1 = myGraphicCollection[0]; Esri.ArcGISRuntime.Geometry.Geometry myGeometry1 = Graphic1.Geometry; // Get the 2nd graphic and geometry from the GraphicCollection. Esri.ArcGISRuntime.Layers.Graphic Graphic2 = myGraphicCollection[1]; Esri.ArcGISRuntime.Geometry.Geometry myGeometry2 = Graphic2.Geometry; // Create a new geometry to hold the results of the GeometryEngine operation. Esri.ArcGISRuntime.Geometry.Geometry theGeometry = null; // Branch the logic to perform the correct GeometryEngine operation based upon the user choice. if (theSpatialOperation == "Difference") { // GeometryEngine.Difference performs a spatial subtraction from the two input geometries. This means that the order of the two input geometry // arguments of the GeometryEngine.Difference Static Method will have different results if they are switched. In a theoretical variable format // you can think of the GeometryEngine.Difference equation like: // A (Difference) B = C // B (Difference) A = D // This gives one version of the GeometryEngine.Difference operation. theGeometry = Esri.ArcGISRuntime.Geometry.GeometryEngine.Difference(myGeometry1, myGeometry2); // Uncomment the next line and comment out the line above to get a very different 'Difference' result. //theGeometry = Esri.ArcGISRuntime.Geometry.GeometryEngine.Difference(myGeometry2, myGeometry1); // NOTE: If you were looking for the "complete" difference between two geometries you will need to run the GeometryEngine.Difference // twice by switching the order of the input arguments and then add the two resultant geometries together (most likely via the // GeometryEngine.Union Static Method). This "complete" difference means that you would be interested in obtaining those parts of the two input // geometries that have nothing in common. In a theoretical variable format to get the "complete" different between two geometries you can think // of the the GeometryEngine.Difference equation like: // [A (Difference) B] + [B (Difference) A] = Complete Difference // If you are interested to see the "complete" different between myGeometry1 and myGeometry2 you could do something like the following // three lines of code: //Esri.ArcGISRuntime.Geometry.Geometry Difference1 = Esri.ArcGISRuntime.Geometry.GeometryEngine.Difference(myGeometry1, myGeometry2); //Esri.ArcGISRuntime.Geometry.Geometry Difference2 = Esri.ArcGISRuntime.Geometry.GeometryEngine.Difference(myGeometry2, myGeometry1); //theGeometry = Esri.ArcGISRuntime.Geometry.GeometryEngine.Union(Difference1, Difference2); } else if (theSpatialOperation == "Intersection") { // GeometryEngine.Intersection returns those parts of the two input geometries that have things in common. This means that the // order of the input parameters of the GeometryEngine.Intersection is irrelevant. In a theoretical variable format // you can think of the GeometryEngine.Intersection equation like: // A (Intersection) B = C // B (Intersection) A = C theGeometry = Esri.ArcGISRuntime.Geometry.GeometryEngine.Intersection(myGeometry1, myGeometry2); } else if (theSpatialOperation == "Union") { // GeometryEngine.Union returns all parts of the two input geometries as combined into a single geometry. This means that the // order of the input parameters of the GeometryEngine.Intersection is irrelevant. In a theoretical variable format // you can think of the GeometryEngine.Union equation like: // A (Union) B = C // B (Union) A = C theGeometry = Esri.ArcGISRuntime.Geometry.GeometryEngine.Union(myGeometry1, myGeometry2); } // Define a basic fill symbol for the polygon. Esri.ArcGISRuntime.Symbology.SimpleFillSymbol myFillSymbol = new Esri.ArcGISRuntime.Symbology.SimpleFillSymbol(); myFillSymbol.Style = Esri.ArcGISRuntime.Symbology.SimpleFillStyle.Solid; myFillSymbol.Color = theColor; // Use the color the user specified. // Create a new graphic and set it's geometry and symbol. Esri.ArcGISRuntime.Layers.Graphic myGraphic = new Esri.ArcGISRuntime.Layers.Graphic(); myGraphic.Geometry = theGeometry; myGraphic.Symbol = myFillSymbol; // Add the graphic to the graphics collection in the MapView2. This will cause the graphic to draw in the map. MyPolygonGraphicsLayer2.Graphics.Add(myGraphic); } } }

See Also

Supported Platforms

This type is supported on the following ArcGIS Runtime .NET SDK platforms: |
---|

Windows Desktop |

Windows Phone |

Windows Store |

Additional Examples

Hyperlink to Example | Description |
---|---|

GeometryEngine_Difference_Intersection_Union | Demonstrates using the powerful GeometryEngine local process to perform the spatial analysis operations of Difference, Intersection, and Union on two input geometries. |