Polygon's and thank you

Jun 11, 2012 at 5:04 PM

First, thanks for this great library. It has already help me make latlongboxes and point plots efficiently.

 

Would anyone be able to point me in the direction of creating a polygon? When I try to do document.AddFeature(polygon) it does work. I am struggling heavily with the documentation. A very simple example would help greatly and possibly others too as I couldn't find a worked example even in C++ for this.

 

Many thanks

Coordinator
Jun 11, 2012 at 8:20 PM

Thanks for the kind words.

In general the best place to look for documentation is probably the KML Reference. Translating the example given there would give something like this:

internal static class Program
{
    public static void Main(string[] args)
    {
        OuterBoundary outerBoundary = new OuterBoundary();
        outerBoundary.LinearRing = new LinearRing();
        outerBoundary.LinearRing.Coordinates = new CoordinateCollection();
        outerBoundary.LinearRing.Coordinates.Add(new Vector(-122.366278, 37.818844, 30));
        outerBoundary.LinearRing.Coordinates.Add(new Vector(-122.365248, 37.819267, 30));
        outerBoundary.LinearRing.Coordinates.Add(new Vector(-122.365640, 37.819861, 30));
        outerBoundary.LinearRing.Coordinates.Add(new Vector(-122.366669, 37.819429, 30));
        outerBoundary.LinearRing.Coordinates.Add(new Vector(-122.366278, 37.818844, 30));

        // Alternativly, the above could be written using the initialization list
        // feature of C# like this:
        InnerBoundary innerBoundary = new InnerBoundary
        {
            LinearRing = new LinearRing
            {
                Coordinates = new CoordinateCollection
                {
                    new Vector(-122.366212, 37.818977, 30),
                    new Vector(-122.365424, 37.819294, 30),
                    new Vector(-122.365704, 37.819731, 30),
                    new Vector(-122.366488, 37.819402, 30),
                    new Vector(-122.366212, 37.818977, 30)
                }
            }
        };

        // This part could also be written using the above syntax, but shown like this for clarity.
        Polygon polygon = new Polygon();
        polygon.Extrude = true;
        polygon.AltitudeMode = AltitudeMode.RelativeToGround;
        polygon.AddInnerBoundary(innerBoundary);
        polygon.OuterBoundary = outerBoundary;

        Placemark placemark = new Placemark();
        placemark.Name = "hollow box";
        placemark.Geometry = polygon;

        Document document = new Document();
        document.Name = "Polygon.kml";
        document.Open = false;
        document.AddFeature(placemark);

        Kml root = new Kml();
        root.Feature = document;
    }
}

Hope it helps!

Jun 12, 2012 at 9:44 AM

Thanks very much, I was using the KML reference guide but still struggled to put that together with the library.

 

I see the step i missed is to add the polygon to a placemark!

Once again thank you very much.