我想在c#中創建一個kml文件。現在我有兩個問題:使用xml元素創建kml文件
什麼是爲了在我的KML文件下面的一行添加KML元素在XML文件中的synatx?
<kml xmlns="http://www.opengis.net/kml/2.2">
我有一個點,我想形成一個線串的數組。我想如何在kml文件的xml中填充座標元素?以下是我的代碼到目前爲止。
CODE:
public void MakeKmlFile(string line)
{
CoordinateCollection coordinates = new CoordinateCollection();
char[] delimiterLine = { '|' };
char[] delimiterPoint = { ',' };
string[] route = line.Split(delimiterLine);
foreach (string point in route)
{
string[] route_point = line.Split(delimiterPoint);
double lat = double.Parse(route_point[1]);
double lon = double.Parse(route_point[0]);
coordinates.Add(new Vector(lat, lon));
}
XmlTextWriter writer = new XmlTextWriter("route.xml", System.Text.Encoding.UTF8);
writer.Formatting = Formatting.Indented;
writer.WriteStartElement("Document");
writer.WriteStartElement("Folder");
writer.WriteStartElement("name");
writer.WriteString("route");
writer.WriteEndElement();
writer.WriteStartElement("Placemark");
writer.WriteStartElement("Style");
writer.WriteStartElement("LineStyle");
writer.WriteStartElement("color");
writer.WriteString("ff0000ff");
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteStartElement("PolyStyle");
writer.WriteStartElement("fill");
writer.WriteString("2");
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteStartElement("LineString");
writer.WriteStartElement("coordinates");
這是結果我得到:
<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Name>Points.kml</Name>
<Placemark />
<Placemark />
<Placemark />
<Placemark />
<Placemark />
</Document>
注意PolyStyle填充元件具有1或0 => 「2」 是無效的值。 – JasonM1 2013-03-15 19:13:56