Export Datatable to KML file

767 Views Asked by At

i Guys, I have a problem when i export a datable of 1000 records to a KML file with c#, When i export it only the last placemark is write in to the kml file, but i dont know why...

This is my code

public static void generar_kml(DataTable data_gps)
{
    var document = new Document();
    var kml = new Kml();
    Placemark placemarks;
    Point Punto_gps;
    foreach (DataRow datatable in data_gps.Rows)
    {
        Punto_gps = new Point();
        Punto_gps.Coordinate = new 
        Vector(double.Parse(datatable["Long"].ToString()),
        double.Parse(datatable["Lat"].ToString()));
        placemarks = new Placemark();
        placemarks.Name = datatable["Place"].ToString();
        placemarks.Geometry = Punto_gps;
        kml.Feature = placemarks;
    }
    Serializer serializer = new Serializer();
    serializer.Serialize(kml);
    Console.WriteLine(serializer.Xml);
    Console.ReadKey();  
}

this is the output;

<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Placemark>
    <name>Name of place</name>
<Point>
    <coordinates>-84.135109999999997,9.9416100000000007</coordinates>
</Point>
</Placemark>
</kml>"
1

There are 1 best solutions below

0
On

You need to add document.AddFeature(placemarks); inside the foreach. You dont need the kml.feature line.