/// <summary>
/// 从目录加载Tin
/// Esri的TIN,是一个文件夹,下面包好8个名称固定的adf文件
/// </summary>
/// <param name="folder">TinDataSet的父目录</param>
/// <param name="tinDataset">tinDataSet的名称</param>
/// <returns></returns>
public ITin GetTinLayer(string folder, string tinDataset)
{
IWorkspaceFactory pWSFact = new TinWorkspaceFactoryClass();
IWorkspace pWS = pWSFact.OpenFromFile(folder, 0);
ITinWorkspace pTinWS = pWS as ITinWorkspace;
ITin pTin = pTinWS.OpenTin(tinDataset);
return pTin;
}
li_TinDataset = new List<string> { "tdenv.adf", "tedg.adf", "thul.adf", "tmsk.adf", "tmsx.adf", "tnod.adf", "tnxy.adf", "tnz.adf" };
/// <summary> /// 检查是否是TIN dataset
/// </summary>
/// <param name="folderpath">用户选择的folder</param>
/// <returns></returns>
public bool CheckTinDataSet(string folderpath)
{
if (!Directory.Exists(folderpath)) return false;
DirectoryInfo di = new DirectoryInfo(folderpath);
FileInfo[] ar_fi= di.GetFiles("*.adf");
List<string> li_tem=new List<string>();
for (int i = 0; i <= ar_fi.Length - 1; i++)
{
li_tem.Add(ar_fi[i].Name);
}
int afirmed = 0; for (int i = 0; i <= li_TinDataset.Count - 1; i++)
{
if (li_tem.Contains(li_TinDataset[i])) afirmed++;
else break;
}
if (afirmed == 8) return true;
else return false;
}
/// <summary>
/// 将整个TIN作为计算对象,使用此方法
/// </summary>
/// <param name="Tin">TinLayer</param>
/// <param name="planeheight">参考面高度</param>
public void CalculateAreaVolumeISurface(ITin Tin, double planeheight,esriPlaneReferenceType aboveOrBelow,out double projectedArea,out double surfaceArea,out double volume)
{
ISurface pSurface = Tin as ISurface;
projectedArea = pSurface.GetProjectedArea(planeheight, aboveOrBelow);
surfaceArea = pSurface.GetSurfaceArea(planeheight, aboveOrBelow);
volume = pSurface.GetVolume(planeheight, aboveOrBelow);
projectedArea = Math.Round(projectedArea, 2);//保留两位小数
surfaceArea = Math.Round(surfaceArea, 2);
volume = Math.Round(volume, 2);
}