This project has moved. For the latest updates, please go here.

Any way to create a KML from WKT?

Aug 22, 2012 at 7:08 PM

I found a way to create polygons from this discussion post. But is there a way I can create a polygon from it's WTK?

something like the below?

Polygon myPoly = Polygon.Parse("POLYGON((56.0265648489975 27.2038803557758, 56.3941528366858 27.2660767903486, 56.4755640102331 26.8820239141298, 56.1093191502074 26.8198049660311, 56.0265648489975 27.2038803557758))");

Aug 25, 2012 at 9:14 AM

There isn't a build in way, no, but you can certainly make your own extension method if you like. I'm not familiar with WTK (does it stand for WorldToolKit?) but looking at the sample input the polygon could be converted to a series of coordinates, which you'd add to the Coordinates property of a LinearRing that would form your OuterBoundary.

Here's a rough sketch:

var coordinates = new CoordinateCollection();
IEnumerable points = YourFuctionThatParsesWTKPolygons();
foreach (Tuple<double, double> point in points)
    coordinates.Add(new Vector(point.Item1, point.Item2));

var outerBoundary = new OuterBoundary();
outerBoundary.LinearRing = new LinearRing();
outerBoundary.LinearRing.Coordinates = coordinates;

var polygon = new Polygon();
polygon.OuterBoundary = outerBoundary;

Aug 28, 2012 at 1:38 PM
Edited Aug 28, 2012 at 1:39 PM

Thanks samcrag. WKT = Well Known Text 

I ended up doing exactly what you're doing there except intead of creating my own WKT Parser I used msSQL's