1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
#!/usr/bin/env python
import pathlib
from fastkml import kml
def print_child_features(element, depth=0):
"""Prints the name of every child node of the given element, recursively."""
if not getattr(element, "features", None):
return
for feature in element.features:
print(" " * depth, feature.name)
print_child_features(feature, depth + 1)
if __name__ == "__main__":
examples_dir = pathlib.Path(__file__).parent
fname = pathlib.Path(examples_dir / "KML_Samples.kml")
k = kml.KML.parse(fname)
print_child_features(k)
|