相关疑难解决方法(0)

使用Python从KML BatchGeo文件中提取坐标

我已经将一些地址上传到BatchGeo并下载了生成的KML文件,我想从中提取坐标.我设法美化冗杂的文本文件在线在这里,但我不知道如何分析它以提取坐标.

<?xml version="1.0" ?>
<kml xmlns="http://earth.google.com/kml/2.0">
    <Document>
        <Placemark>
            <name>...</name>
            <description>....</description>
            <Point>
                <coordinates>-3.1034345755337,57.144817425039,0</coordinates>
            </Point><address>...</address>
            <styleUrl>#0</styleUrl>
        </Placemark>
    </Document>
</kml>
Run Code Online (Sandbox Code Playgroud)

似乎有几个用于python的kml库,但在文档方面并不多(例如pyKML).使用本教程,我已经做到了这一点并创建了一个'lxml.etree._ElementTree'对象,但我不确定它的属性:

from pykml import parser

kml_file = "BatchGeo.kml"

with open(kml_file) as f:

    doc = parser.parse(f)

coordinate = doc.Element("coordinates")
print coordinate
Run Code Online (Sandbox Code Playgroud)

这给出了错误:

AttributeError: 'lxml.etree._ElementTree' object has no attribute 'Element'
Run Code Online (Sandbox Code Playgroud)

那么如何获得坐标列表呢?谢谢.

python lxml geocoding kml

5
推荐指数
1
解决办法
8334
查看次数

标签 统计

geocoding ×1

kml ×1

lxml ×1

python ×1