This example demonstrates how to create a polygon using an array of vertices and set basic properties. This example uses the ILinearRing, IGeometry, ITerrainPolygon66, ICreator66 (CreatePolygon, GeometryCreator), IGeometryCreator (CreateLinearRingGeometry, CreatePolygonGeometry) INavigate66 (FlyTo), and IPosition66 (Copy, Pitch) properties and methods.
private void GeometryPolygon()
{
stringtMsg = String.Empty;
double[] cVerticesArray = null;
ILinearRing cRing = null;
IGeometry cPolygonGeometry = null;
ITerrainPolygon66 cPolygon = null;
try
{
//
// A. Instantiate Terra Explorer Globe
//
var sgworld = new SGWorld66();
//
// B. Create linear ring
//
{
//B1. Create vertices double array, each point in format x,z,y
cVerticesArray = new double[] {
-122.415025, 37.76059, 10,
-122.415868, 37.760546, 11,
-122.415922, 37.761244, 12,
-122.415592, 37.761254, 13,
-122.415557, 37.760973, 14,
-122.415081, 37.76099, 15,
};
// B2. Create linear ring using vertices
{
cRing = sgworld.Creator.GeometryCreator.CreateLinearRingGeometry(cVerticesArray);
}
}
//
// C. Create polygon geometry using linear ring
//
{
cPolygonGeometry = sgworld.Creator.GeometryCreator.CreatePolygonGeometry(cRing, null);
}
//
// D. Create polygon using polygon geometry
//
{
// D1. Set polygon input params
uint nLineColor = 0xFF00FF00; // Abgr value -> solid green
uint nFillColor = 0x7FFF0000; // Abgr value -> 50% transparent blue
AltitudeTypeCode eAltitudeTypeCode = AltitudeTypeCode.ATC_TERRAIN_RELATIVE;
// D2. Create polygon
cPolygon = sgworld.Creator.CreatePolygon(cPolygonGeometry, nLineColor, nFillColor, eAltitudeTypeCode, string.Empty, "Polygon");
}
//
// E. FlyTo polygon
//
{
var cFlyToPos = cPolygon.Position.Copy();
cFlyToPos.Pitch = -89.0; // Set camera to look downward on polygon
sgworld.Navigate.FlyTo(cFlyToPos, ActionCode.AC_FLYTO);
}
}
catch (Exception ex)
{
tMsg = String.Format("GeometryPolygon_Click Exception: {0}", ex.Message);
MessageBox.Show(tMsg);
}
}