Select to view content in your preferred language

Polyline from Points

1705
2
09-08-2010 06:05 AM
BBulla
by
Regular Contributor
Hi,

I'm trying to create a polyline from 3 points.  I can create the From and the To node, but how do I inset the middle node??  This is the code I am using:

//Create a geometry for the line.                               
IPolyline polyline = new PolylineClass();

polyline.FromPoint = point1;
polyline.ToPoint = point3;

// Build the feature.
IFeature feature = featureClass.CreateFeature();
feature.Shape = polyline;


I have point2 which is the middle point, but can't figure out how to insert it into the feature.

Thanks!
0 Kudos
2 Replies
NeilClemmons
Honored Contributor
A polyline is a point collection, so you can add the points to the collection in the correct order.

Dim polyline As IPolyline = New Polyline
Dim pointCollection As IPointCollection = polyline
pointCollection.AddPoint(point)
' repeat until all points are added
0 Kudos
BBulla
by
Regular Contributor
Hi Neil,

Thanks for the tip.  This seems to work for me:

               
//Create the geometry
                IPolyline polyline = new PolylineClass();
                IPointCollection pointCollection = polyline as IPointCollection;
                pointCollection.AddPoint(point1, ref missing, ref missing);
                pointCollection.AddPoint(point2, ref missing, ref missing);
                pointCollection.AddPoint(point3, ref missing, ref missing);

                
                // Build the feature.
                IFeature feature = featureClass.CreateFeature();
                feature.Shape = pointCollection as IPolyline;
0 Kudos