Search code examples
pythongoogle-mapsmapslinekml

kml connect placemarks with a solid line


i've written a kml file full of placemarks with name, description and coordinates. It's structure is like this:

<?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>

The only way I found to connect them is by using <MultiGeometry><LineString><coordinates> but I'm looking for a smarter and smaller solution. A python script would be accepted as a solution too.


Solution

  • If I'm understanding this correctly, all you're looking to do is connect the two coordinates with a line? If so, all you need to do is use <LineString>:

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

    Using python from the documentation:

    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')