This project has moved and is read-only. For the latest updates, please go here.

Insert Polyline from point array

Nov 2, 2012 at 9:27 AM
Edited Nov 2, 2012 at 9:28 AM

Hello.

 

I'm trying to insert a Polyline programmatically from Point Array.

My implementation is :

Polyline shape = (Polyline)project1.ShapeTypes["Polyline"].CreateInstance();

for (i = 0; i < PTS.Length; i++)
    shape.AddVertex(PTS[i].X, PTS[i].Y);

Result is not what I thought. It has 2 more point, because of Polyline Constructor.

Could you tell me how to create a Polyline from point array?

 

Thank you. 

Nov 5, 2012 at 10:02 AM

Move the first and last control point, insert the rest as new vertices:

Polyline shape = (Polyline)project1.ShapeTypes["Polyline"].CreateInstance();
int maxIdx = PTS.Length - 1;
shape.MoveControlPointTo(ControlPointId.FirstVertex, PTS[0].X, PTS[0].Y, ResizeModifiers.None);
shape.MoveControlPointTo(ControlPointId.LastVertex, PTS[maxIdx].X, PTS[maxIdx].Y, ResizeModifiers.None);
for (i = 1; i < maxIdx; i++)
    shape.AddVertex(PTS[i].X, PTS[i].Y);
Nov 6, 2012 at 4:02 AM

Thanks. It works well!