本文整理汇总了Python中pykml.factory.KML_ElementMaker.value方法的典型用法代码示例。如果您正苦于以下问题:Python KML_ElementMaker.value方法的具体用法?Python KML_ElementMaker.value怎么用?Python KML_ElementMaker.value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pykml.factory.KML_ElementMaker
的用法示例。
在下文中一共展示了KML_ElementMaker.value方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: append_linestring
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import value [as 别名]
def append_linestring(timeDiff, dist, normalized, thisStyle, row):
doc.append(
KML.Placemark(
KML.name("Point " + str(count/lineReduceNumBy)),
KML.ExtendedData(
KML.Data(KML.value(timeDiff), name="Time Length"),
KML.Data(KML.value(dist), name="Distance Metres"),
KML.Data(KML.value(dist/timeDiff.seconds), name="Average Speed m/s"),
KML.Data(KML.value(normalized), name="Normalized Speed"),
),
KML.styleUrl("#{}".format(thisStyle)),
KML.LineString(
KML.extrude('1'),
GX.altitudeMode('relative'),
KML.coordinates(
previousPoint,
"{},{},{}".format(row['LOCATION Longitude : '],row['LOCATION Latitude : '],0)
)
)
))
示例2: to_kml
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import value [as 别名]
def to_kml(self, round, attributes=[]):
path = self.geometry.to_kml(round)
from pykml.factory import KML_ElementMaker as KML
pm = KML.Placemark(
KML.name(self.props[attributes[0]['src']]),
path
)
xt = KML.ExtendedData()
for cfg in attributes:
if 'src' in cfg:
if cfg['src'] not in self.props:
continue
#raise errors.KartographError(('attribute not found "%s"'%cfg['src']))
val = self.props[cfg['src']]
import unicodedata
if isinstance(val, str):
val = unicode(val, errors='ignore')
val = unicodedata.normalize('NFKD', val).encode('ascii','ignore')
xt.append(KML.Data(
KML.value(val),
name=cfg['tgt']
))
elif 'where' in cfg:
src = cfg['where']
tgt = cfg['set']
if len(cfg['equals']) != len(cfg['to']):
raise errors.KartographError('attributes: "equals" and "to" arrays must be of same length')
for i in range(len(cfg['equals'])):
if self.props[src] == cfg['equals'][i]:
#svg['data-'+tgt] = cfg['to'][i]
xt.append(KML.Data(
KML.value(cfg['to'][i]),
name=tgt
))
pm.append(xt)
return pm
示例3: ConvertShapeToPlacemark
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import value [as 别名]
def ConvertShapeToPlacemark(shape, geoid, aland, awater, kml):
#if len(shape.parts) > 1:
# print '----------geoid=%s aland=%s awater=%s' % (geoid, aland, awater)
if shape.shapeType != 5:
raise Exception('Unexpected shape type [%d] in file' % shape.shapeType)
pm = KML.Placemark(
KML.name('%s' % geoid),
KML.styleUrl('#ts'),
KML.ExtendedData(
KML.Data(
KML.displayName('ALAND'),
KML.value(aland),
name='string'
),
KML.Data(
KML.displayName('AWATER'),
KML.value(awater),
name='string'
)
),
KML.MultiGeometry(
KML.Polygon(
KML.extrude(0),
KML.altitudeMode('clampToGround')
)
)
)
# The parentPoly will be used to append rings, and a
# new Polygon will be appended for multiple rings in
# a geography.
parentPoly = pm.MultiGeometry.Polygon
#if len(shape.parts) > 1:
# print 'shape has %d parts' % len(shape.parts)
for i in range(0, len(shape.parts)):
lo = shape.parts[i]
hi = len(shape.points)
if i < len(shape.parts) - 1:
hi = shape.parts[i + 1]
#if len(shape.parts) > 1:
# print 'shape has points in [%d, %d) of %d' % (lo, hi, len(shape.points))
if (shape.points[lo][0] != shape.points[hi-1][0] or
shape.points[lo][1] != shape.points[hi-1][1]):
raise Exception('Loop endpoints in [%d, %d) do not match' % (lo, hi))
coords = []
for j in reversed(range(lo, hi)):
lng = shape.points[j][0]
lat = shape.points[j][1]
coords.append([lng, lat])
latlngCoords = []
for c in coords:
latlngCoords.append('%f,%f,0' % (c[0], c[1]))
coordinates = ' '.join(latlngCoords)
# Note: need LinearRing to compute ccw. Need Polygon to compute contains().
spoly = SPolygon(coords)
if i == 0:
parentSpoly = spoly
ring = polygon.LinearRing(coords)
# Some sanity checks to make sure all rings are closed, non-empty,
# and valid.
if not ring.is_ring:
raise Exception('Badly formatted non-ring : %s' % geoid)
if ring.is_empty:
raise Exception('Empty geometry found: %s' % geoid)
if not ring.is_valid:
raise Exception('Invalid ring: %s' % geoid)
if not ring.is_ccw:
# This ring is an internal (enclave) ring.
rring = copy.deepcopy(ring)
rring.coords = list(rring.coords)[::-1]
# Shapely contains does not handle point-overlaps. This
# means that enclaves which touch the containing ring
# are not handled correctly. To cure this, we check two
# points.
if not (parentSpoly.contains(SPoint(rring.coords[0])) or
parentSpoly.contains(SPoint(rring.coords[1]))):
print 'Out-of-order enclave'
# print 'ring %s does not contain %s' % (parentSpoly, ring)
# print ring
# print rring
# Note: if this triggers, we will need to store the polys
# to figure out which one is the enclosing one. Hopefully
# the census files will not exhibit this, although it is
# legal strictly according to the shapefule spec.
raise Exception('Out-of-order enclave')
coordinates = coordinates + ' 0,0,0'
parentPoly.append(KML.innerBoundaryIs(
KML.LinearRing(
KML.coordinates(coordinates)
)
))
else:
# Find the containing poly...
parentPoly.append(KML.innerBoundaryIs(
#.........这里部分代码省略.........
示例4: _convert_
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import value [as 别名]
#.........这里部分代码省略.........
'</script>').format(
param=meta.variable.name,
units=meta.variable.units,
))
),
id="style-highlight",
),
#Time Folders will be appended here
),
)
try:
s = db.Session()
# create a folder to hold the geometries
geom_fld = KML.Folder(
KML.name('Geometries'),
)
for geom in s.query(db.Geometry).all():
coord_list = geom.as_kml_coords()
multigeom_args = [
KML.Polygon(
KML.tessellate('1'),
KML.outerBoundaryIs(
KML.LinearRing(
KML.coordinates(coords.text),
),
),
) for coords in coord_list
]
# TODO: sort values by time to speed loading
values = ['{0},{1}'.format(datetime.strftime(val.time, "%Y-%m-%d %H:%M:%S"),val.value) for val in geom.values]
pm = KML.Placemark(
KML.name('Geometry'),
KML.ExtendedData(
KML.Data(
KML.value('"Date,{param}\\n{data}"'.format(
param=meta.variable.name,
data='\\n'.join(values))
),
name="csv_data",
),
),
KML.description(''),
KML.styleUrl('#smap'),
KML.MultiGeometry(*multigeom_args),
)
geom_fld.append(pm)
doc.Document.append(geom_fld)
# for time in s.query(db.Time).all():
# # create a folder for the time
# timefld = KML.Folder(
## KML.Style(
## KML.ListStyle(
## KML.listItemType('checkHideChildren'),
## KML.bgColor('00ffffff'),
## KML.maxSnippetLines('2'),
## ),
## ),
# KML.name(time.as_xml_date()),
# # placemarks will be appended here
# )
示例5: placeMaker
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import value [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: len
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import value [as 别名]
if len(report["locations"]) > 0:
locs2 = report["locations"]
for locs1 in locs2:
loc = locs1[0]
if loc == 0:
print(locs2)
continue
try:
pm = KML.Placemark(KML.name(""),
KML.Point(
KML.coordinates(str(loc[0]) + "," + str(loc[1])),
KML.ExtendedData(
KML.Data(KML.value("bar"), name="foo")
)
))
except Exception as e:
print(loc)
raise e
fld.append(pm)
counter += 1
fd = open("output.kml", "wb")
fd.write(etree.tostring(fld))
fd.close()
#print(etree.tostring(fld, pretty_print=True))
示例7: createPlacemarkForSelection
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import value [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)
示例8: makeExtendedDataElements
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import value [as 别名]
def makeExtendedDataElements(datadict):
'''Converts a dictionary to ExtendedData/Data elements'''
edata = KML.ExtendedData()
for key, value in datadict.iteritems():
edata.append(KML.Data(KML.value(value), name=key + "_"))
return edata
示例9: main
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import value [as 别名]
#.........这里部分代码省略.........
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"),
,
,
)
))
'''
elif options.points:
#for coord in coords:
# ls.append(KML.coordinates(coord))
lasttime = t.asc2epoch(times[0])
totdist = 0
for i in range(len(times)):
thistime = t.asc2epoch(times[i])
dur = thistime - lasttime
lasttime = thistime
totdist += dists[i]
ex = KML.ExtendedData(
KML.Data(KML.displayName('time'),KML.value(times[i])),
KML.Data(KML.displayName('duration'),KML.value(dur)),
KML.Data(KML.displayName('totdistance'),KML.value(int(round(totdist)))),
)
plm = KML.Placemark(
#KML.name(times[i]),
KML.name(''),
KML.styleUrl(iconstylename),
)
plm.append(ex)
plm.append(KML.Point(
KML.altitudeMode('clampToGround'),
KML.coordinates(coords[i])))
doc.append(plm)
else:
if options.color:
doc.append(
KML.Style(
KML.LineStyle(
KML.color(colors[options.color]),
KML.width(5),
),
id=options.color))
stylename = '#{0}'.format(options.color)
'''
<LineString id="ID">
<!-- specific to LineString -->
<gx:altitudeOffset>0</gx:altitudeOffset> <!-- double -->
<extrude>0</extrude> <!-- boolean -->
<tessellate>0</tessellate> <!-- boolean -->
<altitudeMode>clampToGround</altitudeMode>
<!-- kml:altitudeModeEnum: clampToGround, relativeToGround, or absolute -->
<!-- or, substitute gx:altitudeMode: clampToSeaFloor, relativeToSeaFloor -->
<gx:drawOrder>0</gx:drawOrder> <!-- integer -->
<coordinates>...</coordinates> <!-- lon,lat[,alt] -->
</LineString>
'''
plm = KML.Placemark(
KML.name('runtrack'),
)
if options.color:
plm.append(KML.styleUrl(stylename))
doc.append(plm)
ls = KML.LineString(
KML.altitudeMode('clampToGround'),
# KML.extrude(1),
# KML.tessellate(1),
)
plm.append(ls)
#for coord in coords:
# ls.append(KML.coordinates(coord))
kcoords = ''
for coord in coords:
kcoords += coord + ' \n'
ls.append(KML.coordinates(kcoords))
_GPX.close()
kml = KML.kml(doc)
docstr = etree.tostring(kml, pretty_print=True)
OUT = open(outfile,'w')
OUT.write(docstr)
OUT.close()
示例10: range
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import value [as 别名]
for i in range(len(yyyy)):
datum = str(date.date(int(yyyy[i]),int(mm[i]),int(dd[i])))
ev_time = str(date.time(int(hr[i]),int(mn[i]),int(ss[i])))
alt = str(altitude[i])
press = str(pressure[i])
temp = str(temperature[i])
imur = str(roll[i])
imup = str(pitch[i])
imuy = str(yaw[i])
kmlobj.Document.append(
KML.Placemark(
#~ KML.name('%s'%str(int(index[i]))), #uncomment this to add a name to the placemark (will always appear in GoogleEarth)
KML.ExtendedData( #I add information about the earthquake, it appears in a table ('info' : value)
KML.Data(
KML.value('%s'%datum), #add value of the specific info
name ='date' #name of'info' you add.
),
KML.Data(
KML.value('%s'%ev_time), #add value of the specific info
name ='time' #name of 'info' you add.
), #more data can be added, following the same structure (line 65-68)
KML.Data(
KML.value('%s'%alt), #add value of the specific info
name ='altitude' #name of 'info' you add.
), #more data can be added, following the same structure (line 65-68)
KML.Data(
KML.value('%s'%press), #add value of the specific info
name ='pressure' #name of 'info' you add.
), #more data can be added, following the same structure (line 65-68)
KML.Data(
示例11: make_extended_data_elements
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import value [as 别名]
def make_extended_data_elements(datadict):
"""Converts a dictionary to ExtendedData/Data elements"""
edata = KML.ExtendedData()
for key, value in datadict.items():
edata.append(KML.Data(KML.value(value), name=key + '_'))
return edata
示例12: convert_to_kml
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import value [as 别名]
#.........这里部分代码省略.........
if history == "": history = "n/a"
coords = record[6]
addrss = record[7]
if addrss is None:
addrss = "n/a"
else:
addrss = convert_to_xmlvalid(addrss)
if addrss == "": addrss = "n/a"
print "Record: " + str(record[0])
print "Name: " + str(name)
print "Classification: " + str(classification)
print "Dates: " + str(dates)
print "Status: " + str(status)
print "History: " + str(history)
print "Coordinates: " + str(coords)
print "1912 Address: " + str(addrss)
print "\n"
#answer = raw_input("Press enter to continue...")
if classification == "residential":
style_url = "#residential_map"
elif classification == "hotel":
style_url = "#hotel_map"
elif classification == "commercial":
style_url = "#comm_map"
elif classification == "industrial":
style_url = "#industrial_map"
elif classification == "institute":
style_url = "#institute_map"
elif classification == "health":
style_url = "#health_map"
elif classification == "religious":
style_url = "#relig_map"
elif classification == "recreational":
style_url = "#rec_map"
elif classification == "transportation":
style_url = "#trans_map"
photo_html = get_photo_html(c, id_num)
source_text = get_sources(c, id_num)
print "name: " + str(name)
out_doc.append(
KML.Placemark(
KML.name(name.encode('utf-8')),
KML.styleUrl(style_url),
KML.ExtendedData(
KML.Data(
KML.value(str(name)),
name="name"
),
KML.Data(
KML.value(str(dates)),
name="dates"
),
KML.Data(
KML.value(str(status)),
name="status"
),
KML.Data(
KML.value(str(history)),
name="history"
),
KML.Data(
KML.value(str(addrss)),
name="addrss"
),
KML.Data(
KML.value(str(source_text)),
name="sources"
),
KML.Data(
KML.value(str(photo_html)),
name="photos"
),
#KML.Data(value=str(status), name="status"),
#KML.Data(value=str(history), name="history"),
#KML.Data(value=str(photo_html), name="photos"),
),
KML.Polygon(
KML.tessellate("1"),
KML.outerBoundaryIs(
KML.LinearRing(
KML.coordinates(coords),
),
),
),
),
)
out_kml.append(out_doc)
kml_text = etree.tostring(out_kml, pretty_print=True)
kml_fn = os.path.splitext(db_file)
kml_file = open(kml_fn[0] + ".kml", 'w')
kml_file.write(kml_text + "\n")
示例13: file
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import value [as 别名]
thisPlace.photos[0].get(maxheight=500, maxwidth=500)
placephoto = thisPlace.photos[0].url
print "Found {} at {}".format(placename, query_result.places[0].geo_location)
description = '<img src="{}" />'.format(placephoto)
if placename == "Unknown place":
continue
pubs += 1
if pubs > 0:
description = description + "Hey, it looks like you're at {} on a pub crawl. Want to see other bars in your area?".format(placename)
doc.append(
KML.Placemark(
KML.name("Stopped at: {}".format(placename)),
KML.description(description),
KML.ExtendedData(
KML.Data(KML.value(stop.time.seconds), name="Time Length")
),
KML.Point(
KML.coordinates(
"{},{}".format(stop.long, stop.lat)
)
)
))
# output a KML file
outfile = file('kmloutput.kml','w')
outfile.write(etree.tostring(doc, pretty_print=True))