How to use the fastkml.kml.KML function in fastkml

To help you get started, we’ve selected a few fastkml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cleder / fastkml / fastkml / test_main.py View on Github external
def test_placemark(self):
        doc = """
          
            Simple placemark
            Attached to the ground. Intelligently places itself
               at the height of the underlying terrain.
            
              -122.0822035425683,37.42228990140251,0
            
          
        """
        k = kml.KML()
        k.from_string(doc)
        self.assertEqual(len(list(k.features())), 1)
        self.assertEqual(list(k.features())[0].name, "Simple placemark")
        k2 = kml.KML()
        k2.from_string(k.to_string())
        self.assertEqual(k.to_string(), k2.to_string())
github cleder / fastkml / fastkml / test_main.py View on Github external
7fffaaff
              1.5
            
            
              ff0000ff
              15
            
            
              7f7faaaa
              random
            
          
          
        
        """
        k = kml.KML()
        k.from_string(doc)
        self.assertEqual(len(list(k.features())), 1)
        self.assertTrue(
            isinstance(list(list(k.features())[0].styles())[0], styles.Style)
        )
        style = list(list(list(k.features())[0].styles())[0].styles())
        self.assertEqual(len(style), 4)
        k2 = kml.KML()
        k2.from_string(k.to_string())
        self.assertEqual(k.to_string(), k2.to_string())
github cleder / fastkml / fastkml / test_main.py View on Github external
<data name="holePar">
                The par for this hole is 
                ]]&gt;
                4
              </data>
              
                Mount Everest
                347.45
                10000
              
            
          
        """
        k = kml.KML()
        k.from_string(doc)

        extended_data = list(k.features())[0].extended_data

        self.assertEqual(extended_data.elements[0].name, 'holeNumber')
        self.assertEqual(extended_data.elements[0].value, '1')
        self.assertTrue(
            '<b>This is hole </b>' in extended_data.elements[0].display_name
        )

        self.assertEqual(extended_data.elements[1].name, 'holePar')
        self.assertEqual(extended_data.elements[1].value, '4')
        self.assertTrue(
            '<i>The par for this hole is </i>' in extended_data.elements[1].display_name
        )
        sd = extended_data.elements[2]
github cleder / fastkml / examples / UsageExamples.py View on Github external
from fastkml import kml

def print_child_features(element):
    """ 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 feature.name
        print_child_features(feature)

if __name__ == '__main__':
    
    fname = "KML_Samples.kml"

    k = kml.KML()

    with open(fname) as kmlFile:
        k.from_string(kmlFile.read())    

    print_child_features(k)
github heronyang / airport-simulation / data / sfo-terminal-2 / generate.py View on Github external
def get_kml_document():

    k = kml.KML()
    with open(INPUT_KML, "rb") as f:
        k.from_string(f.read())
    return list(k.features())[0]
github xoolive / traffic / traffic / drawing / kml.py View on Github external
def export(filename: str):
    global current_document
    kml_tree = kml.KML()
    current_document = kml.Document()
    yield current_document
    kml_tree.append(current_document)
    with open(filename, "w", encoding="utf8") as kml_file:
        kml_file.write(kml_tree.to_string(prettyprint=True))
    _stylemap.clear()
    current_document = None
github heronyang / airport-simulation / data / sfo / generate.py View on Github external
def generate_pushback_way():

    k = kml.KML()
    nodes = []

    # Reads spot data from input KML file
    with open("pushback_way.kml", "rb") as f:
        k.from_string(f.read())

    links = []
    items = list(list(k.features())[0].features())
    for item in items:
        name = item.name
        index = name[1:]
        nodes = []
        for coordinate in item.geometry.coords:
            nodes.append(coordinate[:2])
        links.append({
            "name": name,
github heronyang / airport-simulation / data / sfo / generate.py View on Github external
def generate_spot_position_data():

    # Create the KML object to store the parsed result
    k = kml.KML()
    nodes = []

    # Reads spot data from input KML file
    with open("spot.kml", "rb") as f:
        k.from_string(f.read())

    items = list(list(k.features())[0].features())
    for item in items:
        index, name = int(item.name[1:]), item.name
        lat, lng = item.geometry.y, item.geometry.x
        nodes.append({
            "index": index,
            "name": name,
            "lat": lat,
            "lng": lng
        })
github heronyang / airport-simulation / data / simple / generate.py View on Github external
def get_kml_document():

    k = kml.KML()
    with open(INPUT_KML, "rb") as f:
        k.from_string(f.read())
    return list(k.features())[0]