How i retrive Polygon Co-ordinate value as text

Sep 26, 2012 at 1:57 PM

Here i get co-ordinate as List , but wanted to get element of inner text


            foreach (var poly in o.Flatten().OfType<Polygon>())
            {

                //var pointco = poly.OuterBoundary.LinearRing.Coordinates.ToList();
                var pointco = poly.OuterBoundary.LinearRing.Coordinates;

            }

Coordinator
Sep 26, 2012 at 9:24 PM

You can serialize a single element using the SharpKml.Base.Serializer class. This might be over the top for what you need so you could just create the string yourself, something along the lines of this:

var sb = new StringBuilder();

foreach (var point in poly.OuterBoundary.LinearRing.Coordinates)
{
    if (point.Altitude != null)
    {
        sb.AppendFormat(
            CultureInfo.InvariantCulture,
            "{0},{1},{2}\n",
            point.Longitude,
            point.Latitude,
            point.Altitude.Value);
    }
    else
    {
        sb.AppendFormat(
            CultureInfo.InvariantCulture,
            "{0},{1}\n",
            point.Longitude,
            point.Latitude);
    }
}