kml 用实线连接地标

kml connect placemarks with a solid line

我写了一个 kml 文件,里面充满了带有名称、描述和坐标的地标。它的结构是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
  <name>test</name>
  <description><![CDATA[test]]></description>
        <Placemark>
            <name>name 1</name>
            <description>description 1</description>
            <Point>
                <coordinates>18.70669,36.12645</coordinates>
            </Point>
        </Placemark>

        <Placemark>
            <name>name 2</name>
            <description>description 2</description>
            <Point>
                <coordinates>18.70513,36.12698</coordinates>
            </Point>
        </Placemark>
</Document>
</kml>

我发现连接它们的唯一方法是使用 <MultiGeometry><LineString><coordinates>,但我正在寻找更智能、更小的解决方案。 python 脚本也可以作为解决方案接受。

如果我没理解错的话,你要做的就是用一条线连接两个坐标?如果是这样,您需要做的就是使用 <LineString>:

<LineString id="geom_842">
    <coordinates>18.70669,36.12645,0.0 18.70513,36.12698,0.0 </coordinates>
</LineString>

使用 documentation 中的 python:

import simplekml
kml = simplekml.Kml()
lin = kml.newlinestring(name="name", description="description",
      coords=[(18.70669,36.12645), (18.70513,36.12698)])
kml.save('filename.kml')