本文整理汇总了Python中pykml.factory.KML_ElementMaker.coordinates方法的典型用法代码示例。如果您正苦于以下问题:Python KML_ElementMaker.coordinates方法的具体用法?Python KML_ElementMaker.coordinates怎么用?Python KML_ElementMaker.coordinates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pykml.factory.KML_ElementMaker
的用法示例。
在下文中一共展示了KML_ElementMaker.coordinates方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createAdditionalGeometry
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import coordinates [as 别名]
def createAdditionalGeometry(self, type, name='blank', coordin='0,0'):
"""
`Author`: Bill Clark
This method allows for a user to create new point, linestrings, and linearrings. It will default the
name and coordinates for the object if they aren't provided, but every call requires a type, one of the
above three. This method appends the created kml to the additions folder which needs to be produced beforehand.
`type`: String, reading Point, LineString, or LinearRing.
`name`: The name tag for the element. Simply for identification. Must be a String.
`coordin`: The coordinates for the kml. Must be a String.
`return`:
"""
if type == "Point":
pm1 = KML.Placemark(KML.name(name),KML.Point(KML.coordinates(coordin)))
elif type == "LineString":
pm1 = KML.Placemark(KML.name(name),KML.LineString(KML.coordinates(coordin)))
elif type == "LinearRing":
pm1 = KML.Placemark(KML.name(name),KML.LinearRing(KML.coordinates(coordin)))
else:
print 'Derp.'
self.additionfolder.append(pm1)
示例2: test_to_wkt_list_complex_polygon
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import coordinates [as 别名]
def test_to_wkt_list_complex_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 '
),
),
),
KML.innerBoundaryIs(
KML.LinearRing(
KML.coordinates(
'-122.366212,37.818977,30 '
'-122.365424,37.819294,30 '
'-122.365704,37.819731,30 '
'-122.366212,37.818977,30 '
),
),
),
KML.innerBoundaryIs(
KML.LinearRing(
KML.coordinates(
'-122.366212,37.818977,30 '
'-122.365704,37.819731,30 '
'-122.366488,37.819402,30 '
'-122.366212,37.818977,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), '
'(-122.366212 37.818977 30, '
'-122.365424 37.819294 30, '
'-122.365704 37.819731 30, '
'-122.366212 37.818977 30), '
'(-122.366212 37.818977 30, '
'-122.365704 37.819731 30, '
'-122.366488 37.819402 30, '
'-122.366212 37.818977 30))')
)
示例3: plot_kml
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import coordinates [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: finish
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import coordinates [as 别名]
def finish(self, kmlFilename):
rospy.loginfo("[KMLTourGenerator] finish()")
if (self.hasFinished):
return
self.path_fld.append(KML.Placemark(
KML.name('plan-path'),
KML.extrude("1"),
KML.tessellate("1"),
KML.altitudeMode("absolute"),
KML.Style(
KML.LineStyle(
KML.color('7FFF0000'),
KML.width(5)
),
KML.PolyStyle(
KML.color('7FFFFF00')
)
),
KML.LineString(
KML.tessellate("1"),
KML.altitudeMode("absolute"),
KML.coordinates(self.planCoordListStr)
)
))
self.path_fld.append(KML.Placemark(
KML.name('exec-path'),
KML.altitudeMode("absolute"),
KML.Style(
KML.LineStyle(
KML.color('7F0000FF'),
KML.width(5)
),
KML.PolyStyle(
KML.color('7FFFFFFF')
)
),
KML.LineString(
KML.extrude("1"),
KML.tessellate("1"),
KML.altitudeMode("absolute"),
KML.coordinates(self.execCoordListStr)
)
))
# check that the KML document is valid using the Google Extension XML Schema
#assert(Schema("kml22gx.xsd").validate(self.tour_doc))
#print etree.tostring(self.tour_doc, pretty_print=True)
# output a KML file (named based on the Python script)
outfile = file(kmlFilename,'w')
outfile.write(etree.tostring(self.tour_doc, pretty_print=True))
self.hasFinished = True
示例5: AddPlacemarkAndZone
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import coordinates [as 别名]
def AddPlacemarkAndZone(doc, site):
name = site[0]
lat = float(site[1]) + float(site[2])/60.0 + float(site[3])/3600.0;
if site[4] == 'S':
lat = -lat
lng = float(site[5]) + float(site[6])/60.0 + float(site[7])/3600.0;
if site[8] == 'W':
lng = -lng
print 'Adding placemark for %s at (%f, %f)' % (name, lat, lng)
pm = KML.Placemark(
KML.name(name),
KML.styleUrl('#pm'),
KML.Point(
KML.coordinates('%f,%f,0' % (lng, lat))
)
)
doc.append(pm)
zone = KML.Placemark(
KML.name('%s zone' % name),
KML.styleUrl('#ts'),
KML.Polygon(
KML.extrude(0),
KML.altitudeMode('clampToGround')
)
)
poly = zone.Polygon
d = float(zone_radius) / float(earth_radius)
coords = []
# Note: generate perimeter points every 5 degrees around the circle.
step_degrees = 5
for az in xrange(0, 360, step_degrees):
a = float(az)
lat2 = math.asin(math.sin(math.radians(lat))*math.cos(d) +
math.cos(math.radians(lat))*math.sin(d)*math.cos(math.radians(a)))
lng2 = math.radians(lng) + math.atan2(
math.sin(math.radians(a))*math.sin(d)*math.cos(math.radians(lat)),
math.cos(d) - math.sin(math.radians(lat))*math.sin(lat2))
coords.append([math.degrees(lng2), math.degrees(lat2)])
coords.append(coords[0])
latlngCoords = []
for c in coords:
latlngCoords.append('%f,%f,0' % (c[0], c[1]))
coordinates = ' '.join(latlngCoords)
poly.append(KML.outerBoundaryIs(
KML.LinearRing(
KML.coordinates(coordinates)
)
))
doc.append(zone)
示例6: create_kml_placemarks_for_tracks_and_waypoints
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import coordinates [as 别名]
def create_kml_placemarks_for_tracks_and_waypoints(tracks, waypoints, sample=1, description=None, color=None, name=None):
placemarks = []
tracks = tracks or []
waypoints = waypoints or []
for track in tracks:
coordinates = ["%s,%s" % (p.longitude, p.latitude) for i, p in enumerate(track.points) if
i % sample == 0 or len(track.points) < 100]
placemarks.append(
KML.Placemark(
KML.name(name or track.name),
KML.description(description or track.description or ""),
KML.Style(
KML.LineStyle(
KML.color(color) if color else get_random_color(),
KML.width(3)
)
),
KML.MultiGeometry(
KML.LineString(
KML.coordinates(" ".join(coordinates))
)
)
)
)
for waypoint in waypoints:
coordinates = "%s,%s" % (waypoint.long, waypoint.lat)
placemarks.append(
KML.Placemark(
KML.name(name or waypoint.name),
KML.description(description or waypoint.description or ""),
KML.Style(
KML.IconStyle(
KML.color("ffffffff"),
KML.scale(1.0),
KML.Icon(
KML.href(
"http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png")
),
),
KML.LabelStyle(
KML.scale(0.0)
)
),
KML.Point(
KML.coordinates(coordinates)
)
)
)
return placemarks
示例7: test_basic_kml_document_2
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import coordinates [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>'
)
示例8: debugging
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import coordinates [as 别名]
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"
示例9: kml
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import coordinates [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)
示例10: to_kml
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import coordinates [as 别名]
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
示例11: generateKML
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import coordinates [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))
示例12: kml_addAnimPoint
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import coordinates [as 别名]
def kml_addAnimPoint(self, pos, tm):
#pos[0] : latitude
#pos[1] : longitude
#pos[2] : altitude
#pos[3] : roll
#pos[4] : pitch
#pos[5] : yaw
if (pos == None):
return
localTimeStr = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.localtime(tm))
#rospy.logerr(localTimeStr)
self.anim_fld.append(KML.Placemark(
KML.TimeStamp(
KML.when(localTimeStr)
),
KML.altitudeMode("absolute"),
KML.styleUrl('#sn_shaded_dot'),
KML.LookAt(
KML.longitude(pos[1]),
KML.latitude(pos[0]),
KML.altitude(pos[2]),
KML.heading(pos[5]),
KML.tilt(0.0),
KML.range(100.0),
KML.altitudeMode("absolute"),
),
KML.Point(
KML.coordinates("{lon},{lat},{alt}".format(lon=pos[1], lat=pos[0], alt=pos[2]))
)
))
示例13: get_kml_doc
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import coordinates [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
示例14: create_reference_point_element
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import coordinates [as 别名]
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
示例15: build_test_kml
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import coordinates [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")