How to find the combined extent of two geometries (ArcObjects .NET 10.6 SDK)
ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Managing data > Working with geometry > Modifying geometries > How to find the combined extent of two geometries (ArcObjects .NET 10.6 SDK)

How to find the combined extent of two geometries


Finding the combined extent of two geometries

Do the following steps to find the combined extent of two geometries:
  1. Get the envelopes for each geometry.
  2. Union the two envelopes. The output is the combined extent of the two geometries.
The following code example shows an easy way to determine the spatial extent of the union of two geometries:
[C#]
private void Union(IGeometry geometry1, IGeometry geometry2)
{
    if (geometry1 == null || geometry2 == null)
    {
        //Geometries are null.
        return ;
    }

    IEnvelope envelope1=geometry1.Envelope;
    IEnvelope envelope2=geometry2.Envelope;

    //Envelope1 is modified to become the union of the extents of geometry1 and geometry2.
    envelope1.Union(envelope2);
    String report="LowerLeft  X=" + envelope1.LowerLeft.X + "\n" + 
        "LowerLeft  Y=" + envelope1.LowerLeft.Y + "\n\n" + "LowerRight X=" +
        envelope1.LowerRight.X + "\n" + "LowerRight Y=" + envelope1.LowerRight.Y +
        "\n\n" + "UpperLeft  X=" + envelope1.UpperLeft.X + "\n" + 
        "UpperLeft  Y=" + envelope1.UpperLeft.Y + "\n\n" + "UpperRight X=" +
        envelope1.UpperRight.X + "\n" + "UpperRight Y=" + envelope1.UpperRight.Y;

    System.Windows.Forms.MessageBox.Show(report);
}
[VB.NET]
Private Sub Union(ByVal geometry1 As IGeometry, ByVal geometry2 As IGeometry)
    If geometry1 Is Nothing Or geometry2 Is Nothing Then
        'Geometries are null.
        Exit Sub
    End If
    
    Dim envelope1 As IEnvelope=geometry1.Envelope
    Dim envelope2 As IEnvelope=geometry2.Envelope
    
    'Envelope1 is modified to become the union of the extents of geometry1 and geometry2.
    envelope1.Union(envelope2)
    
    Dim report As String="LowerLeft X=" & envelope1.LowerLeft.X & ControlChars.NewLine & _
                           "LowerLeft Y=" & envelope1.LowerLeft.Y & ControlChars.NewLine & _
                           "LowerRight X=" & envelope1.LowerRight.X & ControlChars.NewLine & _
                           "LowerRight Y=" & envelope1.LowerRight.Y & ControlChars.NewLine & _
                           "UpperLeft X=" & envelope1.UpperLeft.X & ControlChars.NewLine & _
                           "UpperLeft Y=" & envelope1.UpperLeft.Y & ControlChars.NewLine & _
                           "UpperRight X=" & envelope1.UpperRight.X & ControlChars.NewLine & _
                           "UpperRight Y=" & envelope1.UpperRight.Y
    Windows.Forms.MessageBox.Show(report)
End Sub






To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
ArcGIS Desktop Basic ArcGIS Desktop Basic
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Advanced ArcGIS Desktop Advanced
Engine Developer Kit Engine