【问题标题】:Export Datatable to KML file将数据表导出到 KML 文件
【发布时间】:2018-03-06 04:08:30
【问题描述】:

我伙计们, 当我使用 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>"

【问题讨论】:

    标签: c# sharpkml


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-27
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多