先簡單說一說skyline軟件的系統,skyline軟件主要有TerraBuilder,TerraExplorer以及TerraGate。TerraBuilder主要是采用圖像,dem等生成地形,制作成三維地球或三維平面;TerraExplorer的功能是編輯和浏覽(關鍵部分);TerraGate主要是網絡功能。換句話說,Terrabuilder是數據制作源,TerraExplorer是數據可視化窗口。
(一)二次開發准備
打開vs2010,在工具欄處右鍵,添加選項卡,建立skyline控件組,在建好的組內,右鍵選擇項
添加skyline有關的com組件
添加完成後,將會得到如下控件:
TE3DWindow是三維浏覽窗口,TEInformationWindow是樹信息目錄窗口,TENavigationMap是鷹眼窗口。
(二)管線生成
//接口的使用
TECoClass = new TerraExplorerClass();
mTerraExplorer = (ITerraExplorer5)TECoClass;
mPlane = (IPlane5)TECoClass;
mNavigation = (ITENavigationMap5)TECoClass;
mRender = (IRender5)TECoClass;
mMenue = (IMenu)TECoClass;
mObjectManager = (IObjectManager5)TECoClass;
mInformationTee = (IInformationTree5)TECoClass;
//加載三維球
mTerraExplorer.LoadEx(@"C:\globe.fly", "", "", 0);//或者mpt文件,可以使用Terrabuilder生成。
管線繪制的代碼生成主要有兩種方式:
1.單管段
int iGround = mInformationTee.CreateGroup("管線", 0);
double x1 = 0, y1 = 0, z1 = 0, x2, y2, z2;
double pipeLength;
double fillOpacity = 0.7;
double pipeRadius = 2;
object oYaw, oPitch;
double finYaw;
while (sdr.Read())
{
//這裡是創建3Dobject的代碼,創建圓柱體,可以進行貼圖,輸入一端的坐標,管徑,管長度,圓柱形狀逼近多邊形的邊數等
}
2.以圖層方式添加,優勢在於成組進行圖層管理,圖層的顯示類型有很多種類,比如每個點位顯示球形,圓柱形,3D模型等等,圖層的屬性中可以進行一定的更改。
//創建圖層組
int iGround = mInformationTee.CreateGroup("管線layer", 0); ;
double x1 = 0, y1 = 0, z1 = 0;
double x2 = 0, y2 = 0, z2 = 0;
double pipeLength;
double pipeRadius = 2;
List Aname = new List();
IPosition6 currCoord, nextCoord;
SGWorld sgworld = new SGWorld();
//創建featurelayer
ILayer6 CylindresLayer = sgworld.Creator.CreateNewFeatureLayer("第一管線段", LayerGeometryType.LGT_POINT, "FileName=pipes" + DateTime.Now.Day + ".shp;TEPlugName=OGR;", iGround);
//sdsdsd.Streaming = false;
//編輯layer屬性,類似於在shp文件中設置字段屬性,每一個點可以取得不同的值,再將其賦值給圖層的屬性中
CylindresLayer.DataSourceInfo.Attributes.CreateAttribute("Yaw", AttributeTypeCode.AT_DOUBLE, 0);
CylindresLayer.DataSourceInfo.Attributes.CreateAttribute("Pitch", AttributeTypeCode.AT_DOUBLE, 0);
CylindresLayer.DataSourceInfo.Attributes.CreateAttribute("Roll", AttributeTypeCode.AT_DOUBLE, 0);
CylindresLayer.DataSourceInfo.Attributes.CreateAttribute("Texture", AttributeTypeCode.AT_TEXT, 1024);
CylindresLayer.DataSourceInfo.Attributes.CreateAttribute("Rotate", AttributeTypeCode.AT_DOUBLE, 100);
CylindresLayer.DataSourceInfo.Attributes.CreateAttribute("RadiusX", AttributeTypeCode.AT_DOUBLE, 0);
CylindresLayer.DataSourceInfo.Attributes.CreateAttribute("Height", AttributeTypeCode.AT_DOUBLE, 0);
CylindresLayer.Visibility.MaxVisibilityDistance = 5000;
//編輯屬性對應,如上圖
CylindresLayer.FeatureGroups.Point.DisplayAs = ObjectTypeCode.OT_CYLINDER;
CylindresLayer.FeatureGroups.Point.SetProperty("Number of sides", 16);
CylindresLayer.FeatureGroups.Point.SetProperty("Line Opacity", 0);
CylindresLayer.FeatureGroups.Point.SetProperty("Fill Opacity", 100);
CylindresLayer.FeatureGroups.Point.SetProperty("Yaw", "[Yaw]");
CylindresLayer.FeatureGroups.Point.SetProperty("Roll", "[Roll]");
CylindresLayer.FeatureGroups.Point.SetProperty("Pitch", "[Pitch]");
CylindresLayer.FeatureGroups.Point.SetProperty("Texture File", "[Texture]");
CylindresLayer.FeatureGroups.Point.SetProperty("Rotate", "[Rotate]");
CylindresLayer.FeatureGroups.Point.SetProperty("Radius X", "[RadiusX]");
CylindresLayer.FeatureGroups.Point.SetProperty("Height", "[Height]");
//創建管段端外圍
ILayer6 SpheresLayer = sgworld.Creator.CreateNewFeatureLayer("管段連接", LayerGeometryType.LGT_POINT, "FileName=connectors" + DateTime.Now.Day + ".shp;TEPlugName=OGR;", iGround);
//SpheresLayer.Streaming
SpheresLayer.Refresh();
SpheresLayer.DataSourceInfo.Attributes.CreateAttribute("Yaw", AttributeTypeCode.AT_DOUBLE, 0);
SpheresLayer.DataSourceInfo.Attributes.CreateAttribute("Pitch", AttributeTypeCode.AT_DOUBLE, 0);
SpheresLayer.DataSourceInfo.Attributes.CreateAttribute("Roll", AttributeTypeCode.AT_DOUBLE, 0);
SpheresLayer.FeatureGroups.Point.DisplayAs = ObjectTypeCode.OT_SPHERE;
SpheresLayer.FeatureGroups.Point.SetProperty("Yaw", "[Yaw]");
SpheresLayer.FeatureGroups.Point.SetProperty("Roll", "[Roll]");
SpheresLayer.FeatureGroups.Point.SetProperty("Pitch", "[Pitch]");
SpheresLayer.FeatureGroups.Point.SetProperty("Segment density", 16);
SpheresLayer.FeatureGroups.Point.SetProperty("Line Opacity", 0);
SpheresLayer.FeatureGroups.Point.SetProperty("Fill Opacity", 100);
SpheresLayer.FeatureGroups.Point.SetProperty("Radius", pipeRadius);
SpheresLayer.FeatureGroups.Point.SetProperty("Texture File", Application.StartupPath+@"\pipeTextureCyan2.bmp");
SpheresLayer.Visibility.MaxVisibilityDistance = 5000;
while (sdr.Read())
{
}
CylindresLayer.Save();
SpheresLayer.Save();
類似的,加載三維模型:
需要注意的是,在加載mpt之後,以圖層方式加載管線顯示不出來,只有在fly文件基礎上才能看到。