File: simple_example.py

package info (click to toggle)
fastkml 1.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,552 kB
  • sloc: python: 18,501; xml: 539; makefile: 16
file content (22 lines) | stat: -rwxr-xr-x 575 bytes parent folder | download
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)