ArcGIS Pro 3.0 API Reference Guide
ArcGIS.Core.Geometry Namespace / EnvelopeBuilderEx Class / CreateEnvelope Method / CreateEnvelope(EnvelopeBuilderEx,SpatialReference) Method
The builder to create the envelope.
(Optional) The SpatialReference. The default value is null. If the input spatial reference is null, then the spatial reference from the input builder is used.
Example

In This Topic
    CreateEnvelope(EnvelopeBuilderEx,SpatialReference) Method
    In This Topic
    Convenience method to create a new instance of the Envelope class.
    Syntax
    Public Overloads Shared Function CreateEnvelope( _
       ByVal envelopeBuilderEx As EnvelopeBuilderEx, _
       Optional ByVal spatialReference As SpatialReference _
    ) As Envelope

    Parameters

    envelopeBuilderEx
    The builder to create the envelope.
    spatialReference
    (Optional) The SpatialReference. The default value is null. If the input spatial reference is null, then the spatial reference from the input builder is used.
    Exceptions
    ExceptionDescription
    envelopeBuilderEx is null.
    Example
    Create_polygon_env
    //Create a polygon graphic using an envelope with simple line and fill styles.
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build 2D envelope
      Coordinate2D env_ll = new Coordinate2D(1.0, 4.75);
      Coordinate2D env_ur = new Coordinate2D(3.0, 5.75);
      //At 2.x - Envelope env = EnvelopeBuilder.CreateEnvelope(env_ll, env_ur);
      Envelope env = EnvelopeBuilderEx.CreateEnvelope(env_ll, env_ur);
    
      //Set symbolology, create and add element to layout
      CIMStroke outline = SymbolFactory.Instance.ConstructStroke(
        ColorFactory.Instance.BlueRGB, 2.0, SimpleLineStyle.DashDotDot);
      CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(
        ColorFactory.Instance.RedRGB, SimpleFillStyle.ForwardDiagonal, outline);
      //At 2.x - GraphicElement polyElm =
      //            LayoutElementFactory.Instance.CreatePolygonGraphicElement(layout, env, polySym);
      //         polyElm.SetName("New Polygon");
      GraphicElement polyElm = ElementFactory.Instance.CreateGraphicElement(
        layout, env, polySym, "New Polygon");
    });
    Create_MapFrame
    //Creates a new map frame and changes the camera's scale.
    
    //Constuct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build geometry
      Coordinate2D ll = new Coordinate2D(6.0, 8.5);
      Coordinate2D ur = new Coordinate2D(8.0, 10.5);
      //At 2.x - Envelope env = EnvelopeBuilder.CreateEnvelope(ll, ur);
      Envelope env = EnvelopeBuilderEx.CreateEnvelope(ll, ur);
    
      //Reference map, create MF and add to layout
      MapProjectItem mapPrjItem = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(item => item.Name.Equals("Map"));
      Map mfMap = mapPrjItem.GetMap();
      //At 2.x - mfElm = LayoutElementFactory.Instance.CreateMapFrame(layout, env, mfMap);
      //         mfElm.SetName("New Map Frame"); 
      mfElm = ElementFactory.Instance.CreateMapFrameElement(layout, env, mfMap, "New Map Frame");
    
      //Set the camera
      Camera camera = mfElm.Camera;
      camera.Scale = 24000;
      mfElm.SetCamera(camera);
    });
    Create Rectangle Element
    //Must be on QueuedTask.Run(() => { ...
    
    //Build geometry
    Coordinate2D ll = new Coordinate2D(1.0, 4.75);
    Coordinate2D ur = new Coordinate2D(3.0, 5.75);
    Envelope env = EnvelopeBuilderEx.CreateEnvelope(ll, ur);
    
    //Set symbolology, create and add element to layout
    CIMStroke outline = SymbolFactory.Instance.ConstructStroke(
      ColorFactory.Instance.BlackRGB, 5.0, SimpleLineStyle.Solid);
    CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(
      ColorFactory.Instance.GreenRGB, SimpleFillStyle.DiagonalCross, outline);
    
    var ge = GraphicFactory.Instance.CreateSimpleGraphic(env, polySym);
    var elemInfo = new ElementInfo()
    {
      Anchor = Anchor.CenterPoint,
      Rotation = 45.0,
      CornerRounding = 5.0
    };
    
    ElementFactory.Instance.CreateGraphicElement(
      container, env, polySym, "New Rectangle", false, elemInfo);
    Create rectangle graphic with simple symbology
    //Create a simple 2D rectangle graphic and apply simple fill and
    //outline symbols.
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build 2D envelope geometry
      Coordinate2D rec_ll = new Coordinate2D(1.0, 4.75);
      Coordinate2D rec_ur = new Coordinate2D(3.0, 5.75);
      //At 2.x - Envelope rec_env = EnvelopeBuilder.CreateEnvelope(rec_ll, rec_ur);
      Envelope rec_env = EnvelopeBuilderEx.CreateEnvelope(rec_ll, rec_ur);
    
      //Set symbolology, create and add element to layout
      CIMStroke outline = SymbolFactory.Instance.ConstructStroke(
        ColorFactory.Instance.BlackRGB, 5.0, SimpleLineStyle.Solid);
      CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(
        ColorFactory.Instance.GreenRGB, SimpleFillStyle.DiagonalCross, outline);
    
      //At 2.x - GraphicElement recElm =
      //           LayoutElementFactory.Instance.CreateRectangleGraphicElement(
      //                                                  layout, rec_env, polySym);
      //         recElm.SetName("New Rectangle");
      //
      GraphicElement recElm = ElementFactory.Instance.CreateGraphicElement(
        container, rec_env, polySym, "New Rectangle");
      //Or use Predefined shape
      GraphicElement recElm2 = ElementFactory.Instance.CreatePredefinedShapeGraphicElement(
                                container, PredefinedShape.Rectangle, rec_env, polySym, 
                                "New Rectangle2");
    });
    Create Point Text Element 1
    //Create a simple point text element and assign basic symbology and text settings.
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build 2D point geometry
      Coordinate2D coord2D = new Coordinate2D(3.5, 10);
    
      //Set symbolology, create and add element to layout
      CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(
                    ColorFactory.Instance.RedRGB, 32, "Arial", "Regular");
      string textString = "Point text";
      //At 2.x - GraphicElement ptTxtElm =
      //         LayoutElementFactory.Instance.CreatePointTextGraphicElement(
      //                           layout, coord2D, textString, sym);
      //ptTxtElm.SetName("New Point Text");
      //ptTxtElm.SetAnchor(Anchor.CenterPoint);
      //ptTxtElm.SetX(4.5);
      //ptTxtElm.SetY(9.5);
      //ptTxtElm.SetRotation(45);
    
      //use ElementInfo to set placement properties during create
      var elemInfo = new ElementInfo()
      {
        Anchor = Anchor.CenterPoint,
        Rotation = 45
      };
      var ptTxtElm = ElementFactory.Instance.CreateTextGraphicElement(
        container, TextType.PointText, coord2D.ToMapPoint(), sym, textString,
                           "New Point Text", true, elemInfo);
    
      //Change additional text properties
      ptTxtElm.SetX(4.5);
      ptTxtElm.SetY(9.5);
    });
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 8.1

    See Also