从曲面创建路线的曲面纵断面,获取桩号、高程数据用以分析、制图。
/// <summary>
/// 获取纵断面数据
/// </summary>
public static List<DataInfo> createMainSurfaceProfile(Alignment operationAlignment, Surface mainSurface, double startStaion = -1, double endStation = -1)
{
List<DataInfo> result = new List<DataInfo>();
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var cDoc = CivilApplication.ActiveDocument;
using (var ts = db.TransactionManager.StartTransaction())
{
ObjectId surfaceId = mainSurface.ObjectId;
//获取样式
ObjectId layerId = operationAlignment.LayerId;
ObjectId styleId;
try
{
styleId = cDoc.Styles.ProfileStyles["Basic"];
}
catch
{
styleId = cDoc.Styles.ProfileStyles[0];
}
ObjectId labelSetId;
try
{
labelSetId = cDoc.Styles.LabelSetStyles.ProfileLabelSetStyles["Complete Label Set"];
}
catch
{
labelSetId = cDoc.Styles.LabelSetStyles.ProfileLabelSetStyles[0];
}
double startS = startStaion == -1 ? operationAlignment.StartingStation : startStaion;
double endS = endStation == -1 ? operationAlignment.EndingStation : endStation;
//从曲面创建纵断面
ObjectId profileId = Profile.CreateFromSurface("曲面纵断面", operationAlignment.ObjectId,
surfaceId, layerId, styleId, labelSetId, 0, startS, endS);
Profile profile = (Profile)profileId.GetObject(OpenMode.ForWrite);
ProfilePVICollection profilePVIs = profile.PVIs;
foreach (ProfilePVI proPVI in profilePVIs)
{
double station = Math.Round(proPVI.Station, 2);
double elevtion = Math.Round(proPVI.Elevation, 2);
DataInfo dataInfo = new DataInfo(station, elevtion);
result.Add(dataInfo);
}
//取指定桩号的高程
//double xNum = (int)(profile.EndingStation / 5) + 1;
//for (int i = 0; i < xNum; i++)
//{
//double station = i * 5;
//if (station >= profile.StartingStation)
//{
//double el = Math.Round(profile.ElevationAt(i * 5), 2);
//DataInfo dataInfo = new DataInfo(i * 5, el);
//tableInfos.Add(dataInfo);
//}
//}
profile.Erase();
ts.Commit();
}
return result;
}
上述代码中所用到的类 将数据转化成x、y的点。
public class DataInfo
{
private DataInfo()
{
}
public DataInfo(double x, double y, double inCurvature = 0)
{
X = x;
Y = y;
curvature = inCurvature;
}
public double X { get; set; }
public double Y { get; set; }
public double curvature { get; set; }
public override bool Equals(object obj)
{
if (!(obj is DataInfo))
{
return false;
}
DataInfo dataInfo = obj as DataInfo;
if (dataInfo.X == X && dataInfo.Y == Y && dataInfo.curvature == curvature)
{
return true;
}
else
{
return false;
}
}
public override int GetHashCode()
{
return string.Format("{0}|{1}|{2}", X, Y, curvature).GetHashCode();
}
}
有问题可评论区留言或私信。
通过获取的数据制图