我正在编写一个C ++类,该类可将数据即时写入KML文件中。
问题是我需要在<Point>
内写几个<Folder>
项,并同时在<LineString>
项内写出一条连接这些点的路径。
My KML
├── Points
| ├── Point 1
| ├── Point 2
| ├── Point 3
| └── ...
|
└── Path
由于我必须即时执行此操作,因此我需要找到一种在KML文件的不同部分中进行编写的方法,以免弄乱XML文档结构。
例如,假设我们有2分:
<Placemark>
<name>Point 1</name>
<Point>
<coordinates>11.807993,48.171485,536.15</coordinates>
</Point>
</Placemark>
<Placemark>
<name>Path</name>
<LineString>
<coordinates>
11.807993,48.171485,536.15
</coordinates>
</LineString>
</Placemark>
<Placemark>
<name>Point 2</name>
<Point>
<coordinates>11.807978,48.171473,538.92</coordinates>
</Point>
</Placemark>
<Placemark>
<name>Path</name>
<LineString>
<coordinates>
11.807993,48.171485,536.15
11.807978,48.171473,538.92
</coordinates>
</LineString>
</Placemark>
依此类推...
这就是生成的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">
<Document>
<name>My KML</name>
<Folder>
<name>Points</name>
<Placemark>
<name>Point 1</name>
<Point>
<coordinates>11.807993,48.171485,536.15</coordinates>
</Point>
</Placemark>
<Placemark>
<name>Point 2</name>
<Point>
<coordinates>11.807978,48.171473,538.92</coordinates>
</Point>
</Placemark>
</Folder>
<Placemark>
<name>Path</name>
<LineString>
<coordinates>
11.807993,48.171485,536.15
11.807978,48.171473,538.92
</coordinates>
</LineString>
</Placemark>
</Document>
</kml>
这只是一个简化的示例。在我的真实情况下,我将不得不使用数千/数百万个点来执行此操作。但是概念与上面相同。
由于我的代码旨在在内存资源非常稀缺/受限的设备上运行,因此我无法使用涉及在内存中构建某种树结构然后将其序列化为XML的解决方案。
我应该如何在C ++中实现这一目标?
编辑:
回答有关资源的评论时,我不能给出任何具体数字,但是目标机器上的瓶颈肯定是内存,这就是为什么我不能将所有坐标都保留在内存中以便以后打印。我必须以online的方式逐一打印每对坐标,并将相同的存储空间重新用于下一对坐标,以便在任何给定的时刻内存中只有一对坐标。>
编辑:
我想我能得出的结论是:
由于在同一文件的不同位置写入似乎很复杂且容易出错 [1] ,因此先写入2个不同的文件,然后再合并它们 [2] 似乎是可行的方法。