ArcGIS Pro 3.8 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);
    }
    Get the individual parts of a multipart feature
    IEnumerable<Geometry> MultipartToSinglePart(Geometry inputGeometry)
    {
      // list holding the part(s) of the input geometry
      List<Geometry> singleParts = new List<Geometry>();
    
      // check if the input is a null pointer or if the geometry is empty
      if (inputGeometry == null || inputGeometry.IsEmpty)
      {
        return singleParts;
      }
    
      // based on the type of geometry, take the parts/points and add them individually into a list
      switch (inputGeometry.GeometryType)
      {
        case GeometryType.Envelope:
          singleParts.Add(inputGeometry.Clone() as Envelope);
          break;
        case GeometryType.Multipatch:
          singleParts.Add(inputGeometry.Clone() as Multipatch);
          break;
        case GeometryType.Multipoint:
          var multiPoint = inputGeometry as Multipoint;
    
          foreach (var point in multiPoint.Points)
          {
            // add each point of collection as a standalone point into the list
            singleParts.Add(point);
          }
          break;
        case GeometryType.Point:
          singleParts.Add(inputGeometry.Clone() as MapPoint);
          break;
        case GeometryType.Polygon:
          var polygonNew = inputGeometry as Polygon;
    
          foreach (var polygonPart in polygonNew.Parts)
          {
            // use the PolygonBuilderEx turning the segments into a standalone
            // polygon instance
            singleParts.Add(PolygonBuilderEx.CreatePolygon(polygonPart));
          }
          break;
        case GeometryType.Polyline:
          var polylineNew = inputGeometry as Polyline;
    
          foreach (var polylinePart in polyline.Parts)
          {
            // use the PolylineBuilderEx turning the segments into a standalone
            // polyline instance
            singleParts.Add(PolylineBuilderEx.CreatePolyline(polylinePart));
          }
          break;
        case GeometryType.Unknown:
          break;
        default:
          break;
      }
      return singleParts;
    }
    Determine relationship between two geometries
    {
      // set up some geometries
    
      // points
      MapPoint point0 = MapPointBuilderEx.CreateMapPoint(0, 0, SpatialReferences.WGS84);
      MapPoint point1 = MapPointBuilderEx.CreateMapPoint(1, 1, SpatialReferences.WGS84);
      MapPoint point2 = MapPointBuilderEx.CreateMapPoint(-5, 5, SpatialReferences.WGS84);
    
      // multipoint
      List<MapPoint> points = [point0, point1, point2];
      Multipoint multipoint = MultipointBuilderEx.CreateMultipoint(points, SpatialReferences.WGS84);
    
      // polygon
      List<Coordinate2D> polygonCoords =
      [
          new Coordinate2D(-10, 0),
      new Coordinate2D(0, 10),
      new Coordinate2D(10, 0),
      new Coordinate2D(-10, 0)
      ];
      polygon = PolygonBuilderEx.CreatePolygon(polygonCoords, SpatialReferences.WGS84);
    
      // polylines
      Polyline polyline1 = PolylineBuilderEx.CreatePolyline(LineBuilderEx.CreateLineSegment(new Coordinate2D(-9.1, 0.1), new Coordinate2D(0, 9)), SpatialReferences.WGS84);
      Polyline polyline2 = PolylineBuilderEx.CreatePolyline(LineBuilderEx.CreateLineSegment(new Coordinate2D(-5, 5), new Coordinate2D(0, 5)), SpatialReferences.WGS84);
      Polyline polyline3 = PolylineBuilderEx.CreatePolyline(LineBuilderEx.CreateLineSegment(new Coordinate2D(2.09, -2.04), new Coordinate2D(5, 10)), SpatialReferences.WGS84);
      Polyline polyline4 = PolylineBuilderEx.CreatePolyline(LineBuilderEx.CreateLineSegment(new Coordinate2D(10, -5), new Coordinate2D(10, 5)), SpatialReferences.WGS84);
    
      List<Segment> segments =
      [
          LineBuilderEx.CreateLineSegment(new Coordinate2D(5.05, -2.87), new Coordinate2D(6.35, 1.57)),
      LineBuilderEx.CreateLineSegment(new Coordinate2D(6.35, 1.57), new Coordinate2D(4.13, 2.59)),
      LineBuilderEx.CreateLineSegment(new Coordinate2D(4.13, 2.59), new Coordinate2D(5, 5))
      ];
      Polyline polyline5 = PolylineBuilderEx.CreatePolyline(segments, SpatialReferences.WGS84);
    
      segments.Add(LineBuilderEx.CreateLineSegment(new Coordinate2D(5, 5), new Coordinate2D(10, 10)));
    
      Polyline polyline6 = PolylineBuilderEx.CreatePolyline(segments, SpatialReferences.WGS84);
      Polyline polyline7 = PolylineBuilderEx.CreatePolyline(polyline5);
      Polyline polyline8 = PolylineBuilderEx.CreatePolyline(LineBuilderEx.CreateLineSegment(new Coordinate2D(5, 5), new Coordinate2D(10, 10)), SpatialReferences.WGS84);
    
      segments.Clear();
      segments.Add(LineBuilderEx.CreateLineSegment(new Coordinate2D(0.6, 3.5), new Coordinate2D(0.7, 7)));
      segments.Add(LineBuilderEx.CreateLineSegment(new Coordinate2D(0.7, 7), new Coordinate2D(3, 9)));
    
      Polyline polyline9 = PolylineBuilderEx.CreatePolyline(segments, SpatialReferences.WGS84);
    
      // now do the Related tests
    
      // Interior/Interior Intersects
      string scl = "T********";
      bool related = GeometryEngine.Instance.Relate(polygon, polyline1, scl);     // related = true
      related = GeometryEngine.Instance.Relate(point0, point1, scl);              // related = false
      related = GeometryEngine.Instance.Relate(point0, multipoint, scl);          // related = true
      related = GeometryEngine.Instance.Relate(multipoint, polygon, scl);         // related = true
      related = GeometryEngine.Instance.Relate(multipoint, polyline1, scl);       // related = false
      related = GeometryEngine.Instance.Relate(polyline2, point2, scl);           // related = false
      related = GeometryEngine.Instance.Relate(point1, polygon, scl);             // related = true
    
      // Interior/Boundary Intersects
      scl = "*T*******";
      related = GeometryEngine.Instance.Relate(polygon, polyline2, scl);          // related = true
      related = GeometryEngine.Instance.Relate(polygon, polyline3, scl);          // related = false
      related = GeometryEngine.Instance.Relate(point1, polygon, scl);             // related = false
    
      // Boundary/Boundary Interior intersects
      scl = "***T*****";
      related = GeometryEngine.Instance.Relate(polygon, polyline4, scl);          // related = true
    
      // Overlaps Dim1
      scl = "1*T***T**";
      related = GeometryEngine.Instance.Relate(polygon, polyline5, scl);          // related = true
    
      // Crosses Area/Line (LineB crosses PolygonA)
      scl = "1020F1102";
      related = GeometryEngine.Instance.Relate(polygon, polyline6, scl);          // related = false
      related = GeometryEngine.Instance.Relate(polygon, polyline9, scl);          // related = true
    
      // Boundary/Boundary Touches
      scl = "F***T****";
      related = GeometryEngine.Instance.Relate(polygon, polyline7, scl);          // related = false
      related = GeometryEngine.Instance.Relate(polygon, polyline8, scl);          // related = true
    }
    Construct a Polyline - from a Cubic Bezier
    {
      polyline = PolylineBuilderEx.CreatePolyline(bezierSegment);
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also