我将google earth中的几个坐标保存为kml文件。下面的代码为我提供了第一个位置的坐标。知道如何得到剩下的吗-我将不得不以某种方式迭代所有位置。
from pykml import parser
with open('list.kml', 'r') as f:
root = parser.parse(f).getroot()
print(root.Document.Placemark.Point.coordinates)
您可以使用
for i in root.findall('.//{http://www.opengis.net/kml/2.2}Point'):
print(i.coordinates)
或者,为Document/Placemark/Point
:提供更精确的路径
for i in root.findall('{http://www.opengis.net/kml/2.2}Document/{http://www.opengis.net/kml/2.2}Placemark/{http://www.opengis.net/kml/2.2}Point'):
print(i.coordinates)