将Datatable导出到KML文件

时间:2018-03-06 04:08:31

标签: c# sharpkml

我是男人, 当我使用c#将1000条记录的数据导出到KML文件时出现问题,当我导出它时,只有最后一个地标写入kml文件,但我不知道为什么......

这是我的代码

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();  
}

这是输出;

<?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 个答案:

答案 0 :(得分:1)

您需要添加document.AddFeature(placemarks);在foreach里面。您不需要kml.feature行。