ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Core.Geometry Namespace / PolylineBuilderEx Class / CreatePolyline Method / CreatePolyline(IEnumerable<MapPoint>,AttributeFlags,SpatialReference) Method
Points to create the polyline. Line segments are created from the coordinates of the points.
AttributeFlags to set the HasZ, HasM and HasID attributes. If no attributes should be set, pass AttributeFlags.None. If all attributes should be set, pass AttributeFlags.AllAttributes. Use the bitwise OR operator to set two attributes. For example, to set HasZ = true and HasM = true, pass AttributeFlags.HasZ | AttributeFlags.HasM. For performance reasons, the attributes of the input points are not used. However, if an attribute is specified, then the attribute values of the input points is used. For example, if AttributeFlags.HasZ is specified, then the Z-values of the input points is used for the newly created polyline.
(Optional) The SpatialReference. The default value is null. For performance reasons, the spatial references of the input points are ignored.
Example

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

    Parameters

    points
    Points to create the polyline. Line segments are created from the coordinates of the points.
    attributes
    AttributeFlags to set the HasZ, HasM and HasID attributes. If no attributes should be set, pass AttributeFlags.None. If all attributes should be set, pass AttributeFlags.AllAttributes. Use the bitwise OR operator to set two attributes. For example, to set HasZ = true and HasM = true, pass AttributeFlags.HasZ | AttributeFlags.HasM. For performance reasons, the attributes of the input points are not used. However, if an attribute is specified, then the attribute values of the input points is used. For example, if AttributeFlags.HasZ is specified, then the Z-values of the input points is used for the newly created polyline.
    spatialReference
    (Optional) The SpatialReference. The default value is null. For performance reasons, the spatial references of the input points are ignored.

    Return Value

    Exceptions
    ExceptionDescription
    points is null.
    Example
    Builder Properties
    {
      // list of points
      List<MapPoint> pointsForBuilder = new List<MapPoint>
    {
      MapPointBuilderEx.CreateMapPoint(0, 0, 2, 3, 1),
      MapPointBuilderEx.CreateMapPoint(1, 1, 5, 6),
      MapPointBuilderEx.CreateMapPoint(2, 1, 6),
      MapPointBuilderEx.CreateMapPoint(0, 0)
    };
    
      // will have attributes because it is created with convenience method
      Polyline polylineWithAttrs = PolylineBuilderEx.CreatePolyline(pointsForBuilder);
      bool hasZ = polylineWithAttrs.HasZ;          // hasZ = true
      bool hasM = polylineWithAttrs.HasM;          // hasM = true
      bool hasID = polylineWithAttrs.HasID;        // hasID = true
    
      // will not have attributes because it is specified as a parameter
      Polyline polylineWithoutAttrs =
        PolylineBuilderEx.CreatePolyline(pointsForBuilder, AttributeFlags.None);
      hasZ = polylineWithoutAttrs.HasZ;          // hasZ = false
      hasM = polylineWithoutAttrs.HasM;          // hasM = false
      hasID = polylineWithoutAttrs.HasID;        // hasID = false
    
      // will have attributes because it is created with convenience method
      Polygon polygonWithAttrs = PolygonBuilderEx.CreatePolygon(pointsForBuilder);
      hasZ = polygonWithAttrs.HasZ;               // hasZ = true
      hasM = polygonWithAttrs.HasM;               // hasM = true
      hasID = polygonWithAttrs.HasID;             // hasID = true
    
      // will not have attributes because it is specified as a parameter
      Polygon polygonWithoutAttrs =
            PolygonBuilderEx.CreatePolygon(pointsForBuilder, AttributeFlags.None);
      hasZ = polygonWithoutAttrs.HasZ;               // hasZ = false
      hasM = polygonWithoutAttrs.HasM;               // hasM = false
      hasID = polygonWithoutAttrs.HasID;             // hasID = false
    
      // will not have attributes because it is specified as a parameter
      PolylineBuilderEx polylineB =
                 new PolylineBuilderEx(pointsForBuilder, AttributeFlags.None);
      hasZ = polylineB.HasZ;                      // hasZ = false
      hasM = polylineB.HasM;                      // hasM = false
      hasID = polylineB.HasID;                    // hasID = false
    
      // will have attributes because it is passed an attributed polyline
      polylineB = new PolylineBuilderEx(polylineWithAttrs);
      hasZ = polylineB.HasZ;                      // hasZ = true
      hasM = polylineB.HasM;                      // hasM = true
      hasID = polylineB.HasID;                    // hasID = true
    
      // will not have attributes because it is passed a non-attributed polyline
      polylineB = new PolylineBuilderEx(polylineWithoutAttrs);
      hasZ = polylineB.HasZ;                      // hasZ = false
      hasM = polylineB.HasM;                      // hasM = false
      hasID = polylineB.HasID;                    // hasID = false
    
      // will not have attributes because it is specified as a parameter
      PolygonBuilderEx polygonB = new PolygonBuilderEx(pointsForBuilder, AttributeFlags.None);
      hasZ = polygonB.HasZ;                       // hasZ = false
      hasM = polygonB.HasM;                       // hasM = false
      hasID = polygonB.HasID;                     // hasID = false
    
      // will have attributes because it is passed an attributed polygon
      polygonB = new PolygonBuilderEx(polygonWithAttrs);
      hasZ = polygonB.HasZ;                       // hasZ = true
      hasM = polygonB.HasM;                       // hasM = true
      hasID = polygonB.HasID;                     // hasID = true
    
      // will not have attributes because it is passed a non-attributed polygon
      polygonB = new PolygonBuilderEx(polygonWithoutAttrs);
      hasZ = polygonB.HasZ;                       // hasZ = true
      hasM = polygonB.HasM;                       // hasM = true
      hasID = polygonB.HasID;                     // hasID = true
    }
    Construct a Polyline - from a Cubic Bezier
    {
      polyline = PolylineBuilderEx.CreatePolyline(bezierSegment);
    }
    Calibrate M-values using segment lengths and M values from input points - CalibrateMsByDistance
    {
      List<MapPoint> points = [];
    
      MapPointBuilderEx pointBuilder = new(0, 0)
      {
        HasM = true,
        M = 0
      };
      points.Add(pointBuilder.ToGeometry());
    
      pointBuilder.SetValues(0, 8);
      pointBuilder.M = 12;
      points.Add(pointBuilder.ToGeometry());
    
      pointBuilder.SetValues(0, 18);
      pointBuilder.M = 10;
      points.Add(pointBuilder.ToGeometry());
    
      pointBuilder.SetValues(0, 28);
      pointBuilder.M = 14;
      points.Add(pointBuilder.ToGeometry());
    
      pointBuilder.SetValues(0, 32);
      pointBuilder.M = 20;
      points.Add(pointBuilder.ToGeometry());
    
      pointBuilder.SetValues(0, 38);
      pointBuilder.M = 26;
      points.Add(pointBuilder.ToGeometry());
    
      pointBuilder.SetValues(0, 50);
      pointBuilder.M = 30;
      points.Add(pointBuilder.ToGeometry());
    
      polyline = PolylineBuilderEx.CreatePolyline(points, AttributeFlags.HasM);
      // The points in the polyline are (0, 0, 0), (0, 8, 12), (0, 18, 10), (0, 28, 14), (0, 32, 20), (0, 38, 26), (0, 50, 30)
    
      // Calibrate Ms using points (0, 8, 15), (0, 28, 30), (0, 38, 20)
      points.Clear();
      pointBuilder.SetValues(0, 8);
      pointBuilder.M = 15;
      points.Add(pointBuilder.ToGeometry());
    
      pointBuilder.SetValues(0, 28);
      pointBuilder.M = 30;
      points.Add(pointBuilder.ToGeometry());
    
      pointBuilder.SetValues(0, 38);
      pointBuilder.M = 20;
      points.Add(pointBuilder.ToGeometry());
    
      double cutOffDistance = polyline.Length;
    
      // ExtrapolateBefore
      Polyline updatedPolyline = GeometryEngine.Instance.CalibrateMsByDistance(polyline, points, UpdateMMethod.ExtrapolateBefore, true, cutOffDistance) as Polyline;
      // The points in the updated polyline are
      // (0, 0, 9), (0, 8, 15), (0, 18, 10), (0, 28, 30), (0, 32, 20), (0, 38, 20), (0, 50, 30)
    
      // Interpolate
      updatedPolyline = GeometryEngine.Instance.CalibrateMsByDistance(polyline, points, UpdateMMethod.Interpolate, true, cutOffDistance) as Polyline;
      // The points in the updated polyline are
      // (0, 0, 0), (0, 8, 15), (0, 18, 22.5), (0, 28, 30), (0, 32, 26), (0, 38, 20), (0, 50, 30)
    
      // ExtrapolateAfter
      updatedPolyline = GeometryEngine.Instance.CalibrateMsByDistance(polyline, points, UpdateMMethod.ExtrapolateAfter, true, cutOffDistance) as Polyline;
      // The points in the updated polyline are
      // (0, 0, 0), (0, 8, 15), (0, 18, 10), (0, 28, 30), (0, 32, 20), (0, 38, 20), (0, 50, 8)
    
      // ExtrapolateBefore and Interpolate and ExtrapolateAfter
      updatedPolyline = GeometryEngine.Instance.CalibrateMsByDistance(polyline, points, UpdateMMethod.ExtrapolateAfter, true, cutOffDistance) as Polyline;
      // The points in the updated polyline are
      // (0, 0, 9), (0, 8, 15), (0, 18, 22.5), (0, 28, 30), (0, 32, 26), (0, 38, 20), (0, 50, 8)
    }
    Determine if all the M-values are numbers - IsMSimple
    {
      Coordinate2D[] coords = [new Coordinate2D(-2, 2), new Coordinate2D(3, 5), new Coordinate2D(7, 2)];
      polyline = PolylineBuilderEx.CreatePolyline(coords); // polyline.HasM = false
      bool isMSimple = GeometryEngine.Instance.IsMSimple(polyline); // isMSimple = false
    
      PolylineBuilderEx polylineBuilder = new(polyline)
      {
        HasM = true
      };
      polyline = polylineBuilder.ToGeometry();
      isMSimple = GeometryEngine.Instance.IsMSimple(polyline); // isMSimple = false
    
      MapPoint point1 = MapPointBuilderEx.CreateMapPoint(-2, 2, -1, 1);
      MapPoint point2 = MapPointBuilderEx.CreateMapPoint(3, 5, -2, 2);
      MapPoint[] points = [point1, point2];
      polyline = PolylineBuilderEx.CreatePolyline(points, AttributeFlags.HasM);
      isMSimple = GeometryEngine.Instance.IsMSimple(polyline); // isMSimple = true
    }
    Add an offset value to each of the M-values - OffsetMs
    {
      // Create a polyline and add an offset of 2 to each of the M-values
      MapPointBuilderEx pointBuilder = new(0, 0)
      {
        M = 1
      };
      MapPoint point1 = pointBuilder.ToGeometry();
    
      pointBuilder.SetValues(2, 2);
      pointBuilder.M = 3;
      MapPoint point2 = pointBuilder.ToGeometry();
    
      polyline = PolylineBuilderEx.CreatePolyline([point1, point2], AttributeFlags.HasM);
      ;
    
      Polyline outPolyline = GeometryEngine.Instance.OffsetMs(polyline, 2) as Polyline;
      // The xy-values of the points in outPolyline are the same as the points in the input polyline.
      // The M-values in outPolyline are { 3, 5 }
    
      // Create an envelope and add an offset of 25 to each of the M-values
      EnvelopeBuilderEx envelopeBuilder = new(-5, 1, 2, 4)
      {
        MMin = 10,
        MMax = 20
      };
      Envelope envelope = envelopeBuilder.ToGeometry();
    
      Envelope outEnvelope = GeometryEngine.Instance.OffsetMs(envelope, 25) as Envelope;
      // The xy-values of the points in outEnvelope are the same as the points in the input envelope.
      // outEnvelope.MMin = 35, outEnvelope.MMax = 45
    
      // Add a negative offset to the M-values of the envelope
      outEnvelope = GeometryEngine.Instance.OffsetMs(envelope, -10) as Envelope;
      // The xy-values of the points in outEnvelope are the same as the points in the input envelope.
      // outEnvelope.MMin = 0, outEnvelope.MMax = 10
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also