获取三维多段线的节点坐标
本帖最后由 雪山飞狐_lzh 于 2012-7-6 23:30 编辑如何获取三维多段线的节点坐标,Polyline3d应该用哪个函数啊? 在线等,急,先谢谢大家! Public Function GetVerPts(ByVal ID As ObjectId) As Point3d()
Using Trans As Transaction = DB.TransactionManager.StartTransaction
Dim Ent As Entity = Trans.GetObject(ID, OpenMode.ForRead)
If TypeOf Ent Is Polyline3d Then
Dim objPolyline3d As Polyline3d = Ent, pts As New List(Of Point3d)
Dim VID As ObjectId = Nothing, Vtx As PolylineVertex3d = Nothing
Dim Temp_type As Poly3dType = objPolyline3d.PolyType '将先前的拟合类型先保存下来,计算完毕后复原
objPolyline3d.ConvertToPolyType(Poly3dType.SimplePoly)
For Each VID In objPolyline3d
Vtx = Trans.GetObject(ID, OpenMode.ForRead)
pts.Add(New Point3d(Vtx.Position.X, Vtx.Position.Y, Vtx.Position.Z))
Next
objPolyline3d.ConvertToPolyType(Temp_type)
GetVerPts = pts.ToArray
Else
GetVerPts = New Point3d() {}
End If
Trans.Commit()
End Using
Return Nothing
End Function看看这个能不能有用。(拟合的时候,计算可能有问题) Point3dCollection cool = new Point3dCollection();//定义一个点的集合
Polyline3d pol = new Polyline3d();//已知的三维多段线
pol.GetStretchPoints(cool); //执行完这个函数,cool(点集合)就有值了
//最后你遍历下cool 得到是点的坐标
希望能帮到你!!! Polyline2d 的,二维pline节点坐标怎么获取? 多义线都是复合实体(简单实体集合),可以foreach的 本帖最后由 sxpd 于 2012-7-7 08:50 编辑
/// <summary>
/// 获取复合实体的子实体集合
/// </summary>
/// <typeparam name="T">复合实体类型(PolyLine2d/3d、PolyfaceMesh......)</typeparam>
/// <param name="ent">复合实体</param>
/// <param name="tr">事务实例</param>
/// <returns>子实体迭代器</returns>
public static IEnumerable<Vertex> GetVertexs<T>(this T ent, Transaction tr) where T : Entity, IEnumerable
{
foreach (ObjectId id in ent)
{
yield return (Vertex)tr.GetObject(id, OpenMode.ForRead);
}
}
/// <summary>
/// 获取复合实体的子实体集合
/// </summary>
/// <typeparam name="T">复合实体类型(PolyLine2d/3d、PolyfaceMesh......)</typeparam>
/// <param name="ent">复合实体</param>
/// <param name="tr">事务实例</param>
/// <param name="mode">打开模式(读/写)</param>
/// <returns>子实体迭代器</returns>
public static IEnumerable<Vertex> GetVertexs<T>(this T ent, Transaction tr, OpenMode mode) where T : Entity, IEnumerable
{
foreach (ObjectId id in ent)
{
yield return (Vertex)tr.GetObject(id, mode);
}
}
Point3dCollection cool = new Point3dCollection();//定义一个点的集合
Polyline3d pol = new Polyline3d();//已知的三维多段线
pol.GetStretchPoints(cool); //执行完这个函数,cool(点集合)就有值了
//最后你遍历下cool 得到是点的坐标
上面是Polyline3d (三维pline)节点坐标获取方法,不知道对不?。
Polyline2d (二维pline)节点坐标怎么获取?
Polyline(lwpline)( 轻便或普通的pline)节点坐标怎么获取? GetStretchPoints容易出问题的
我以前的代码
LWPolyline pl = tr.GetObject(resEnt.ObjectId, OpenMode.ForRead) as LWPolyline;
var ptlst =
Enumerable
.Range(0, pl.NumberOfVertices)
.Select(i => pl.GetPoint2dAt(i));
页:
[1]
2