[GIS] Extracting coordinates of placemark from KML using FastKML

coordinatesfastkmlkmlpython

I would like to parse a KML document in order to put the information (names of placemarks, coordinates) into a python array for further processing. This is what I have so far:

from fastkml import kml

with open('evalPoints.kml') as myfile:
    doc=myfile.read()
k = kml.KML()
k.from_string(doc)

outerFeature = list(k.features())
innerFeature = list(outerFeature[0].features())

placemarks = list(innerFeature[0].features())

for p in placemarks:
    coords = p.coordinates #this does not work

Unfortunately, parsing the coordinates does not work, while parsing the name of the placemarks works like a charm with p.name. What am I doing wrong?

Best Answer

Thanks to the comment of Taras, I found the answer. The coordinates can be extracted based on Shapely commands, i.e. by using p.geometry.x, p.geometry.y

Related Question