将数据从c++文件输入到KML文件
Enter data to KML file from c++ file
我需要输入从c++文件到KML文件的坐标才能使用Google Earth运行,你会怎么做?KML文件为:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"
xmlns:gx="http://www.google.com/kml/ext/2.2"
xmlns:kml="http://www.opengis.net/kml/2.2"
xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
<name>Path.kml</name>
<Style id="pathstyle">
<LineStyle>
<color>ff190cff</color>
<width>2</width>
</LineStyle>
</Style>
<Placemark>
<name>Path</name>
<description>This is the path between the 2 points</description>
<styleUrl>#pathstyle</styleUrl>
<LineString>
<tessellate>1</tessellate>
<coordinates>
long1,lat1,0
long2,lat2,0
</coordinates>
</LineString>
</Placemark>
当纬度和经度输入到c++文件中时,我将如何输入该文件中的数据?它们被声明为双浮点
这里有一个我成功使用的策略:创建一系列函数来逐步构建KML/XML。例如,这里有一个函数来序列化KML:的Placemark
部分
(另请参阅现场演示。)
#include <fstream>
#include <sstream>
#include <string>
std::string FormatPlacemark(double lat1, double long1, double lat2, double long2)
{
std::ostringstream ss;
ss << "<Placemark>n"
<< "<name>Path</name>n"
<< "<description>This is the path between the 2 points</description>n"
<< "<styleUrl>#pathstyle</styleUrl>n"
<< "<LineString>n"
<< "<tessellate>1</tessellate>n"
<< "<coordinates>"
<< long1 << "," << lat1 << ",0"
<< " "
<< long2 << "," << lat2 << ",0"
<< "</coordinates>n"
<< "</LineString>n"
<< "</Placemark>n";
return ss.str();
}
以下是如何创建/打开您的KML文件并对其进行写入:
std::ofstream handle;
// http://www.cplusplus.com/reference/ios/ios/exceptions/
// Throw an exception on failure to open the file or on a write error.
handle.exceptions(std::ofstream::failbit | std::ofstream::badbit);
// Open the KML file for writing:
handle.open("C:/Output/Sample.kml");
// Write to the KML file:
handle << "<?xml version='1.0' encoding='utf-8'?>n";
handle << "<kml xmlns='http://www.opengis.net/kml/2.2'>n";
handle << FormatPlacemark(-76.2, 38.5, -76.1, 38.6);
handle << "</kml>n";
handle.close();
相关文章:
- C++文本文件输入
- C++ 中文件输入输出中的长长 v/s int
- 如何修复函数中的 fstream 文件输入以将正确的信息存储在结构数组中?
- 用空格填充 2D 数组(从文件输入)
- 流对象来表示文件输入,然后是标准输入?
- 用精神解析文件输入
- 从文件输入和输出
- 来自文本文件输入 c++ 的向量
- 如何通过键盘或分数文件输入分数
- 了解文件输入和输出,我可以写入文件,但无法从文件打印
- 词频程序 - 文件输入太大?
- 尝试从 csv 文件输入大量数据时出错
- 如何将文件从文件输入到C 中的矩阵中
- 如何从Windows CMD运行可执行文件并将其传递给文件输入的参数参数和重定向
- 如何解析文本文件并使用构造函数中的文件输入来创建对象的容器
- 这是读取文件输入的正确方法吗?
- 如何在 c++ 中使用二进制文件输入/输出读取/写入结构的字符串类型成员
- 如何创建一个具有空值、递减编号系统和.txt文件输入值的二维阵列网格
- C 文件输入流循环问题
- 使用对输入整数的文件输入