Using polygon as covering layer with different color and transparency

Nov 2, 2012 at 3:19 AM

Thanks the project team to establish this useful tool for shorten the time consuming in managing KML files.

Recently, I try to build a covering layer based on the placemarks array. Initially, it is easy to use Polygon and OuterBoundary class to setup the covering area, however, the color setting process has a little different than Placemark icon setting.

Here is the reduced process:

//dbl_Boundary is a (N x 2) array which go through the selecting function to find out the boundary points of placemarks by Jarvis March method, declare likes this:

double[,] dbl_Boundary = new double[int_DataCount,2];

//----------------------------Write to KML--------------------------//

var document = new Document();
document.Id = str_KML_ID;
document.Name = str_KML_Name;

OuterBoundary outerBoundary = new OuterBoundary();
outerBoundary.LinearRing = new LinearRing();
outerBoundary.LinearRing.Coordinates = new CoordinateCollection();

//Let the points to the CoordinateCollection
for (int i = 0; i < int_BoundaryCounts; i++)
       outerBoundary.LinearRing.Coordinates.Add(new Vector(dbl_Boundary[i, 1], dbl_Boundary[i, 0], 30));

// Polygon Setting:
Polygon polygon = new Polygon();
polygon.Extrude = true;
polygon.AltitudeMode = AltitudeMode.ClampToGround;
polygon.OuterBoundary = outerBoundary;

//Color Style Setting:
byte byte_Color_R = 150, byte_Color_G = 150, byte_Color_B = 150, byte_Color_A=100; //you may get your own color by other method
var style = new Style();

style.Polygon = new PolygonStyle();
style.Polygon.ColorMode = SharpKml.Dom.ColorMode.Normal;
style.Polygon.Color = new Color32(byte_Color_A, byte_Color_B, byte_Color_G, byte_Color_R);

//Set the polygon and style to the Placemark:
Placemark placemark = new Placemark();
placemark.Name = str_KML_Name;
placemark.Geometry = polygon;
placemark.StyleSelector = style;

//Finally to the document and save it
var Mykml = new Kml();
Mykml.Feature = document;
KmlFile MykmlFile = KmlFile.Create(Mykml, true);


Nov 2, 2012 at 7:35 AM

Thanks for the kind words.

I'll take a look at the code you posted over the weekend, but in the meantime I'm a bit confused about the exact problem you are having - does the above code not compile or is the emitted KML incorrect?


Nov 2, 2012 at 7:38 AM
Edited Nov 2, 2012 at 8:06 AM

Oh, it works well, I just share my experience of using the polygon factor. It's a little different then using style.icon.