这两天替别人写一个三维校园的展示程序。用的是SceneControl二次开发。
须要利用DOM和TIN构建三维地形。如今说下依据高程点生成TIN的过程:
(1)依据高程点文件(Excel)生成点shapefile
(2)使用ITinEdit的AddFromFeatureClass方法生成TIN
高程点数据格式例如以下:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZ2lzZXJfd2h1/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
操作界面例如以下:
:
生成TIN效果图:
代码非常easy理解,例如以下:
#region 创建TIN
private void button_ok_Click(object sender , EventArgs e)
{
try
{
strTinName=textBox_TINName.Text;
outFolder=textBox_outpath.Text;
if (strTinName=="")
{
MessageBox.Show("请输入TIN名称!");
}
else if (outFolder=="")
{
MessageBox.Show("请选择TIN保存路径");
}
else
{
//生成点shape
Excel2Shape excel2shape = new Excel2Shape(textBox_point.Text);
excel2shape.CreateShapeFromExcel(); //获取shapefile
string path = excel2shape.path;
string name = excel2shape.name; IWorkspaceFactory pWSFac = new ShapefileWorkspaceFactoryClass();
IFeatureWorkspace pFeatureWS = pWSFac.OpenFromFile(path , 0) as IFeatureWorkspace;
IFeatureClass pFeatureClass = pFeatureWS.OpenFeatureClass(name);
IField pField = pFeatureClass.Fields.get_Field(pFeatureClass.FindField("Z"));
//创建TIN
ITin pTin = Create_TIN(pFeatureClass , pField , outFolder);
ITinLayer pTinlayer = new TinLayerClass();
pTinlayer.Dataset = pTin;
pTinlayer.Name = strTinName; pSceneControl.SceneGraph.Scene.AddLayer(pTinlayer as ILayer , true); this.Close();
} }
catch (System.Exception ex)
{
MessageBox.Show(ex.Message + "创建TIN失败。");
} }
/// <summary>
/// 创建TIN
/// </summary>
/// <param name="pFeatureClass">点要素类</param>
/// <param name="pField">Z字段</param>
/// <param name="pPath">路径</param>
public ITin Create_TIN(IFeatureClass pFeatureClass , IField pField , string pPath)
{
IGeoDataset pGeoDataset = pFeatureClass as IGeoDataset;
ITinEdit pTinEdit = new TinClass();
pTinEdit.InitNew(pGeoDataset.Extent);
object pObj = Type.Missing; pTinEdit.AddFromFeatureClass(pFeatureClass , null , pField , null ,
esriTinSurfaceType.esriTinMassPoint , ref pObj);
if (System.IO.File.Exists(pPath))
{
_3DCampus.helper.FolderHelper.DeleteFolder(pPath);
}
pTinEdit.SaveAs(pPath , ref pObj);
pTinEdit.Refresh();
return pTinEdit as ITin; }
#endregion