如何使用simplekml删除KML元素?

时间:2019-06-04 13:21:19

标签: python-3.x simplekml

我在Python脚本中使用simpleKML创建一个KML文件。添加元素很容易,但是我希望能够再次删除元素。

我检查了stack Overflow Answer,发现可以“从现有对象中删除元素”。但是,我对simpleKML的简单性印象深刻,我宁愿坚持使用此软件包。

Fx。从MultiGeometry中删除第二个Point(此处为id =“ 17”):

<?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 id="1">
        <Placemark id="11">
            <MultiGeometry id="10">
                <Point id="15">
                    <coordinates>9.042574667,51.834697333,0.0</coordinates>
                </Point>
                <Point id="17">
                    <coordinates>9.0425585,51.834703333,0.0</coordinates>
                </Point>
                <Point id="19">
                    <coordinates>9.042558833,51.834702667,0.0</coordinates>
                </Point>
            </MultiGeometry>
        </Placemark>
    </Document>
</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 id="1">
        <Placemark id="11">
            <MultiGeometry id="10">
                <Point id="15">
                    <coordinates>9.042574667,51.834697333,0.0</coordinates>
                </Point>
                <Point id="19">
                    <coordinates>9.042558833,51.834702667,0.0</coordinates>
                </Point>
            </MultiGeometry>
        </Placemark>
    </Document>
</kml>

由于simpleKML会自动向所有元素添加“ id”属性,因此拥有诸如getElementById之类的东西并从kml对象中删除行应该很简单。至少对于那些比我更有能力进行编码的人来说,很简单。

0 个答案:

没有答案