本文整理汇总了Python中pykml.factory.KML_ElementMaker.when方法的典型用法代码示例。如果您正苦于以下问题:Python KML_ElementMaker.when方法的具体用法?Python KML_ElementMaker.when怎么用?Python KML_ElementMaker.when使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pykml.factory.KML_ElementMaker
的用法示例。
在下文中一共展示了KML_ElementMaker.when方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: kml_addAnimPoint
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import when [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]))
)
))
示例2: buildKML
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import when [as 别名]
def buildKML():
media_filtered = pickle.load( open( "media_filtered.p", "rb" ) )
kml = open('media_KML.kml', "w")
kmlobj = KML.kml(
KML.Document(
KML.Style(
KML.BalloonStyle(
KML.displayMode('default'),
KML.text('<b>$[name]</b><br/>$[description]')
),
KML.IconStyle(
KML.Icon(
KML.href('http://maps.google.com/mapfiles/kml/paddle/red-circle.png'),
KML.scale('1.0')
),
id='mystyle'
),
id="balloonStyle"
)
)
)
# add placemarks to the Document element
for media in media_filtered:
kmlobj.Document.append(
KML.Placemark(
KML.name(media.location.name),
KML.description("Name: " + media.user.full_name +
"<br>Username: <a href=\"https://instagram.com/" + media.user.username + "/\">" + media.user.username + "</a><br>" +
"<img src=" + media.images['standard_resolution'].url + "><br>" +
media.caption.text),
KML.styleUrl('#balloonStyle'),
KML.TimeStamp(
KML.when(media.created_time.isoformat() + 'Z')
),
KML.Point(
KML.extrude(1),
KML.altitudeMode('relativeToGround'),
KML.coordinates('{lon},{lat},{alt}'.format(
lon=media.location.point.longitude,
lat=media.location.point.latitude,
alt=0,
),
),
),
)
)
kml.write(etree.tostring(etree.ElementTree(kmlobj),pretty_print=True))
kml.close()
示例3: build_xml
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import when [as 别名]
def build_xml(self):
track = GX.Track(
)
for position in self.track.positions:
track.append(KML.when("%s" % (
position.timestamp.strftime('%Y-%m-%dT%H:%M:%SZ'),)
))
for position in self.track.positions:
track.append(GX.coord("%f %f %d" % (
float(position.lon)/10000000,
float(position.lat)/10000000,
position.alt))
)
return track
示例4: addKML
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import when [as 别名]
def addKML(m, f):
try:
mmsi = m['mmsi']
x = str(m['x'])
y = str(m['y'])
pm = KML.Placemark(
KML.name(str(mmsi)),
KML.Point(
KML.coordinates(x + ',' + y)
),
KML.TimeStamp(
KML.when(getTime())
),
)
f.append(pm)
except:
pass
示例5: placeMaker
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import when [as 别名]
def placeMaker(attr):
'''Uses pyKML to produce a placemark for an image
The use of pyKML isn't actually necessary,
you could do just as well appending the placemarks from the NASA
KML files into a single document, but the intention was to
give an example usage of pyKML.'''
try:
placemark = K.Placemark(
K.open(0),
K.name(attr['MRF']),
K.styleUrl("#sm_style"),
K.Point(
K.altitudeMode('relativeToGround'),
K.coordinates(",".join([attr["Longitude"],attr["Latitude"],attr["Elevation"]]))
),
K.LookAt(
K.tilt(attr["Tilt"]),
K.longitude(attr["Longitude"]),
K.latitude(attr["Latitude"]),
K.range(40000)
),
K.TimeStamp(K.when(time.strftime("%Y-%m-%dT%H:%M:%SZ",time.strptime(attr["YYYYMMDD"]+attr["HHMMSS"],"%Y%m%d %H%M%S")))),
K.ExtendedData(
K.Data( K.value(attr["MRF"]), name="MRF"),
K.Data( K.value(attr["IMG"]), name="IMG"),
K.Data( K.value(attr["Features"]), name="features"),
K.Data( K.value(attr["YYYYMMDD"]), name="YYYYMMDD"),
K.Data( K.value(attr["HHMMSS"]), name="HHMMSS"),
K.Data( K.value(attr["Camera Tilt"]), name="Camera_Tilt"),
K.Data( K.value(attr["Camera Lens"]), name="Camera_Lens"),
K.Data( K.value(attr["Camera"]), name="Camera"),
K.Data( K.value(attr["Sun Azimuth"]), name="Sun_Azimuth"),
K.Data( K.value(attr["Sun Elevation"]), name="Sun_Elevation"),
K.Data( K.value(attr["Spacecraft Altitude"]), name="Spacecraft_Altitude"),
K.Data( K.value(attr["DB Entry"]), name="DB_Entry"),
)
)
except :
return None
return placemark
示例6: create_placemarks
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import when [as 别名]
def create_placemarks(location):
pm = KML.Placemark()
pm.append(
KML.description(
'<table border="1">'
'<tr><th>latitude</th><td>{lat}</td>'
'<tr><th>longitude</th><td>{lon}</td>'
'<tr><th>altitude</th><td>{alt}</td>'
'<tr><th>heading</th><td>{head}</td>'
'<tr><th>tilt</th><td>{tilt}</td>'
'<tr><th>roll</th><td>{roll}</td>'
'</table>'.format(
lat=location['loc'].latitude,
lon=location['loc'].longitude,
alt=location['loc'].altitude,
head=location['loc'].heading,
tilt=location['loc'].tilt,
roll=location['loc'].roll,
)
)
)
pm.append(
KML.TimeStamp(
KML.when(location['time'].strftime('%Y-%m-%dT%H:%M:%SZ'))
)
)
coord_list = [
str(location['loc'].longitude),
str(location['loc'].latitude),
]
if location['loc'].altitude != None:
coord_list.append(str(location['loc'].altitude))
pm.append(
KML.Point(
KML.extrude(1),
KML.altitudeMode('relativeToGround'),
KML.coordinates(','.join(coord_list)),
)
)
return pm
示例7: createPlacemarkAsLineString
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import when [as 别名]
def createPlacemarkAsLineString(self, city, objects, fld):
for obj in objects:
e = city.getEdge(obj)
n_uuids = []
n_uuids.append(e.getStartpointName())
n_uuids.append(e.getEndpointName())
p_nodes = []
for n_uuid in n_uuids:
n = city.getNode(n_uuid)
p_nodes.append(n)
p_nodes.reverse()
nodes_transformed = []
for n in p_nodes:
nodes_transformed.append(self.transformCoorindate(n))
coordinates = ''
for n in nodes_transformed:
coordinates+="{0},{1},{2}".format(n.getX(), n.getY(), n.getZ())+"\n"
y = int(e.getAttribute("built_year").getDouble())
if y < 1:
y = 1900
m = 1
d = 1
if y < 0.01:
continue
pm = KML.Placemark(
KML.name(obj),
KML.styleUrl("#SWMM"),
KML.TimeStamp(
KML.when((date(y,m,d)).strftime('%Y-%m-%dT%H:%MZ')),
),
KML.LineString(
KML.altitudeMode("relativeToGround"),
KML.coordinates(coordinates),
),
)
fld.append(pm)
示例8: buildKML
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import when [as 别名]
def buildKML(patterns, latitude, longitude,days,frequence):
patterns = [(i.replace("\'",'').replace('\"','')) for i in patterns]
origin = (latitude, longitude)
count = 100
global pm1
pm1 = KML.Placemark(
KML.TimeStamp(KML.when(count)),
KML.name("f: "+str(frequence)),
KML.Point( KML.coordinates(reproject3857to4326(origin))),
KML.Style(
KML.IconStyle(
KML.Icon(KML.href(""))
)
)
)
folder.append(pm1)
for pattern in patterns:
coor = reproject3857to4326(origin)
if(pattern == '1'):
pm1 = KML.Placemark(
KML.TimeStamp(KML.when(count)),
KML.Point( KML.coordinates(coor)),
KML.Style(
KML.IconStyle(
KML.Icon(KML.href("suns/so1.png"))
)
)
)
folder.append(pm1)
elif(pattern == '2'):
pm1 = KML.Placemark(
KML.TimeStamp(KML.when(count)),
KML.Point( KML.coordinates(coor)),
KML.Style(
KML.IconStyle(
KML.Icon(KML.href("suns/so2.png"))
)
)
)
folder.append(pm1)
elif(pattern == '3'):
pm1 = KML.Placemark(
KML.TimeStamp(KML.when(count)),
KML.Point( KML.coordinates(coor)),
KML.Style(
KML.IconStyle(
KML.Icon(KML.href("suns/so3.png"))
)
)
)
folder.append(pm1)
elif(pattern == '4'):
pm1 = KML.Placemark(
KML.TimeStamp(KML.when(count)),
KML.Point( KML.coordinates(coor)),
KML.Style(
KML.IconStyle(
KML.Icon(KML.href("suns/so4.png"))
)
)
)
folder.append(pm1)
elif(pattern == '5'):
pm1 = KML.Placemark(
KML.TimeStamp(KML.when(count)),
KML.Point( KML.coordinates(coor)),
KML.Style(
KML.IconStyle(
KML.Icon(KML.href("suns/so5.png"))
)
)
)
folder.append(pm1)
elif(pattern == '6'):
pm1 = KML.Placemark(
KML.TimeStamp(KML.when(count)),
KML.Point( KML.coordinates(coor)),
KML.Style(
KML.IconStyle(
KML.Icon(KML.href("suns/so6.png"))
)
)
)
folder.append(pm1)
elif(pattern == '7'):
pm1 = KML.Placemark(
KML.TimeStamp(KML.when(count)),
KML.Point( KML.coordinates(coor)),
KML.Style(
KML.IconStyle(
KML.Icon(KML.href("suns/so7.png"))
)
)
)
folder.append(pm1)
elif(pattern == '8'):
pm1 = KML.Placemark(
KML.TimeStamp(KML.when(count)),
KML.Point( KML.coordinates(coor)),
KML.Style(
#.........这里部分代码省略.........
示例9: createPlacemarkForSelection
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import when [as 别名]
def createPlacemarkForSelection(self, cmp, uuid, center, fld):
#geomtryLinks = cmp.getAttribute("Geometry").getLinks()
#for link in geomtryLinks:
# link.
l = cmp.getAttribute("l_bounding").getDouble()
b = cmp.getAttribute("b_bounding").getDouble()
h = cmp.getAttribute("h_bounding").getDouble()
alpha = cmp.getAttribute("alpha_bounding").getDouble()
nodes = []
nodes.append(Node(l/2, -b/2, h))
nodes.append(Node(l/2, b/2, h))
nodes.append(Node(-l/2, b/2, h))
nodes.append(Node(-l/2, -b/2, h))
nodes.append(Node(l/2, -b/2, h))
nodes = self.rotatePolygon(nodes, alpha)
nodes = self.translatePolygon(nodes, center)
nodes_transformed = []
exdata = KML.ExtendedData()
attributes = cmp.getAllAttributes()
for k in attributes:
attr = attributes[k]
#print attr.getType()
if attr.getType() == Attribute.DOUBLE:
#print str(k) + " " + str(attr.getDouble())
d = KML.Data(
KML.name(k),
KML.value(attr.getDouble()),
)
exdata.append(d)
for n in nodes:
nodes_transformed.append(self.transformCoorindate(n))
coordinates = ''
for n in nodes_transformed:
coordinates+="{0},{1},{2}".format(n.getX(), n.getY(), n.getZ())+"\n"
y = int(cmp.getAttribute("built_year").getDouble())
if y < 1:
y = 1900
m = 1
d = 1
pm = KML.Placemark(
KML.name(uuid+"_Data"),
exdata,
KML.styleUrl("#transRedPoly"),
KML.TimeStamp(
KML.when((date(y,m,d)).strftime('%Y-%m-%dT%H:%MZ')),
),
KML.Polygon(
KML.extrude(1),
KML.altitudeMode("relativeToGround"),
KML.outerBoundaryIs(
KML.LinearRing(
KML.coordinates(coordinates),
),
),
),
)
fld.append(pm)
示例10: createPlacemarkAsLineRing
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import when [as 别名]
def createPlacemarkAsLineRing(self, city, objects, fld):
for obj in objects:
f = city.getFace(obj)
nodes = f.getNodes()
p_nodes = []
for n_uuid in nodes:
n = city.getNode(n_uuid)
p_nodes.append(n)
if pydmextensions.CGALGeometry_CheckOrientation(f.getNodePointers()) == False:
p_nodes.reverse()
p_nodes.append(p_nodes[0])
nodes_transformed = []
for n in p_nodes:
nodes_transformed.append(self.transformCoorindate(n))
coordinates = ''
z = 0
if self.ExtrudAttr != "":
z = f.getAttribute(self.ExtrudAttr).getDouble()
for n in nodes_transformed:
coordinates+="{0},{1},{2}".format(n.getX(), n.getY(), z)+"\n"
y = int(f.getAttribute("built_year").getDouble())
#print y
m = 1
d = 1
if y < 1:
y = 1900
if self.ExtrudAttr == "":
pm = KML.Placemark(
KML.name(obj),
KML.styleUrl(str("style_")+str(obj)),
KML.TimeStamp(
KML.when((date(y,m,d)).strftime('%Y-%m-%dT%H:%MZ')),
),
KML.Polygon(
KML.outerBoundaryIs(
KML.LinearRing(
KML.altitudeMode("clampToGround"),
KML.coordinates(coordinates),
),
),
),
)
fld.append(pm)
if self.ExtrudAttr != "":
pm = KML.Placemark(
KML.name(obj),
KML.styleUrl(str("style_")+str(obj)),
KML.TimeStamp(
KML.when((date(y,m,d)).strftime('%Y-%m-%dT%H:%MZ')),
),
KML.Polygon(
KML.extrude(1),
KML.altitudeMode("relativeToGround"),
KML.outerBoundaryIs(
KML.LinearRing(
KML.coordinates(coordinates),
),
),
),
)
fld.append(pm)
示例11: main
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import when [as 别名]
#.........这里部分代码省略.........
),
id=stylename,
)
)
)
# create placemark for the observer, and add it to the KML document
pm_observer = KML.Placemark(
KML.name('Observer'),
KML.styleUrl('#{0}'.format(stylename)),
KML.Point(
KML.extrude(True),
KML.altitudeMode('relativeToGround'),
KML.coordinates("{0},{1},{2}".format(longitude, latitude, height)),
),
)
doc.Document.append(pm_observer)
# iterate through the ephemeris data
for i in data:
timestamp = i['datetime UTC']
azimuth_rad = i['azimuth_angle']
azimuth_deg = degrees(azimuth_rad)
altitude_rad = i['altitude_angle']
altitude_deg = degrees(altitude_rad)
if altitude_deg > 0:
# define a placemark along the ephemeris vector for labeling
delta_lat_rad, delta_lon_rad, delta_alt = calculate_geographic_offset(
azimuth_angle=radians(adjust_heading_degrees(degrees(azimuth_rad))),
altitude_angle=altitude_rad,
distance=label_distance,
)
pm1 = KML.Placemark(
KML.name((timestamp + timedelta(timezone_offset)).strftime('%H:%M')),
KML.styleUrl('#{0}'.format(stylename)),
KML.LookAt(
KML.longitude(longitude),
KML.latitude(latitude),
KML.altitude(height),
KML.heading(adjust_heading_degrees(azimuth_deg)),
KML.tilt(90),
# KML.roll(0),
KML.altitudeMode("relativeToGround"),
KML.range(50),
),
KML.Point(
KML.altitudeMode("relativeToGround"),
KML.coordinates("{lon},{lat},{alt}".format(
lon=longitude + degrees(delta_lon_rad),
lat=latitude + degrees(delta_lat_rad),
alt=height + delta_alt,
)),
),
)
pm2 = KML.Placemark(
KML.name('Sun View'),
KML.LookAt(
KML.longitude(longitude),
KML.latitude(latitude),
KML.altitude(height),
KML.heading(adjust_heading_degrees(180 + azimuth_deg)),
KML.tilt(90 - altitude_deg - 0.2),
# KML.roll(0),
KML.altitudeMode("relativeToGround"),
KML.range(2 * label_distance),
),
KML.Model(
KML.altitudeMode('relativeToGround'),
KML.Location(
KML.longitude(longitude),
KML.latitude(latitude),
KML.altitude(height),
),
KML.Orientation(
KML.heading(adjust_heading_degrees(azimuth_deg)),
KML.tilt(90 - altitude_deg),
KML.roll(0),
),
KML.Scale(
KML.x(1000),
KML.y(1000),
KML.z(500000),
),
KML.Link(
KML.href('unit_cone_red.dae'),
),
),
)
doc.Document.append(
KML.Folder(
KML.name(timestamp.strftime('%Y-%m-%dT%H:%MZ')),
pm1,
pm2,
KML.TimeStamp(
KML.when(timestamp.strftime('%Y-%m-%dT%H:%MZ')),
),
)
)
print(etree.tostring(doc,
pretty_print=True,
encoding='utf-8',
xml_declaration=True))
示例12: buildKML
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import when [as 别名]
def buildKML(patterns, latitude, longitude):
patterns = [(i.replace("\'",'').replace('\"','')) for i in patterns]
count = 100
for pattern in patterns:
direction = pattern[:1]
speed = int(pattern[1:])
origin = (latitude, longitude)
points = []
for a in range(int(dictDirection[str(direction)][0]*10)+100,int(dictDirection[str(direction)][1]*10)-99,5):
angle = a/10
X = (speed * 200) * math.sin(math.radians(angle))
Y = (speed * 200) * math.cos(math.radians(angle))
point = (latitude+X, longitude+Y)
points.append(point)
pointsReproject = ''
pointsReproject1 = ''
for point in points:
pointsReproject += (reproject3857to4326(point, count)+'\n')
for point in reversed(points):
pointsReproject1 += (reproject3857to4326(point, count-70)+'\n')
coordinates = reproject3857to4326(origin, count)+'\n'+pointsReproject+reproject3857to4326(origin,count)
coordinates1 = reproject3857to4326(origin, count-70)+'\n'+pointsReproject1+reproject3857to4326(origin,count-70)
coordinates2 = reproject3857to4326(origin, count)+'\n'+reproject3857to4326(points[0], count)+'\n'+reproject3857to4326(points[0], count-70)+'\n'+reproject3857to4326(origin, count-70)
coordinates3 = reproject3857to4326(origin, count)+'\n'+reproject3857to4326(points[-1], count)+'\n'+reproject3857to4326(points[-1], count-70)+'\n'+reproject3857to4326(origin, count-70)
coordinates4 = pointsReproject+pointsReproject1
poly = KML.Placemark(
KML.description('<b>Direction:</b> {0}</br><b>Speed:</b> {1} m/s'.format(dictDirection1[str(direction)],
dictSpeed[str(speed)])),
KML.TimeStamp(KML.when(count)),
KML.name('Localization: </br>'+str(latitude)+','+str(longitude)),
KML.styleUrl('#color'+str(speed)),
KML.Polygon(
KML.extrude('0'),
KML.altitudeMode('relativeToGround'),
KML.outerBoundaryIs(
KML.LinearRing(
KML.coordinates(
coordinates
),
),
),
),
)
poly1 = KML.Placemark(
KML.TimeStamp(KML.when(count)),
KML.styleUrl('#color'+str(speed)),
KML.Polygon(
KML.extrude('0'),
KML.altitudeMode('relativeToGround'),
KML.outerBoundaryIs(
KML.LinearRing(
KML.coordinates(
coordinates1
),
),
),
),
)
poly2 = KML.Placemark(
KML.TimeStamp(KML.when(count)),
KML.styleUrl('#color'+str(speed)),
KML.Polygon(
KML.extrude('0'),
KML.altitudeMode('relativeToGround'),
KML.outerBoundaryIs(
KML.LinearRing(
KML.coordinates(
coordinates2
),
),
),
),
)
poly3 = KML.Placemark(
KML.TimeStamp(KML.when(count)),
KML.styleUrl('#color'+str(speed)),
KML.Polygon(
KML.extrude('0'),
KML.altitudeMode('relativeToGround'),
KML.outerBoundaryIs(
KML.LinearRing(
KML.coordinates(
coordinates3
),
),
),
),
)
poly4 = KML.Placemark(
KML.TimeStamp(KML.when(count)),
KML.styleUrl('#color'+str(speed)),
#.........这里部分代码省略.........
示例13:
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import when [as 别名]
),
KML.Orientation(
KML.heading(adjust_heading_degrees(azimuth_deg)),
KML.tilt(90-altitude_deg),
KML.roll(0),
),
KML.Scale(
KML.x(1000),
KML.y(1000),
KML.z(500000),
),
KML.Link(
KML.href('unit_cone_red.dae'),
),
),
)
doc.Document.append(
KML.Folder(
KML.name(timestamp.strftime('%Y-%m-%dT%H:%MZ')),
pm1,
pm2,
KML.TimeStamp(
KML.when((timestamp).strftime('%Y-%m-%dT%H:%MZ')),
),
)
)
print etree.tostring(doc, pretty_print=True)
示例14: makeExtendedDataElements
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import when [as 别名]
balloonstyle,
id="earthquake-style-{threshold}".format(threshold=threshold),
)
)
doc.append(KML.Folder())
# read in a csv file, and create a placemark for each record
url="http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-M2.5.txt"
fileobject = urllib2.urlopen(url)
for row in csv.DictReader(fileobject):
timestamp = datetime.strptime(row["Datetime"], "%A, %B %d, %Y %H:%M:%S %Z")
pm = KML.Placemark(
KML.name("Magnitude={0}".format(row['Magnitude'])),
KML.TimeStamp(
KML.when(timestamp.strftime('%Y-%m-%dT%H:%M:%SZ')),
),
KML.styleUrl(
"#earthquake-style-{thresh}".format(
thresh=int(float(row['Magnitude']))
)
),
makeExtendedDataElements(row),
KML.Point(
KML.coordinates("{0},{1}".format(row["Lon"],row["Lat"]))
)
)
doc.Folder.append(pm)
# check if the schema is valid
from pykml.parser import Schema
示例15: main
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import when [as 别名]
def main():
# ###############################################################################
usage = "usage: %prog [options] <gpxfile>\n\n"
usage += "where:\n"
usage += " <gpxfile>\tgpx formatted file"
parser = optparse.OptionParser(usage=usage)
parser.add_option("-p", "--points", dest="points", action="store_true", help="specify if points output is desired", default=False)
parser.add_option("-f", "--flyover", dest="flyover", action="store_true", help="specify if flyover output is desired", default=False)
parser.add_option("-c", "--color", dest="color", help="track color if not flyover", default='641400FF')
parser.add_option("-o", "--output", dest="output", help="output file", default=None)
(options, args) = parser.parse_args()
# see http://www.zonums.com/gmaps/kml_color/
colors = {'pink':'64781EF0', 'blue':'64F01E14'}
gpxfile = args.pop(0)
if options.output == None:
outfile = os.path.basename(gpxfile) + '.kml'
else:
outfile = options.output
# get input
_GPX = open(gpxfile,'r')
gpx = gpxpy.parse(_GPX)
# create a KML file skeleton
stylename = "sn_shaded_dot"
color = colors[options.color]
sty = KML.Style(
KML.IconStyle(
KML.scale(1.2),
KML.Icon(
KML.href("http://maps.google.com/mapfiles/kml/shapes/shaded_dot.png")
),
KML.color(colors[options.color]),
),
id=stylename,
)
iconstylename = '#sn_shaded_dot'
doc = KML.Document(
KML.Name('generated from {0}'.format(gpxfile)),
KML.open(1),
)
doc.append(sty)
'''
<TimeStamp>
<when>1997-07-16T07:30:15Z</when>
</TimeStamp>
'''
# loop through gpx tracks, creating kml placemarks
times = []
coords = []
dists = []
points = []
lastpoint = None
for track in gpx.tracks:
for segment in track.segments:
for point in segment.points:
if not lastpoint:
lastpoint = point
plon = point.longitude
plat = point.latitude
pelev = point.elevation
points.append(point)
thisdist = gpxpy.geo.distance(lastpoint.latitude, lastpoint.longitude, lastpoint.elevation, plat, plon, pelev)
lastpoint = point
dists.append(thisdist)
ptime = t.dt2asc(point.time)
times.append(ptime)
coords.append('{lon},{lat},{alt}'.format(lon = plon,lat = plat,alt = 0))
if options.flyover:
plm = KML.Placemark()
doc.append(plm)
track = GX.track()
plm.append(track)
for when in times:
track.append(KML.when(when))
for coord in coords:
track.append(KML.coordinates(coord))
'''
doc.append(KML.Placemark(
KML.LookAt(
KML.longitude(plon),
KML.latitude(plat),
KML.tilt(45),
KML.heading(0), # make this behind the guy
KML.altitudeMode("relativeToGround"),
KML.range(50),
),
KML.Point(
KML.altitudeMode("relativeToGround"),
,
,
#.........这里部分代码省略.........