本文整理汇总了Python中pykml.factory.KML_ElementMaker.kml方法的典型用法代码示例。如果您正苦于以下问题:Python KML_ElementMaker.kml方法的具体用法?Python KML_ElementMaker.kml怎么用?Python KML_ElementMaker.kml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pykml.factory.KML_ElementMaker
的用法示例。
在下文中一共展示了KML_ElementMaker.kml方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: navigation_route
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import kml [as 别名]
def navigation_route():
"""
Flask route that dynamically generates a KML of the current navigation
outputs from the navigation module.
"""
# Retrieve origin and create a list of KML attributes
origin = mission_planner.environment.origin
rover_position = mission_planner.navigator.position
rover_rotation = mission_planner.navigator.rotation
rover_location = (rover_position, rover_rotation)
goal = mission_planner.navigator.goal
kml_list = [KML.name("SRR Navigation")]
# Add placemark for rover location estimate.
kml_list.append(frame_placemark(
origin, "Rover", rover_position.x, rover_position.y, rover_rotation,
marker='rover.png'))
# Add placemark for navigation goal.
if goal is not None:
global_goal = srr.util.to_world(rover_location, goal)
kml_list.append(frame_placemark(
origin, "Goal", global_goal.x, global_goal.y,
marker='goal.png', color='ff00ffff'))
# Create a KML document with this environment represented.
doc = KML.kml(
KML.Document(
*kml_list
)
)
return etree.tostring(doc)
示例2: get_kml_doc
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import kml [as 别名]
def get_kml_doc(llhs):
"""Generates a KML document from a Pandas table of single point
solutions. Requires columns lat, lon, and height.
"""
from pykml.parser import Schema
from pykml.factory import KML_ElementMaker as KML
from pykml.factory import GX_ElementMaker as GX
center = llhs[['lat', 'lon', 'height']].mean()
elts = lambda e: '%s,%s,%d' % (e['lon'], e['lat'], e['height'])
coords = ' '.join(llhs.apply(elts, axis=1).values)
xml_coords = KML.coordinates(coords)
doc = KML.kml(
KML.Placemark(
KML.name("gx:altitudeMode Example"),
KML.LookAt(
KML.longitude(center.lon),
KML.latitude(center.lat),
KML.heading(center.height),
KML.tilt(70),
KML.range(6300),
GX.altitudeMode("relativeToSeaFloor"),),
KML.LineString(
KML.extrude(1),
GX.altitudeMode("relativeToSeaFloor"),
xml_coords
)
)
)
return doc
示例3: plot_kml
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import kml [as 别名]
def plot_kml(galaxy):
"""
Hacky function to dump a galaxy to a kml. Be sure pykml is installed before using.
"""
from pykml.factory import KML_ElementMaker as KML
from lxml import etree
fld = KML.kml()
for system in galaxy:
a = KML.Placemark(
KML.name('foo'),
KML.Point(
KML.coordinates('%f,%f' % (galaxy[system]["position_x"],galaxy[system]["position_y"]))
)
)
fld.append(a)
for dest in galaxy[system]['destinations']:
a = KML.Placemark(
KML.name("foo"),
KML.LineString(
KML.coordinates(
"%s,%s %s,%s" % (galaxy[system]["position_x"],galaxy[system]["position_y"], galaxy[dest]["position_x"],galaxy[dest]["position_y"])
)
)
)
fld.append(a)
f = open("test.kml", 'wa')
f.write(etree.tostring(fld, pretty_print=True))
f.close()
示例4: generate_kml
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import kml [as 别名]
def generate_kml(places):
doc = KML.kml(
KML.Document(
KML.Name("Awesome places"),
KML.Style(
KML.IconStyle(
KML.scale(1.2),
KML.Icon(
KML.href("http://maps.google.com/mapfiles/kml/pal4/icon28.png")
),
)
)
)
)
for data in places:
pm = KML.Placemark(
KML.name(data.get("name")),
KML.Point(KML.coordinates(str(data.get("lng")) + "," + str(data.get("lat"))))
)
doc.Document.append(pm)
result = etree.tostring(doc, pretty_print=True)
result.replace("placemark", "Placemark")
result.replace("point", "Point")
return result
示例5: update_kml
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import kml [as 别名]
def update_kml(self, request, response):
change = KML.Change()
create = KML.Create()
delete = KML.Delete()
doc = KML.Document(targetId=KmlPlacemark.DOC_ID)
for id_, kpm in self.placemarks.items():
if kpm.is_new:
style_url = KmlStyleUtils.get_style_url_for_callsign(kpm.callsign)
model_url = None # KmlStyleUtils.get_model_url_for_callsign(kpm.callsign, request.host_url)
placemark = kpm.get_placemark(style_url, model_url)
doc.append(placemark)
kpm.is_new = False
else:
kpm.generate_update(change = change, create = create, delete = delete)
if doc.countchildren() > 0:
create.append(doc)
update = KML.Update(KML.targetHref(request.path_url))
if change.countchildren() > 0:
update.append(change)
if create.countchildren() > 0:
update.append(create)
if delete.countchildren() > 0:
update.append(delete)
network_link_control = KML.NetworkLinkControl(update)
return KML.kml(network_link_control)
示例6: TranslateShpFileToKML
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import kml [as 别名]
def TranslateShpFileToKML(file):
print 'Translating file %s' % file
basename = os.path.splitext(os.path.basename(file))[0]
doc = KML.kml(
KML.Document(
KML.name('US Census Tracts ' + basename),
KML.Style(
KML.LineStyle(
KML.color('ff00ff00'),
KML.width(2)
),
KML.PolyStyle(
KML.color('66006600')
),
id="ts"
)
)
)
ProcessShpFile(file, basename, doc)
kmlFilename = os.path.join(os.path.dirname(file), basename + '.kml')
print 'Writing output file %s' % kmlFilename
outputFile = open(kmlFilename, 'w+')
outputFile.write(etree.tostring(doc, pretty_print=True))
outputFile.close()
示例7: initDocument
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import kml [as 别名]
def initDocument():
doc = KML.kml(
KML.Document(
KML.Name("Sun Position"),
KML.Style(
KML.IconStyle(
KML.scale(1.2),
KML.Icon(
KML.href("http://maps.google.com/mapfiles/kml/shapes/shaded_dot.png")
),
),
id="truc"
),
KML.Style(
KML.LineStyle(
KML.color("ff0000ff"),
KML.width(1)
),
KML.PolyStyle(
KML.color("ffff0000")
),
id="redLineBluePoly"
)
)
)
return doc
示例8: kml
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import kml [as 别名]
def kml(locations):
"""KML file for the locations
"""
# create document
document = KML.kml(KML.Document(KML.name("Layer example")))
# bullets
for layer_code,layer_name in categories(locations):
style = KML.Style(
KML.IconStyle(
KML.scale(1.0),
KML.Icon(
KML.href('%slocations/%s.png' % (settings.MEDIA_URL, layer_code)),
),
id='icon-%s' % layer_code
),
id=layer_code
)
document.append(style)
# locations
folder = KML.Folder()
for location in locations:
placemark = KML.Placemark(
KML.name(location['title']),
KML.description('<![CDATA[ %s ]]>' % location['description']),
KML.styleUrl('#%s' % location['category']),
KML.Point(
KML.coordinates(','.join([location['lng'],location['lat']]))
),
)
folder.append(placemark)
document.append(folder)
# rettsugo!
return etree.tostring(document)
示例9: test_basic_kml_document_2
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import kml [as 别名]
def test_basic_kml_document_2(self):
"""Tests the creation of a basic OGC KML document."""
doc = KML.kml(
KML.Document(
KML.name("KmlFile"),
KML.Placemark(
KML.name("Untitled Placemark"),
KML.Point(
KML.coordinates("-95.265,38.959,0")
)
)
)
)
self.assertTrue(Schema("kml22gx.xsd").validate(doc))
self.assertEquals(
etree.tostring(doc),
'<kml xmlns:gx="http://www.google.com/kml/ext/2.2" '
'xmlns:atom="http://www.w3.org/2005/Atom" '
'xmlns="http://www.opengis.net/kml/2.2">'
'<Document>'
'<name>KmlFile</name>'
'<Placemark>'
'<name>Untitled Placemark</name>'
'<Point>'
'<coordinates>-95.265,38.959,0</coordinates>'
'</Point>'
'</Placemark>'
'</Document>'
'</kml>'
)
示例10: test_basic_kml_document_2
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import kml [as 别名]
def test_basic_kml_document_2(self):
"""Tests the creation of a basic OGC KML document."""
doc = KML.kml(
KML.Document(
KML.name('KmlFile'),
KML.Placemark(
KML.name('Untitled Placemark'),
KML.Point(
KML.coordinates('-95.265,38.959,0')
)
)
)
)
# validate against a local schema
self.assertTrue(Schema('ogckml22.xsd').validate(doc))
# validate against a remote schema
self.assertTrue(Schema('http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd').validate(doc))
data = etree.tostring(doc, encoding='ascii')
expected = \
b'<kml xmlns:gx="http://www.google.com/kml/ext/2.2" ' \
b'xmlns:atom="http://www.w3.org/2005/Atom" ' \
b'xmlns="http://www.opengis.net/kml/2.2">' \
b'<Document>' \
b'<name>KmlFile</name>' \
b'<Placemark>' \
b'<name>Untitled Placemark</name>' \
b'<Point>' \
b'<coordinates>-95.265,38.959,0</coordinates>' \
b'</Point>' \
b'</Placemark>' \
b'</Document>' \
b'</kml>'
self.assertXmlEquivalentOutputs(data, expected)
示例11: test_basic_kml_document
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import kml [as 别名]
def test_basic_kml_document(self):
"""Tests the creation of a basic KML with Google Extensions ."""
doc = KML.kml(
GX.Tour(
GX.Playlist(
GX.SoundCue(
KML.href('http://dev.keyhole.com/codesite/cntowerfacts.mp3')
),
GX.Wait(
GX.duration(10)
),
GX.FlyTo(
GX.duration(5),
GX.flyToMode('bounce'),
KML.LookAt(
KML.longitude(-79.387),
KML.latitude(43.643),
KML.altitude(0),
KML.heading(-172.3),
KML.tilt(10),
KML.range(1200),
KML.altitudeMode('relativeToGround'),
)
)
)
)
)
self.assertTrue(Schema('kml22gx.xsd').validate(doc))
data = etree.tostring(doc, encoding='ascii')
expected = \
b'<kml xmlns:gx="http://www.google.com/kml/ext/2.2" ' \
b'xmlns:atom="http://www.w3.org/2005/Atom" ' \
b'xmlns="http://www.opengis.net/kml/2.2">' \
b'<gx:Tour>' \
b'<gx:Playlist>' \
b'<gx:SoundCue>' \
b'<href>http://dev.keyhole.com/codesite/cntowerfacts.mp3</href>' \
b'</gx:SoundCue>' \
b'<gx:Wait>' \
b'<gx:duration>10</gx:duration>' \
b'</gx:Wait>' \
b'<gx:FlyTo>' \
b'<gx:duration>5</gx:duration>' \
b'<gx:flyToMode>bounce</gx:flyToMode>' \
b'<LookAt>' \
b'<longitude>-79.387</longitude>' \
b'<latitude>43.643</latitude>' \
b'<altitude>0</altitude>' \
b'<heading>-172.3</heading>' \
b'<tilt>10</tilt>' \
b'<range>1200</range>' \
b'<altitudeMode>relativeToGround</altitudeMode>' \
b'</LookAt>' \
b'</gx:FlyTo>' \
b'</gx:Playlist>' \
b'</gx:Tour>' \
b'</kml>'
self.assertXmlEquivalentOutputs(data, expected)
示例12: main
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import kml [as 别名]
def main():
kmlobj = KML.kml( KML.Document(KML.Style(KML.LabelStyle(KML.scale(6)),id="big_label")))
data = '<?xml version="1.0" encoding="utf-8"?>\n<kml xmlns="http://www.opengis.net/kml/2.2">\n<Document>\n<name>Balloon with image</name>'
cconn = CloudConn.CloudConn(mav_id)
id = raw_input("flt_?")
stat , vals = cconn.getallfromflt(int(id))
counter = 0
if stat == cons.SUCCESS:
for each in vals:
lat = float(each[0].split(",")[0].split("=")[1])
lon = float(each[0].split(",")[1].split("=")[1])
alt = float(each[0].split(",")[2].split("=")[1])
kmlobj.Document.append(
KML.Placemark(
KML.name("ECE-445-DEMO"),
KML.Point(
KML.extrude(1),
KML.altitudeMode('relativeToGround'),
KML.coordinates('{lon},{lat},{alt}'.format(
lon=lon,
lat=lat,
alt=alt,
),
))))
#pm1 = KML.Placemark(KML.name(str(counter)),KML.Point(KML.coordinates(latlonstr)))
dax = etree.tostring(etree.ElementTree(kmlobj),pretty_print=True)
fd = open(fname+".kml", 'wb')
fd.write(dax)
fd.close()
示例13: build_test_kml
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import kml [as 别名]
def build_test_kml():
"""build a simple KML file with a simple LineString, for testing purposes"""
from pykml.factory import KML_ElementMaker as KML
from pykml.factory import GX_ElementMaker as GX
from lxml import etree
from django.http import HttpResponse
kml = KML.kml(
KML.Placemark(
KML.name("build_test_kml output"),
KML.LookAt(
KML.longitude(146.806),
KML.latitude(12.219),
KML.heading(-60),
KML.tilt(70),
KML.range(6300),
GX.altitudeMode("relativeToSeaFloor"),
),
KML.LineString(
KML.extrude(1),
GX.altitudeMode("relativeToSeaFloor"),
KML.coordinates(
"146.825,12.233,400 "
"146.820,12.222,400 "
"146.812,12.212,400 "
"146.796,12.209,400 "
"146.788,12.205,400"
),
),
)
)
kml_str = etree.tostring(kml)
return HttpResponse(kml_str, content_type="application/vnd.google-earth.kml")
示例14: build_kml
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import kml [as 别名]
def build_kml(location_seq):
placemark_list = []
for name, lat, lng in location_seq:
pm = generate_placemark(name, lat, lng, RADIUS, CIRCLE_SEGMENTS)
placemark_list.append(pm)
return KML.kml(KML.Document(*placemark_list))
示例15: generateKML
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import kml [as 别名]
def generateKML(ids, spotList):
km = KML.kml()
doc = KML.Document(KML.name("Aires camping car info"))
icones = glob.glob(LOGOS_FOLDER+"A*")
for icone in icones:
icone = icone.replace(DESC_FOLDER, "")
type = os.path.basename(icone).replace("40.gif", "")
style = KML.Style(
KML.IconStyle(
KML.scale(1.0),
KML.Icon(
KML.href(icone),
),
),
id=type.lower()
)
doc.append(style)
for id in ids:
idStr = str(id)
with codecs.open(DESC_FOLDER+"/"+idStr+".html",'r',encoding='utf-8') as f:
place = KML.Placemark(
KML.name(spotList[id]["name"]),
KML.description(f.read()),
KML.styleUrl("#"+spotList[id]["type"].lower()),
KML.Point(
KML.coordinates(spotList[id]["lat"]+","+spotList[id]["long"])
)
)
doc.append(place)
km.append(doc)
print(etree.tostring(km))