ArcGIS Pro 3.1 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / GraphicFactory Class / CreateSimpleGraphic Method
The geometry for the resulting graphic
The symbol to be used with the graphic (optional)
Example

In This Topic
    CreateSimpleGraphic Method (GraphicFactory)
    In This Topic
    Creates a point, line, polygon or text graphic based on the input geometry and symbol. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public CIMGraphic CreateSimpleGraphic( 
       Geometry geometry,
       CIMSymbol symbol
    )
    Public Function CreateSimpleGraphic( _
       ByVal geometry As Geometry, _
       Optional ByVal symbol As CIMSymbol _
    ) As CIMGraphic

    Parameters

    geometry
    The geometry for the resulting graphic
    symbol
    The symbol to be used with the graphic (optional)

    Return Value

    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    empty or null geometry
    Example
    Create Circle Graphic
    //Must be on QueuedTask.Run(() => { ...
    
    //Build geometry
    Coordinate2D center = new Coordinate2D(2, 4);
    EllipticArcSegment circle_seg = EllipticArcBuilderEx.CreateCircle(
      new Coordinate2D(2, 4), 0.5, ArcOrientation.ArcClockwise, null);
    var circle_poly = PolygonBuilderEx.CreatePolygon(PolylineBuilderEx.CreatePolyline(circle_seg));
    
    //PolylineBuilderEx.CreatePolyline(cir, AttributeFlags.AllAttributes));
    //Set symbolology, create and add element to layout
    CIMStroke outline = SymbolFactory.Instance.ConstructStroke(
      ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Dash);
    
    CIMPolygonSymbol circleSym = SymbolFactory.Instance.ConstructPolygonSymbol(
      ColorFactory.Instance.RedRGB, SimpleFillStyle.Solid, outline);
    SymbolFactory.Instance.ConstructPolygonSymbol(null,
      SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.RedRGB, 2));
    
    var circleGraphic = GraphicFactory.Instance.CreateSimpleGraphic(circle_poly, circleSym);
    
    //Make an element to add to GraphicsLayer or Layout
    //var elemInfo = new ElementInfo() { Anchor = Anchor.CenterPoint };
    //GraphicElement cirElm = ElementFactory.Instance.CreateGraphicElement(
    //  container, circleGraphic, "New Circle", true, elemInfo);
    
    Create Arrow Graphic
    //Must be on QueuedTask.Run(() => { ...
    
    //Build geometry
    List<Coordinate2D> plCoords = new List<Coordinate2D>();
    plCoords.Add(new Coordinate2D(1, 8.5));
    plCoords.Add(new Coordinate2D(1.66, 9));
    plCoords.Add(new Coordinate2D(2.33, 8.1));
    plCoords.Add(new Coordinate2D(3, 8.5));
    Polyline linePl = PolylineBuilderEx.CreatePolyline(plCoords);
    
    //Set up the arrow info
    var arrowInfo = new ArrowInfo()
    {
      ArrowHeadKey = ArrowInfo.DefaultArrowHeadKeys[1],
      ArrowOnBothEnds = true,
      ArrowSizePoints = 30,
      LineWidthPoints = 15
    };
    
    var graphic = GraphicFactory.Instance.CreateArrowGraphic(linePl, arrowInfo);
    
    //Make an element to add to GraphicsLayer or Layout
    //var ge = ElementFactory.Instance.CreateGraphicElement(
    //  container, graphic, "Arrow Line", false);
    Create Point Element
    //Must be on QueuedTask.Run(() => { ...
    
    //Build geometry
    Coordinate2D coord2D = new Coordinate2D(2.0, 10.0);
    
    //Reference a point symbol in a style
    StyleProjectItem stylePrjItm = Project.Current.GetItems<StyleProjectItem>()
             .FirstOrDefault(item => item.Name == "ArcGIS 2D");
    SymbolStyleItem symStyleItm = stylePrjItm.SearchSymbols(
                          StyleItemType.PointSymbol, "City Hall")[0];
    CIMPointSymbol pointSym = symStyleItm.Symbol as CIMPointSymbol;
    pointSym.SetSize(50);
    
    var elemInfo = new ElementInfo()
    {
      CustomProperties = new List<CIMStringMap>() {
         new CIMStringMap() { Key = "Key1", Value = "Value1"},
         new CIMStringMap() { Key = "Key2", Value = "Value2"}
       },
      Anchor = Anchor.TopRightCorner,
      Rotation = 45.0
    };
    
    var graphic = GraphicFactory.Instance.CreateSimpleGraphic(
                                  coord2D.ToMapPoint(), pointSym);
    
    ElementFactory.Instance.CreateGraphicElement(
      container, graphic, "New Point", true, elemInfo);
    
    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 Graphic Elements
    //Must be on QueuedTask.Run(() => { ...
    
    //Build geometry
    List<Coordinate2D> plyCoords = new List<Coordinate2D>();
    plyCoords.Add(new Coordinate2D(1, 7));
    plyCoords.Add(new Coordinate2D(2, 7));
    plyCoords.Add(new Coordinate2D(2, 6.7));
    plyCoords.Add(new Coordinate2D(3, 6.7));
    plyCoords.Add(new Coordinate2D(3, 6.1));
    plyCoords.Add(new Coordinate2D(1, 6.1));
    Polygon poly = PolygonBuilderEx.CreatePolygon(plyCoords);
    
    //Build geometry
    Coordinate2D ll = new Coordinate2D(1.0, 4.75);
    Coordinate2D ur = new Coordinate2D(3.0, 5.75);
    Envelope env = EnvelopeBuilderEx.CreateEnvelope(ll, ur);
    
    //Build geometry
    Coordinate2D coord2D = new Coordinate2D(2.0, 10.0);
    
    var g1 = GraphicFactory.Instance.CreateSimpleGraphic(poly);
    var g2 = GraphicFactory.Instance.CreateSimpleGraphic(env);
    var g3 = GraphicFactory.Instance.CreateSimpleGraphic(coord2D.ToMapPoint());
    
    var ge = ElementFactory.Instance.CreateGraphicElements(
      container, new List<CIMGraphic>() { g1, g2, g3 },
      new List<string>() { "Poly", "Envelope", "MapPoint" },
      true);
    Create Graphic Element using CIMGraphic
    //on the QueuedTask
    //Place symbol on the layout
    //At 2.x - MapPoint location = MapPointBuilder.CreateMapPoint(
    //                                               new Coordinate2D(9, 1));
    MapPoint location = MapPointBuilderEx.CreateMapPoint(new Coordinate2D(9, 1));
    
    //specify a symbol
    var pt_symbol = SymbolFactory.Instance.ConstructPointSymbol(
                          ColorFactory.Instance.GreenRGB);
    
    //create a CIMGraphic 
    var graphic = new CIMPointGraphic()
    {
      Symbol = pt_symbol.MakeSymbolReference(),
      Location = location //center of map
    };
    //Or use GraphicFactory
    var graphic2 = GraphicFactory.Instance.CreateSimpleGraphic(location, pt_symbol);
    
    //At 2.x - LayoutElementFactory.Instance.CreateGraphicElement(layout, graphic);
    ElementFactory.Instance.CreateGraphicElement(container, graphic);
    ElementFactory.Instance.CreateGraphicElement(container, graphic2);
    Bulk Element creation
    //Must be on QueuedTask.Run(() => { ...
    
    //List of Point graphics
    var listGraphics = new List<CIMPointGraphic>();
    var listGraphics2 = new List<CIMPointGraphic>();
    //Symbol
    var pointSymbol = SymbolFactory.Instance.ConstructPointSymbol(
                                        ColorFactory.Instance.BlackRGB);
    //Define size of the array
    int dx = 5;
    int dy = 5;
    MapPoint point = null;
    //Create the List of graphics for the array
    for (int row = 0; row <= dx; ++row)
    {
      for (int col = 0; col <= dy; ++col)
      {
        //At 2.x - point = MapPointBuilder.CreateMapPoint(col, row);
        point = MapPointBuilderEx.CreateMapPoint(col, row);
        //create a CIMGraphic 
        var graphic = new CIMPointGraphic()
        {
          Symbol = pointSymbol.MakeSymbolReference(),
          Location = point
        };
        listGraphics.Add(graphic);
        //Or use GraphicFactory
        var graphic2 = GraphicFactory.Instance.CreateSimpleGraphic(
                                      point, pointSymbol) as CIMPointGraphic;
        listGraphics2.Add(graphic2);
      }
    }
    //Draw the array of graphics
    //At 2.x - var bulkgraphics =
    //              LayoutElementFactory.Instance.CreateGraphicElements(
    //                                              layout, listGraphics, null);
    
    var bulkgraphics = ElementFactory.Instance.CreateGraphicElements(
                                                       container, listGraphics);
    var bulkgraphics2 = ElementFactory.Instance.CreateGraphicElements(
                                                       container, listGraphics2);
    Translates a point in map coordinates to a point in page coordinates
    internal class GetMapCoordinates : MapTool
    {
      protected override void OnToolMouseDown(MapViewMouseButtonEventArgs e)
      {
        if (e.ChangedButton == System.Windows.Input.MouseButton.Left)
          e.Handled = true; //Handle the event args to get the call to the corresponding async method
      }
    
      protected override Task HandleMouseDownAsync(MapViewMouseButtonEventArgs e)
      {
        return QueuedTask.Run(() =>
        {
          var pointSymbol = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.BlackRGB, 8);
          var layout = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault().GetLayout();
          
          //Convert the clicked point in client coordinates to the corresponding map coordinates.
          var mapPoint = MapView.Active.ClientToMap(e.ClientPoint);
          ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(string.Format("X: {0} Y: {1} Z: {2}",
              mapPoint.X, mapPoint.Y, mapPoint.Z), "Map Coordinates");
          //Get the corresponding layout point
          var mapFrame = layout.FindElement("New Map Frame") as MapFrame;
          var pointOnLayoutFrame = mapFrame.MapToPage(mapPoint);
    
          //Create a point graphic on the Layout.
          var cimGraphicElement = new CIMPointGraphic
          {
            Location = pointOnLayoutFrame,
            Symbol = pointSymbol.MakeSymbolReference()
          };
          //Or use GraphicFactory
          var cimGraphicElement2 = GraphicFactory.Instance.CreateSimpleGraphic(
                  pointOnLayoutFrame, pointSymbol);
    
          //At 2.x - LayoutElementFactory.Instance.CreateGraphicElement(layout, cimGraphicElement);
    
          ElementFactory.Instance.CreateGraphicElement(layout, cimGraphicElement);
          ElementFactory.Instance.CreateGraphicElement(layout, cimGraphicElement2);
    
        });
        
      }
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.0 or higher.
    See Also