ArcGIS Pro 3.0 API Reference Guide
ArcGIS.Core.Geometry Namespace / EnvelopeBuilderEx Class / CreateEnvelope Method / CreateEnvelope(MapPoint,MapPoint,SpatialReference) Method
Lower left corner of the envelope.
Upper right corner of the envelope.
(Optional) The SpatialReference. The default value is null. The spatial reference of each point is ignored.
Example

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

    Parameters

    minPoint
    Lower left corner of the envelope.
    maxPoint
    Upper right corner of the envelope.
    spatialReference
    (Optional) The SpatialReference. The default value is null. The spatial reference of each point is ignored.

    Return Value

    Exceptions
    ExceptionDescription
    minPoint or maxPoint is null.
    Remarks
    The spatial references of the two points must be the same or null.The spatial references of the input points are ignored. There is no check to see if the spatial references are equal. If either point has coordinates that are outside the domain of the spatial reference, then unexpected results will occur when using the geometry.

    The resulting envelope is normalized to ensure its XMin <= XMax, YMin <= YMax, ZMin <= ZMax and MMin <= MMax. If either of the xy-coordinate values are NaN, then the envelope is set to empty.

    The resulting envelope inherits attributes, Z, M and ID-values, from the input points. For example, if either minPoint or maxPoint HasZ property is true, then the envelope's HasZ property is true.

    Example
    Construct a Polygon - from an Envelope
    // Use a builderEx convenience method or use a builderEx constructor.
    
    MapPoint minPt = MapPointBuilderEx.CreateMapPoint(1.0, 1.0);
    MapPoint maxPt = MapPointBuilderEx.CreateMapPoint(2.0, 2.0);
    
    // Create an envelope
    Envelope env = EnvelopeBuilderEx.CreateEnvelope(minPt, maxPt);
    
    Polygon polygonFromEnv = PolygonBuilderEx.CreatePolygon(env);
    
    PolygonBuilderEx polygonBuilderEx = new PolygonBuilderEx(env);
    polygonBuilderEx.SpatialReference = SpatialReferences.WGS84;
    polygonFromEnv = polygonBuilderEx.ToGeometry() as Polygon;
    
    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