我想下载一个 KML 文件并在 Python 中将其特定元素打印为字符串。
谁能给我一个如何做到这一点的例子吗?
谢谢。
最佳答案
下载和解析我将留给另一个答案。以下是我检索 KML 文件中每个地标的描述和坐标的方法。
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 循环也许可以重写,但我还没有找到确切的方法。
关于python - KML 到 Python 中的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7821977/