Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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())
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())
<data name="holePar">
The par for this hole is
]]>
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]
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)
def get_kml_document():
k = kml.KML()
with open(INPUT_KML, "rb") as f:
k.from_string(f.read())
return list(k.features())[0]
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
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,
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
})
def get_kml_document():
k = kml.KML()
with open(INPUT_KML, "rb") as f:
k.from_string(f.read())
return list(k.features())[0]