ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.Geometry Namespace / PolylineBuilderEx Class / CreatePolyline Method / CreatePolyline(IEnumerable<Segment>,SpatialReference) Method
Segments to create the polyline. The spatial references of the segments are checked for compatibility.
(Optional) The SpatialReference. The default value is null. If spatialReference is null, then the spatial reference will be inherited from segments which requires traversing through the enumeration of segments. For improved performance or if you want to set these properties yourself, use CreatePolyline(IEnumerable<Segment>,AttributeFlags,SpatialReference).
Example

In This Topic
    CreatePolyline(IEnumerable<Segment>,SpatialReference) Method
    In This Topic
    Convenience method to create a new instance of the Polyline class.
    Syntax
    Public Overloads Shared Function CreatePolyline( _
       ByVal segments As IEnumerable(Of Segment), _
       Optional ByVal spatialReference As SpatialReference _
    ) As Polyline

    Parameters

    segments
    Segments to create the polyline. The spatial references of the segments are checked for compatibility.
    spatialReference
    (Optional) The SpatialReference. The default value is null. If spatialReference is null, then the spatial reference will be inherited from segments which requires traversing through the enumeration of segments. For improved performance or if you want to set these properties yourself, use CreatePolyline(IEnumerable<Segment>,AttributeFlags,SpatialReference).

    Return Value

    Exceptions
    ExceptionDescription
    Incompatible spatial references.
    segments is null.
    Remarks
    The HasZ, HasM and HasID properties are inherited from segments which requires traversing through the enumeration of segments. For improved performance or if you want to set these properties yourself, use CreatePolyline(IEnumerable<Segment>,AttributeFlags,SpatialReference).
    Example
    Get the segments of a Polyline
    {
      ICollection<Segment> collectionSegments = new List<Segment>();
      polyline.GetAllSegments(ref collectionSegments);
      int numSegmentsInCollection = collectionSegments.Count;    // = 10
    
      IList<Segment> iList = collectionSegments as IList<Segment>;
      for (int i = 0; i < numSegmentsInCollection; i++)
      {
        // do something with iList[i]
      }
    
      // use the segments to build another polyline
      Polyline polylineFromSegments = PolylineBuilderEx.CreatePolyline(collectionSegments);
    }
    Construct a Polyline - from a Cubic Bezier
    {
      polyline = PolylineBuilderEx.CreatePolyline(bezierSegment);
    }
    Create Bezier Curve Element
    {
      //Note: Must be on QueuedTask.Run
      //Build geometry
      Coordinate2D pt1 = new Coordinate2D(1, 7.5);
      Coordinate2D pt2 = new Coordinate2D(1.66, 8);
      Coordinate2D pt3 = new Coordinate2D(2.33, 7.1);
      Coordinate2D pt4 = new Coordinate2D(3, 7.5);
      var bez = new CubicBezierBuilderEx(pt1, pt2, pt3, pt4);
      var bezSeg = bez.ToSegment();
      Polyline bezPl = PolylineBuilderEx.CreatePolyline(bezSeg, AttributeFlags.AllAttributes);
    
      //Set symbology, create and add element to layout
      CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(
        ColorFactory.Instance.RedRGB, 4.0, SimpleLineStyle.DashDot);
    
      ElementFactory.Instance.CreateGraphicElement(layout, bezPl, lineSym, "New Bezier");
    }
    Create Lasso Line, Freehand Graphic Element
    {
      //Note: Must be on QueuedTask.Run
      //Build geometry
      List<Coordinate2D> plCoords = new List<Coordinate2D>();
      plCoords.Add(new Coordinate2D(1.5, 10.5));
      plCoords.Add(new Coordinate2D(1.25, 9.5));
      plCoords.Add(new Coordinate2D(1, 10.5));
      plCoords.Add(new Coordinate2D(0.75, 9.5));
      plCoords.Add(new Coordinate2D(0.5, 10.5));
      plCoords.Add(new Coordinate2D(0.5, 1));
      plCoords.Add(new Coordinate2D(0.75, 2));
      plCoords.Add(new Coordinate2D(1, 1));
      Polyline linePl = PolylineBuilderEx.CreatePolyline(plCoords);
    
      //Set symbology, create and add element to layout
      CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(
                ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Solid);
      //var graphic = GraphicFactory.Instance.CreateShapeGraphic(linePl, lineSym);
    
      var ge = ElementFactory.Instance.CreateGraphicElement(
                              layout, linePl, lineSym, "New Freehand");
    }
    Create Line Element
    {
      //Note: 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);
    
      //Reference a line symbol in a style
      var ProjectStyles = Project.Current.GetItems<StyleProjectItem>();
      StyleProjectItem style = ProjectStyles.First(x => x.Name == "ArcGIS 2D");
      var symStyle = style.SearchSymbols(StyleItemType.LineSymbol, "Line with 2 Markers")[0];
      CIMLineSymbol lineSym = symStyle.Symbol as CIMLineSymbol;
      lineSym.SetSize(20);
    
      //Set symbology, create and add element to layout
      //CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlueRGB, 4.0, SimpleLineStyle.Solid);
      ElementFactory.Instance.CreateGraphicElement(
        layout, linePl, lineSym, "New Line");
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also