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:
k = kml.KML()

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?

  • Does this print(p.geometry) give you anything? – Taras Nov 28 '19 at 7:44
  • Yes! It gives POINT Z (-98.88773425196743 19.19703568013584 0). The question now is, how can this POINT Z thing be transformed into pure numbers? – Michael Nov 28 '19 at 8:00

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

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.