Hello there

 

An awesome and useful Portable Library that helps exporting Google Earth KML files in a stream-like fashion is available on NuGet with the name of TNX.KML

The KmlExporter class, is able to write a compliant KML file with placemarks and routes with your styles

 

Here an exaple for beginning

 

//a couple of items
var items = new[]
{
new {lati=45.20,longi=9.13, name=”about milano”},
new {lati=41.40,longi=12.3, name=”about roma”},
};

var fname = “kmlout.kml”;

using (var f = File.OpenWrite(fname))
//this is the KML exporter helper
using (var w = new KmlExporter(f, “test1”))
{
//this create a reusable line style
w.WriteLineStyle(4, “linestyle1”);

w.WriteRoute(“route1”, items, x => x.lati, x => x.longi, null, “linestyle1”);
}

//start file opening with default (google earth) application
Process.Start(fname);

 

 

here a more complete example

 

//a couple of items
var items = new[]
{
new {lati=45.20,longi=9.13, name=”about milano”},
new {lati=41.40,longi=12.3, name=”about roma”},
};

var fname = “kmlout2.kml”;

using (var f = File.OpenWrite(fname))
//this is the KML exporter helper
using (var w = new KmlExporter(f, “test1”))
{
//this create a reusable line style
w.WriteLineStyle(4, “linestyle1”);
//a reausable icon style
w.WriteIconStyle(“stop”, “http://vixra.files.wordpress.com/2012/02/stop1.png”);

//the route
w.WriteRoute(“route1”, items, x => x.lati, x => x.longi, null, “linestyle1”);

//the ending placemark
w.WritePlacemark(“route1-stop”, items.Last().lati, items.Last().longi, “route ending”, “stop”);
}

//start file opening with default (google earth) application
Process.Start(fname);

3 thoughts on “TNX.KML”

  1. I simply desired to say thanks yet again. I am not sure the things that I would have used in the absence of the actual techniques documented by you regarding such concern. Certainly was a terrifying circumstance in my opinion, nevertheless coming across the very professional mode you resolved the issue made me to cry with joy. I am just thankful for this guidance and in addition trust you realize what a great job you are always putting in training most people through your site. I am certain you’ve never encountered any of us.

  2. Thank you so much for providing individuals with such a remarkable chance to check tips from this blog. It is always very lovely and also stuffed with a good time for me and my office friends to search your web site not less than thrice in 7 days to study the fresh items you have. And indeed, I’m always astounded with all the mind-boggling pointers you serve. Certain 1 areas in this posting are clearly the very best I’ve had.

Lascia un commento