简体   繁体   中英

How to get all coordinates from kml file?

I saved a couple of coordinates from google earth as a kml file. The following code provides me with the coordinates of the first location. Any idea how to get the remaining ones?-I would somehow have to iterate over all locations.

from pykml import parser
 with open('list.kml', 'r') as f:
 root = parser.parse(f).getroot()
print(root.Document.Placemark.Point.coordinates)

You can use

for i in root.findall('.//{http://www.opengis.net/kml/2.2}Point'):
    print(i.coordinates)

Or, providing a more exact path to 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM