I've searched around quite a bit for this specific Python module, and haven't been able to find a source which points me in the right direction.
I'm trying to read a KML file and display all of the features inside of a folder, I believe I'm achieving this using fastkml, but I have a problem.
Using the following code everything works until the line, len(k.features). I tried printing it, adding quotes as shown in the documentation, but nothing works. Can anyone point me in the right direction?
Thanks.
Example: https://github.com/cleder/fastkml
Code:
from fastkml import kml
doc = file("Allpoints.kml").read()
k = kml.KML()
k.from_string(doc)
len(k.features())
Use Google Earth to open KML files You can view most simple KML files with Google Earth for Chrome (version 9) or in the Google Earth app on your mobile device. If you're unable to view complex KML files, use Google Earth for desktop (version 7), which supports all KML features.
Since KML files are saved in plain text, users may create KML files from scratch or by copying features from Google Earth Pro. To do this, right-click a feature in the 3D Viewer of Google Earth Pro and select Copy, then paste it into a TXT file open in a text editor. Users can then save .
Google Earth is a popular and highly suggested tool to open KML files. This wikiHow teaches you how to open KML files in Google Earth with both Mac and PC as well as the Google Earth app available for both Android and iOS devices.
On chrome go to https://www.google.com/earth/ • Click Launch Earth in Chrome. Click the Menu button on the left side navigation bar. Click Settings. Scroll to the bottom of the settings and where it says Enable KML file import turn it on then click save.
features()
returns a generator object that you can iterate over but it doesn't have a len
function:
for f in k.features():
print(f.name)
if you really need the length then you can use a list comprehension to turn the generator into a list:
features = list(k.features())
len(features)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With