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