原始:
修订后:
/// <summary>
/// 更新线要素(三点要素构成)的端点
/// </summary>
/// <param name="pLineFeature">线要素</param>
/// <param name="pEndpointFeature1">端点1</param>
/// <param name="pEndpointFeature2">端点2</param>
static public void UpdataFeatureLineEndpoint(IFeature pLineFeature, IFeature pEndpointFeature1, IFeature pEndpointFeature2)
{
// 获取Polyline
IGeometry pLineGeometry = pLineFeature.ShapeCopy;
IPolyline pPolyline = pLineGeometry as IPolyline;
// 获取待更新的端点
IPoint pEndpoint1 = pEndpointFeature1.ShapeCopy as IPoint;
IPoint pEndpoint2 = pEndpointFeature2.ShapeCopy as IPoint;
// QI
IPointCollection pCollection = pPolyline as IPointCollection;
// 更新两端点
pCollection.UpdatePoint(0, pEndpoint1);
pCollection.UpdatePoint(-1, pEndpoint2);
// 要素更新并保存
pLineFeature.Shape = pCollection as IGeometry;
pLineFeature.Store();
}
/// <summary>
/// 依据线要素端点与点要素距离,更新其端点
/// </summary>
/// <param name="pLineFeature"></param>
/// <param name="pEndpointFeature1"></param>
/// <param name="pEndpointFeature2"></param>
static public void UpdataFeatureLineEndpointAppendDistandce(IFeature pLineFeature, IFeature pEndpointFeature1, IFeature pEndpointFeature2)
{
// 获取Polyline
IGeometry pLineGeometry = pLineFeature.ShapeCopy;
IPolyline pPolyline = pLineGeometry as IPolyline;
/// 计算原有Polyline端点与待添加端点距离,确定起始点、终止点
// 获取待更新的端点
IPoint pEndpoint1 = pEndpointFeature1.ShapeCopy as IPoint;
IPoint pEndpoint2 = pEndpointFeature2.ShapeCopy as IPoint;
// 获取Polyline任意一个端点
IPoint pLineEndPoint = pPolyline.ToPoint;
double pLength1 = Math.Pow((pLineEndPoint.X - pEndpoint1.X), 2) + Math.Pow((pLineEndPoint.Y - pEndpoint1.Y), 2);
double pLength2 = Math.Pow((pLineEndPoint.X - pEndpoint2.X), 2) + Math.Pow((pLineEndPoint.Y - pEndpoint2.Y), 2);
// QI
IPointCollection pCollection = pPolyline as IPointCollection;
// 根据距离远近更新线要素的端点
if (pLength1 > pLength2)
{
// 更新起始点
pCollection.UpdatePoint(0, pEndpoint1);
// 更新末尾点
pCollection.UpdatePoint(-1, pEndpoint2);
}
else
{
// 更新起始点
pCollection.UpdatePoint(0, pEndpoint2);
// 更新末尾点
pCollection.UpdatePoint(-1, pEndpoint1);
}
// 要素更新并保存
pLineFeature.Shape = pCollection as IGeometry;
pLineFeature.Store();
}
资源1:
转载于:https://www.cnblogs.com/fatherZyl/p/3277924.html
IPointCollection转线IPolyline:
1 IPolyline pl = new PolylineClass(); 2 3 IPointCollection ptc = pl as IPointCollection; 4 5 object missing = Type.Missing; 6 7 for (int i = 0; i < num1; i++) 8 { 9 IPoint pt = autoStation.GetFeature(i).Shape as IPoint;//提取点 10 ptc.AddPoint(pt, missing, missing); 11 12 } 13 14 (pl as ITopologicalOperator).Simplify();
//把IPolyline插入到IFeatureClass中
1 IFeatureClass f1 = (ws as IFeatureWorkspace).OpenFeatureClass("bb1"); 2 IFeature fea=f1.CreateFeature(); 3 fea.Shape = pl; 4 fea.Store();
资源2:
转载于:https://www.cnblogs.com/yzhyingcool/p/11102493.html
补充指出官方帮助的一个问题。
该方法用于向环、线。面等几何中添加节点。官方帮助里是这样描述的:Adds a vertex to a Path, Ring, Polyline, or Polygon; or adds a reference to the input point to a Multipoint, TriangleFan, or TriangleStrip.
官方给的方法说明如下:
[C#]
public void AddPoint ( IPoint inPoint, ref object before, ref object after );
[C#]
Optional Values
before To indicate that this parameter is undefined, first define a variable object Missing = Type.Missing; then pass this in as ref Missing.
after To indicate that this parameter is undefined, first define a variable object Missing = Type.Missing; then pass this in as ref Missing.
官网示例与网上的分享案例无一例外的只使用了第一个参数,而后两个可选参数被省略或者使用Type.Missing,这样新加的节点添加到几何的最后一个节点之后。能否把第2、3参利用起来,使新加的节点到指定的位置?博主研究了这个可能,得出下面结论。
1、参数类型应为int,其实就是一个index;
2、before意指在给定index指向的节点前加节点,after反之;
3、ref关键字是不需要的。
//before 在这个索引之前加
pointCollection.AddPoint(point,index,Type.Missing);