Engine 开发中如何往已有IPointCollection中的指定位置处添加多个点

使用IPointCollection.AddPoints只能添加一个点,这样再添加下一个点时,索引位置会发生变化
已邀请:

朱新颖

赞同来自:

【解决办法】:
AO帮助中IPointCollection.AddPoints下面有这样的说明:
[C#]
When using C# you must use the IGeometryBridge interface to call this method.
所以可以使用IGeometryBridge.InsertPoints方法在指定索引位置添加多个点,示例代码为:
public void InsertPoints()
{
IPoint point1 = new PointClass();
point1.PutCoords(10, 10);
IPoint point2 = new PointClass();
point2.PutCoords(20, 20);
IPoint pointArray = new IPoint[2];
pointArray[0] = point1;
pointArray[1] = point2;
IPointCollection4 pointCollection = new MultipointClass();
//insert points to pointCollection starting at the given index
IGeometryBridge geometryBridge = new GeometryEnvironmentClass();
int index = 0;
geometryBridge.InsertPoints(pointCollection, index, ref pointArray);
//insert more points at a different index
IPoint point3 = new PointClass();
point3.PutCoords(30, 30);
IPoint point4 = new PointClass();
point4.PutCoords(40, 40);
IPoint secondPointArray = new IPoint[2];
secondPointArray[0] = point3;
secondPointArray[1] = point4;
int secondindex = 1;
geometryBridge.InsertPoints(pointCollection, secondindex, ref secondPointArray);
}

要回复问题请先登录注册