Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
KML要在Python中使用字符串吗?_Python_Kml - Fatal编程技术网

KML要在Python中使用字符串吗?

KML要在Python中使用字符串吗?,python,kml,Python,Kml,我想下载一个KML文件,并在Python中将其特定元素打印为字符串 谁能给我举个例子说明怎么做 谢谢 您可以使用urllib在python中下载KML文件。要读取KML,可以使用解析器(搜索“KML python解析器”) 您可以使用urllib在python中下载KML文件。要读取KML,可以使用解析器(搜索“KML python解析器”) 谷歌新的pyKML库很适合这一点。见例 下面是一个非常简单的例子 谷歌新的pyKML库很适合这一点。见例 下面是一个非常简单的例子 下载和解析我将留给另一

我想下载一个KML文件,并在Python中将其特定元素打印为字符串

谁能给我举个例子说明怎么做


谢谢

您可以使用urllib在python中下载KML文件。要读取KML,可以使用解析器(搜索“KML python解析器”)

您可以使用urllib在python中下载KML文件。要读取KML,可以使用解析器(搜索“KML python解析器”)

谷歌新的pyKML库很适合这一点。见例

下面是一个非常简单的例子


谷歌新的pyKML库很适合这一点。见例

下面是一个非常简单的例子


下载和解析我将留给另一个答案。下面是我如何检索KML文件中每个placemark的描述和坐标的

namespace = {'ns' : 'http://www.opengis.net/kml/2.2'}
placemarks = doc.xpath('//ns:Placemark', namespaces=namespace)

for placemark in placemarks :
    for description in placemark.xpath('.//ns:description', namespaces=namespace):
        descriptionText = description.text.strip()

    for coords in placemark.xpath('.//ns:coordinates', namespaces=namespace):
        coordinates = coords.text.strip()

    # Here you have the description and coordinates

描述和坐标的for循环可能会被重写,但我还没有找到具体的重写方法。

下载和解析我将留给另一个答案。下面是我如何检索KML文件中每个placemark的描述和坐标的

namespace = {'ns' : 'http://www.opengis.net/kml/2.2'}
placemarks = doc.xpath('//ns:Placemark', namespaces=namespace)

for placemark in placemarks :
    for description in placemark.xpath('.//ns:description', namespaces=namespace):
        descriptionText = description.text.strip()

    for coords in placemark.xpath('.//ns:coordinates', namespaces=namespace):
        coordinates = coords.text.strip()

    # Here you have the description and coordinates

描述和坐标的for循环也许可以重写,但我还没有找到具体的重写方法。

KML只是XML。只需使用XML解析器来解析它。有没有可能用Python下载和解析XML的简单示例?迷失在一堆谷歌链接中的死掉的软件…检查一下lxml KML仅仅是XML。只需使用XML解析器来解析它。有没有可能用Python下载和解析XML的简单示例?迷失在一堆谷歌链接中的死掉的软件…看看lxml