当前位置:文档之家› 将数据写入KML文件

将数据写入KML文件

将CPoint结构写入KML文件中,使用文件流提高速度。

1、需包含” fstream”文件
#include <fstream>
2、例子:
void WriteToKML(char *filename,vector<CPoint> sourcedata)
{
ofstream o_file;
o_file.open(filename,ios::trunc|ios::binary);
o_file<<"<?xml version='1.0' encoding='UTF-8'?>\r\n";
o_file<<"<kml xmlns='/kml/2.2'>\r\n";
o_file<<"<Document>\r\n";
o_file<<"<name>";
o_file<<filename;
o_file<<"</name>\r\n";
o_file<<"<Style id='yellowLine'>\r\n";
o_file<<"<LineStyle>\r\n";
o_file<<"<color>7f00ffff</color>\r\n";
o_file<<"<width>2</width>\r\n";
o_file<<"</LineStyle>\r\n";
o_file<<"<PolyStyle>\r\n";
o_file<<"<color>7f00ff00</color>\r\n";
o_file<<"</PolyStyle>\r\n";
o_file<<"</Style>\r\n";
o_file<<"<Placemark>\r\n";
o_file<<"<name>Flight Path</name>\r\n";
o_file<<"<description>Flight Route path</description>\r\n";
o_file<<"<styleUrl>#yellowLine</styleUrl>\r\n";
o_file<<"<visibility>1</visibility>";
o_file<<"<open>0</open>";
o_file<<"<LineString>\r\n";
o_file<<"<extrude>1</extrude>\r\n";
o_file<<"<tessellate>1</tessellate>\r\n";
o_file<<"<altitudeMode>absolute</altitudeMode>\r\n";
o_file<<"<coordinates>\r\n";
int numb = sourcedata.size();
int count;
for (count=0;count < numb;count++)
{
o_file<<setprecision(12)<<sourcedata[count].x<<","
o_file<<setprecision(12)<<sourcedata[count].y;
}
o_file<<"</coordinates>\r\n </LineString>\r\n </Placemark>\r\n";
o_file<<"</Document>\r\n </kml>";
o_file.close();
}。

相关主题