本文整理汇总了Python中pykml.factory.KML_ElementMaker类的典型用法代码示例。如果您正苦于以下问题:Python KML_ElementMaker类的具体用法?Python KML_ElementMaker怎么用?Python KML_ElementMaker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KML_ElementMaker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_kml
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()
示例2: to_kml
def to_kml(self, round=None):
from pykml.factory import KML_ElementMaker as KML
poly = KML.Polygon(
KML.tesselate("1")
)
outer = KML.outerBoundaryIs()
inner = KML.innerBoundaryIs()
has_inner = False
for i in range(len(self.poly)):
cnt = self.poly[i]
coords = ''
for p in cnt:
coords += ','.join(map(str, p)) + ' '
ring = KML.LinearRing(
KML.coordinates(coords)
)
#hole = self.poly.isHole(i)
#if hole == False:
outer.append(ring)
#else:
# inner.append(ring)
# has_inner = True
poly.append(outer)
if has_inner:
poly.append(inner)
return poly
示例3: init_kml_canvas
def init_kml_canvas(self):
from pykml.factory import KML_ElementMaker as KML
kml = KML.kml(
KML.Document(
KML.name('kartograph map')
)
)
return kml
示例4: create_reference_point_element
def create_reference_point_element(inps, lats, lons, ts_obj):
star_file = "star.png"
colormap = mpl.cm.get_cmap(inps.colormap) # set colormap
norm = mpl.colors.Normalize(vmin=inps.vlim[0], vmax=inps.vlim[1])
ref_yx = (int(ts_obj.metadata['REF_Y']), int(ts_obj.metadata['REF_X']))
ref_lalo = (lats[ref_yx[0], ref_yx[1]], lons[ref_yx[0], ref_yx[1]])
reference_point = KML.Placemark(
KML.Style(
KML.IconStyle(
KML.color(get_color_for_velocity(0.0, colormap, norm)),
KML.scale(1.),
KML.Icon(KML.href("{}".format(star_file)))
)
),
KML.description("Reference point <br /> \n <br /> \n" +
generate_description_string(ref_lalo, ref_yx, 0.00, 0.00, 0.00, 1.00)
),
KML.Point(
KML.coordinates("{}, {}".format(ref_lalo[1], ref_lalo[0]))
)
)
return reference_point, star_file
示例5: to_placemark
def to_placemark(t):
if t.route is None:
return None
geometries = []
for ls in t.route:
g = []
for lon, lat in ls:
g.append('{},{}'.format(lon, lat))
coordinates = ' '.join(g)
geometry = KML.LineString(
KML.coordinates(coordinates))
geometries.append(geometry)
name = t.number
if t.company is not None:
name = '{} {}'.format(t.company, t.number)
href = 'https://angkot.web.id/route/#/{}/'.format(t.id)
return KML.Placemark(
KML.name(name),
ATOM.link(href=href),
ATOM.updated(t.updated.isoformat()),
KML.MultiGeometry(*geometries))
示例6: createKMLFromContainer
def createKMLFromContainer(data, filename):
iconColors = ["ff0000ff", "ff00ff00", "ffff0000", "ff00ffff", "ffff00ff", "ffffff00"]
doc = KML.Document()
for i, color in enumerate(iconColors):
doc.append(
KML.Style(
KML.IconStyle(
KML.color(color),
),
id="report-style-" + str(i)
)
)
doc.append(KML.Folder("all"))
colorIndex = 0
for tIndex, task in enumerate(data):
print task
for hIndex, house in enumerate(task.info["houses"]):
pm = KML.Placemark(
KML.styleUrl("#report-style-" + str(colorIndex % len(iconColors))),
KML.name(str(tIndex) + "-" + str(hIndex)),
KML.Point(
KML.coordinates("{0},{1}".format(house["geometry"]["coordinates"][0],
house["geometry"]["coordinates"][1]))
)
)
doc.Folder.append(pm)
colorIndex += 1
out = open(filename, "wb")
out.write(etree.tostring(doc, pretty_print=True))
out.close()
示例7: create_network_link_element
def create_network_link_element(name, kml_file, ts_obj):
lats, lons = flatten_lalos(None, ts_obj)
network_link = KML.NetworkLink(
KML.name(name),
KML.visibility(1),
KML.Region(
KML.Lod(
KML.minLodPixels(0),
KML.maxLodPixels(1800)
),
KML.LatLonAltBox(
KML.north(lats[-1] + 0.5),
KML.south(lats[0] - 0.5),
KML.east(lons[-1] + 0.5),
KML.west(lons[0] - 0.5)
)
),
KML.Link(
KML.href(kml_file),
KML.viewRefreshMode('onRegion')
)
)
return network_link
示例8: setToKMLPolygon
def setToKMLPolygon (inputSet, isMultiGeometry):
"""initializes container list for Polygon Coordinates"""
PolygonCoords = []
"""Adds input coordinates to container list"""
for eachCoord in inputSet:
PolygonCoords.append(CoordinateToString(eachCoord, isMultiGeometry))
"""initializes string which contains polygon coordinates """
PolygonCoordinatesString = ''
for PolygonCoord in PolygonCoords:
PolygonCoordinatesString = PolygonCoordinatesString + str(PolygonCoord)
"""Creates the KML polygon object"""
KMLPolygon = KML.Polygon(
KML.outerBoundaryIs(
KML.LinearRing(
KML.coordinates(
PolygonCoordinatesString
)
)
)
)
return KMLPolygon
示例9: test_to_wkt_list_simple_polygon
def test_to_wkt_list_simple_polygon(self):
"""Tests the to_wkt_list function for a polygon with inner rings."""
from pykml.util import to_wkt_list
# create a polygon
poly = KML.Polygon(
KML.extrude('1'),
KML.altitudeMode('relativeToGround'),
KML.outerBoundaryIs(
KML.LinearRing(
KML.coordinates(
'-122.366278,37.818844,30 '
'-122.365248,37.819267,30 '
'-122.365640,37.819861,30 '
'-122.366669,37.819429,30 '
'-122.366278,37.818844,30 '
),
),
),
)
poly_wkt_list = to_wkt_list(poly)
self.assertEqual(len(poly_wkt_list), 1)
self.assertEqual(
poly_wkt_list[0],
('POLYGON ((-122.366278 37.818844 30, '
'-122.365248 37.819267 30, '
'-122.365640 37.819861 30, '
'-122.366669 37.819429 30, '
'-122.366278 37.818844 30))')
)
示例10: debugging
def debugging(latitude, longitude) :
global initLat, initLon, me, ne, lat, lon, carryY, carryX, fld, filebool, angles
lat=latitude
lon=longitude
#lat=filt(lat, a)
#lon=filt(lon, a)
#print lat, lon
lat_rad = lat *math.pi/180.0
lon_rad = lon *math.pi/180.0
if(filebool == True) :
pm = KML.Placemark(KML.name("Placemark %d" % count), KML.Point(KML.coordinates("%f,%f" % (lat, lon))))
fld.append(pm)
count = count + 1
try :
#print angles[2]
if(initLat == 0) :
br.sendTransform((0, 0, 0), tf.transformations.quaternion_from_euler(0, 0, carryYaw, "sxyz"), rospy.Time.now(), 'base_link', 'dummy')
(trans, rot) = listener.lookupTransform('map', 'base_link', rospy.Time())
angles = tf.transformations.euler_from_quaternion(rot)
initLat = lat_rad
initLon = lon_rad
me = earth_radius*(1-earth_ecc*earth_ecc)/((1-earth_ecc*earth_ecc*math.sin(lat_rad)*math.sin(lat_rad))**1.5)
ne = earth_radius/((1-earth_ecc*earth_ecc*math.sin(lat_rad)*math.sin(lat_rad))**0.5)
br.sendTransform((0, 0, 0), tf.transformations.quaternion_from_euler(0, 0, -(carryYaw + angles[2])), rospy.Time.now(), 'map', 'world')
#br.sendTransform((0, 0, 0), tf.transformations.quaternion_from_euler(0, 0, carryYaw), rospy.Time.now(), 'world', 'map')
else :
carryY=(lon_rad - initLon)*(ne+h)*math.cos(lat_rad)
carryX=(lat_rad - initLat)*(me+h)
print carryYaw
#br.sendTransform((carryX -trans[0], carryY -trans[1], 0), tf.transformations.quaternion_from_euler(0, 0, carryYaw -angles[2], "sxyz"), rospy.Time.now(), 'base_link', 'world')
br.sendTransform((-carryX, -carryY, 0), tf.transformations.quaternion_from_euler(0, 0, carryYaw, "sxyz"), rospy.Time.now(), 'base_link', 'dummy')
except(tf.LookupException, tf.ConnectivityException, tf.ExtrapolationException) :
print "exception"
示例11:
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>'
)
示例12: generate_kml
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
示例13: update_kml
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)
示例14: mission_route
def mission_route():
"""
Flask route that dynamically generates a KML of the current mission
as specified in the mission YAML.
"""
# Retrieve origin and create a list of KML attributes
origin = mission_planner.environment.origin
kml_list = [KML.name("SRR Mission")]
# Add placemarks for each mission waypoint.
for task in mission_planner.mission:
kml_list.append(frame_placemark(origin, task.name,
task.location.x, task.location.y,
marker='waypoint.png',
color='ffff0000'))
if not task.is_point:
kml_list.append(
bounds_placemark(origin, task.name + " bounds", task.bounds))
# Create a KML document with this environment represented.
doc = KML.kml(
KML.Document(
*kml_list
)
)
return etree.tostring(doc)
示例15: navigation_route
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)