本文整理汇总了Python中pykml.factory.KML_ElementMaker.key方法的典型用法代码示例。如果您正苦于以下问题:Python KML_ElementMaker.key方法的具体用法?Python KML_ElementMaker.key怎么用?Python KML_ElementMaker.key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pykml.factory.KML_ElementMaker
的用法示例。
在下文中一共展示了KML_ElementMaker.key方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: colourStyle
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import key [as 别名]
def colourStyle(self,
doc,
colourID,
colour_normal,
width_normal,
colour_highlight,
width_highlight):
"""
Append line style elements to a KML document.
Arguments:
doc: KML document to hold the new styles
colourID: the base ID for the styles
colour_normal: normal colour for the line
width_normal: normal width for the line
colour_highlight: highlighted colour for the line
width_highlight: highlighted width for the line
"""
doc.append(
KML.Style(
KML.IconStyle(
KML.Icon(),
id="no_icon_n"
),
KML.LineStyle(
KML.color(colour_normal),
KML.width(width_normal)
),
id=(colourID + '_n')
)
)
doc.append(
KML.Style(
KML.IconStyle(
KML.Icon(),
id="no_icon_h"
),
KML.LineStyle(
KML.color(colour_highlight),
KML.width(width_highlight)
),
id=(colourID + '_h')
)
)
doc.append(
KML.StyleMap(
KML.Pair(
KML.key('normal'),
KML.styleUrl('#' + colourID + '_n')
),
KML.Pair(
KML.key('highlight'),
KML.styleUrl('#' + colourID + '_h')
),
id=colourID
)
)
示例2: add_style
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import key [as 别名]
def add_style(doc, color, highlight):
# Add the normal style for the KML
doc.append(KML.Style(
KML.IconStyle(
KML.color(color),
KML.scale(1.1),
KML.Icon(
KML.href('http://www.gstatic.com/mapspro/images/stock/503-wht-blank_maps.png')
),
KML.hotspot('', x='16', y='31', xunits='pixels', yunits='insetPixels'),
),
KML.LabelStyle(
KML.scale(1.1)
),
id='icon-503-{}-normal'.format(color)))
# Add the highlight style for the KML
doc.append(KML.Style(
KML.IconStyle(
KML.color(highlight),
KML.scale(1.1),
KML.Icon(
KML.href('http://www.gstatic.com/mapspro/images/stock/503-wht-blank_maps.png')
),
KML.hotSpot('', x='16', y='31', xunits='pixels', yunits='insetPixels'),
),
KML.LabelStyle(
KML.scale(1.1)
),
id='icon-503-{}-highlight'.format(highlight)))
# Set the style map
doc.append(KML.StyleMap(
KML.Pair(
KML.key('normal'),
KML.styleUrl('#icon-503-{}-normal'.format(color))
),
KML.Pair(
KML.key('highlight'),
KML.styleUrl('#icon-503-{}-highlight'.format(highlight))
),
id='icon-503-{}'.format(color)))
return doc
示例3: create_style_map
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import key [as 别名]
def create_style_map(id_, n_style, h_style):
style = \
KML.StyleMap(
KML.Pair(
KML.key('normal'),
KML.styleUrl('#'+n_style.id),
),
KML.Pair(
KML.key('highlight'),
KML.styleUrl('#'+h_style.id),
),
id=id_,
)
return KmlStyle(id_, n_style.styles+h_style.styles+[style])
示例4: newKML
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import key [as 别名]
def newKML():
doc = KML.Document()
jet = plt.get_cmap('jet')
colorList = {}
for k in range(11):
colorList[k] = matplotlib.colors.rgb2hex(jet(k/10.0))[1:]
for (colorName, colorCode) in colorList.iteritems():
style = KML.Style(
KML.IconStyle(
KML.color("FF{}".format(colorCode)),
KML.scale(0.6)
),
KML.LabelStyle(KML.scale(0.5)),
id="house_{}".format(colorName)
)
styleMap = KML.StyleMap(
KML.Pair(
KML.key("normal"),
KML.styleUrl("house_{}".format(colorName))
),
id="stylemap_house_{}".format(colorName))
doc.append(style)
doc.append(styleMap)
return doc
示例5: create_stylemap
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import key [as 别名]
def create_stylemap(id_name, style1_id, style2_id, key1="normal", key2="highlight"):
out_smap = KML.StyleMap(
KML.Pair(
KML.key(key1),
KML.styleUrl("#" + style1_id),
),
KML.Pair(
KML.key(key2),
KML.styleUrl("#" + style2_id),
),
id=id_name,
)
#print "out_smap: " + str(out_smap)
#print "out_smap: " + str(type(out_smap))
return out_smap
示例6: _convert_
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import key [as 别名]
def _convert_(self,request):
from pykml.factory import KML_ElementMaker as KML
from lxml import etree
## create the database
if self.use_stat:
raise(NotImplementedError)
else:
db = self.sub.to_db(wkt=True,to_disk=True)
meta = request.ocg
if request.environ['SERVER_PORT']=='80':
portstr = ''
else:
portstr = ':{port}'.format(port=request.environ['SERVER_PORT'])
url='{protocol}://{server}{port}{path}'.format(
protocol='http',
port=portstr,
server=request.environ['SERVER_NAME'],
path=request.environ['PATH_INFO'],
)
description = (
'<table border="1">'
'<tbody>'
'<tr><th>Archive</th><td>{archive}</td></tr>'
'<tr><th>Emissions Scenario</th><td>{scenario}</td></tr>'
'<tr><th>Climate Model</th><td>{model}</td></tr>'
'<tr><th>Run</th><td>{run}</td></tr>'
'<tr><th>Output Variable</th><td>{variable}</td></tr>'
'<tr><th>Units</th><td>{units}</td></tr>'
'<tr><th>Start Time</th><td>{start}</td></tr>'
'<tr><th>End Time</th><td>{end}</td></tr>'
'<tr>'
'<th>Request URL</th>'
'<td><a href="{url}">{url}</a></td>'
'</tr>'
'<tr>'
'<th>Other Available Formats</th>'
'<td>'
'<a href="{url}">KML</a> - Keyhole Markup Language<br/>'
'<a href="{url_kmz}">KMZ</a> - Keyhole Markup Language (zipped)<br/>'
'<a href="{url_shz}">Shapefile</a> - ESRI Shapefile<br/>'
'<a href="{url_csv}">CSV</a> - Comma Separated Values (text file)<br/>'
'<a href="{url_json}">JSON</a> - Javascript Object Notation'
'</td>'
'</tr>'
'</tbody>'
'</table>'
).format(
archive=meta.archive.name,
scenario=meta.scenario,
model=meta.climate_model,
run=meta.run,
variable=meta.variable,
units=meta.variable.units,
simout=meta.simulation_output.netcdf_variable,
start=meta.temporal[0],
end=meta.temporal[-1],
operation=meta.operation,
url=url,
url_kmz=url.replace('.kml', '.kmz'),
url_shz=url.replace('.kml', '.shz'),
url_csv=url.replace('.kml', '.csv'),
url_json=url.replace('.kml', '.geojson'),
)
##### TODO: build linked urls on the fly
#from piston.emitters import Emitter
#Emitter.EMITTERS.keys()
#['xml', 'sqlite', 'nc', 'shz', 'kml', 'kcsv', 'django', 'json', 'html', 'meta', 'lshz', 'csv', 'pickle', 'kmz']
doc = KML.kml(
KML.Document(
KML.name('Climate Simulation Output'),
KML.open(1),
KML.description(description),
KML.snippet(
'<i>Click for metadata!</i>',
maxLines="2",
),
KML.StyleMap(
KML.Pair(
KML.key('normal'),
KML.styleUrl('#style-normal'),
),
KML.Pair(
KML.key('highlight'),
KML.styleUrl('#style-highlight'),
),
id="smap",
),
KML.Style(
KML.LineStyle(
KML.color('ff0000ff'),
KML.width('2'),
),
KML.PolyStyle(
KML.color('400000ff'),
),
id="style-normal",
#.........这里部分代码省略.........
示例7: _makeStyle
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import key [as 别名]
def _makeStyle(name, color):
"""
Build swath pairs and map...
"""
# style for the normal state of a swath
stylen = KML.Style(
KML.IconStyle(
KML.scale('0.4'),
KML.Icon(
KML.href('http://maps.google.com/mapfiles/kml/shapes/star.png')
)
),
KML.LineStyle(
KML.color('ff{}'.format(color)),
KML.width(2.0)
),
KML.LabelStyle(
KML.color('990000ff'),
KML.width('2')
),
KML.PolyStyle(
KML.color('00{}'.format(color)),
KML.fill('1'),
KML.outline('1')
),
id='{}n'.format(name)
)
# style for the 'mouse-over' state of a swath
styleh = KML.Style(
KML.IconStyle(
KML.scale('0.8'),
KML.Icon(
KML.href('http://maps.google.com/mapfiles/kml/shapes/star.png')
)
),
KML.LineStyle(
KML.color('ffff4158'),
KML.width(1.5)
),
KML.LabelStyle(
KML.color('990000ff'),
KML.width('2')
),
KML.PolyStyle(
KML.color('fff7fff'),
KML.fill('1'),
KML.outline('1')
),
id='{}h'.format(name)
)
# mapping of above styles
stylem = KML.StyleMap(
KML.Pair(
KML.key('normal'),
KML.styleUrl('#{}n'.format(name))
),
KML.Pair(
KML.key('highlight'),
KML.styleUrl('#{}h'.format(name))
),
id='{}stylemap'.format(name)
)
# Expand to make the style simpler...
# kurl = 'http://maps.google.com/mapfiles/kml/shapes/star.png'
# style1 = KML.Style(
# KML.IconStyle(
# KML.scale('0.4'),
# KML.Icon(
# KML.href(kurl)
# )
# ),
# KML.LabelStyle(
# KML.color('990000ff'),
# KML.width('2')
# ),
# KML.LineStyle(
# KML.color('ff0000ff'),
# KML.width(2.0)
# ),
# KML.PolyStyle(
# KML.color('997f7fff'),
# KML.fill('1'),
# KML.outline('1')
# ),
# id='{}1'.format(name),
# )
return stylen, styleh, stylem
示例8: writeKML
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import key [as 别名]
#.........这里部分代码省略.........
print "Error Parsing URL<%(Page)s>: http://eol.jsc.nasa.gov/scripts/sseop/PhotoKML.pl?photo=%(Mission)s-%(Roll)s-%(Frame)s"%image
else:
placemarks += [placeMaker(attr)]
ct += 1
if ct%10 == 0:
sys.stdout.write(".")
sys.stdout.flush()
#create the kml file
doc = K.kml(
K.Document(
K.Style(
K.LabelStyle(K.scale("0")),
K.IconStyle(
K.scale(1.0),
K.Icon(K.href("http://maps.google.com/mapfiles/kml/shapes/camera.png"))
),
K.BalloonStyle(
K.text(
"""<![CDATA[<P><STRONG><FONT size=4>$[MRF]</FONT</STRONG></P><P><IMG alt="$[MRF] image" src="$[IMG]" align=top></P>
<P> </P>
<P><STRONG><FONT size=4>Astronaut Photograph</FONT></STRONG></P>
<P><STRONG>Features</STRONG>: $[features]</P>
<P><STRONG>Acquired</STRONG>: $[YYYYMMDD] (YYYYMMDD), $[HHMMSS] (HHMMSS) GMT</P>
<P><STRONG>Camera Tilt</STRONG>: $[Camera_Tilt] <STRONG>Camera Lens</STRONG>: $[Camera_Lens] <STRONG>Camera</STRONG>: $[Camera]</P>
<P><STRONG>Sun Azimuth</STRONG>: $[Sun_Azimuth] <STRONG>Sun Elevation</STRONG>: $[Sun_Elevation] <STRONG>Spacecraft Altitude</STRONG>: $[Spacecraft_Altitude] nautical miles</P>
<P><STRONG>Database Entry Page</STRONG>: <FONT face=Arial><A href='$[DB_Entry]'>$[DB_Entry]</A></FONT></P>
<P><STRONG><FONT color="red">Astronaut photographs are not georectified, and therefore have orientation and scale independent from Google Earth base imagery.</FONT></STRONG></P>
<P> </P>
<P align=center><FONT face=Arial> Image Science and Analysis Laboratory, NASA-Johnson Space Center. "The Gateway to Astronaut Photography of Earth." <BR><A href="http://eol.jsc.nasa.gov/"><IMG height=71 alt="Crew Earth Observations" src="http://eol.jsc.nasa.gov/images/CEO.jpg" width=82 align=left border=0></A> <A href="http://www.nasa.gov/" target=_blank><IMG height=71 alt="NASA meatball" src="http://eol.jsc.nasa.gov/images/NASA.jpg" width=82 align=right border=0></A> <!--{PS..3}--><!--{PS..4}--><!--{PS..6}--><BR>Send questions or comments to the NASA Responsible Official at <A href="mailto:[email protected]">[email protected]</A><BR>Curator: <A onclick="window.open('/credits.htm', 'win1', config='height=598, width=500')" href="http://eol.jsc.nasa.gov/#" alt="Web Team">Earth Sciences Web Team</A><BR>Notices: <A href="http://www.jsc.nasa.gov/policies.html" target=_blank>Web Accessibility and Policy Notices, NASA Web Privacy Policy</A><BR><!--{PS..5}--></FONT></P>
$[geDirections]"""
)
),
id="sn_style"
),
K.Style(
K.LabelStyle(K.scale("1.1")),
K.IconStyle(
K.scale(1.2),
K.Icon(K.href("http://maps.google.com/mapfiles/kml/shapes/camera.png"))
),
K.BalloonStyle(
K.text(
"""<![CDATA[<P><STRONG><FONT size=4>$[MRF]</FONT</STRONG></P><P><IMG alt="$[MRF] image" src="$[IMG]" align=top></P>
<P> </P>
<P><STRONG><FONT size=4>Astronaut Photograph</FONT></STRONG></P>
<P><STRONG>Features</STRONG>: $[features]</P>
<P><STRONG>Acquired</STRONG>: $[YYYYMMDD] (YYYYMMDD), $[HHMMSS] (HHMMSS) GMT</P>
<P><STRONG>Camera Tilt</STRONG>: $[Camera_Tilt] <STRONG>Camera Lens</STRONG>: $[Camera_Lens] <STRONG>Camera</STRONG>: $[Camera]</P>
<P><STRONG>Sun Azimuth</STRONG>: $[Sun_Azimuth] <STRONG>Sun Elevation</STRONG>: $[Sun_Elevation] <STRONG>Spacecraft Altitude</STRONG>: $[Spacecraft_Altitude] nautical miles</P>
<P><STRONG>Database Entry Page</STRONG>: <FONT face=Arial><A href='$[DB_Entry]'>$[DB_Entry]</A></FONT></P>
<P><STRONG><FONT color="red">Astronaut photographs are not georectified, and therefore have orientation and scale independent from Google Earth base imagery.</FONT></STRONG></P>
<P> </P>
<P align=center><FONT face=Arial> Image Science and Analysis Laboratory, NASA-Johnson Space Center. "The Gateway to Astronaut Photography of Earth." <BR><A href="http://eol.jsc.nasa.gov/"><IMG height=71 alt="Crew Earth Observations" src="http://eol.jsc.nasa.gov/images/CEO.jpg" width=82 align=left border=0></A> <A href="http://www.nasa.gov/" target=_blank><IMG height=71 alt="NASA meatball" src="http://eol.jsc.nasa.gov/images/NASA.jpg" width=82 align=right border=0></A> <!--{PS..3}--><!--{PS..4}--><!--{PS..6}--><BR>Send questions or comments to the NASA Responsible Official at <A href="mailto:[email protected]">[email protected]</A><BR>Curator: <A onclick="window.open('/credits.htm', 'win1', config='height=598, width=500')" href="http://eol.jsc.nasa.gov/#" alt="Web Team">Earth Sciences Web Team</A><BR>Notices: <A href="http://www.jsc.nasa.gov/policies.html" target=_blank>Web Accessibility and Policy Notices, NASA Web Privacy Policy</A><BR><!--{PS..5}--></FONT></P>
$[geDirections]"""
)
),
id="sh_style"
),
K.StyleMap(
K.Pair(
K.key("normal"),
K.styleUrl("#sn_style")
),
K.Pair(
K.key("highlight"),
K.styleUrl("#sh_style")
),
id="sm_style"
),
*placemarks
)
)
from lxml import etree
kmlfile.write(etree.tostring(doc))
print "\nDone!"
示例9: validate
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import key [as 别名]
def validate():
table = {}
reader = open('{}/gtfs/files/shapes.txt'.format(REPORT_PATH))
for line in reader:
shape, lat, lng, seq = re.split(',', line.rstrip())
if shape == 'shape_id':
continue
if shape not in table:
table[shape] = {}
table[shape][seq] = (lat, lng)
# For each shape
for shape in table:
doc = KML.Document(KML.name('Shape {}'.format(shape)))
# For each sequence in order
for seq in sorted(table[shape].keys()):
# Add a placemark in the KML file
doc.append(KML.Placemark(
KML.name('{}'.format(seq)),
KML.styleUrl('#icon-503-777777'),
KML.Point(
KML.coordinates('{},{},0'.format(table[shape][seq][1], table[shape][seq][0]))
)
))
# Add the normal style for the KML
doc.append(KML.Style(
KML.IconStyle(
KML.color('ff777777'),
KML.scale(1.1),
KML.Icon(
KML.href('http://www.gstatic.com/mapspro/images/stock/503-wht-blank_maps.png')
),
KML.hotspot('', x='16', y='31', xunits='pixels', yunits='insetPixels'),
),
KML.LabelStyle(
KML.scale(1.1)
),
id='icon-503-777777-normal'))
# Add the highlight style for the KML
doc.append(KML.Style(
KML.IconStyle(
KML.color('ff555555'),
KML.scale(1.1),
KML.Icon(
KML.href('http://www.gstatic.com/mapspro/images/stock/503-wht-blank_maps.png')
),
KML.hotSpot('', x='16', y='31', xunits='pixels', yunits='insetPixels'),
),
KML.LabelStyle(
KML.scale(1.1)
),
id='icon-503-555555-highlight'))
# Set the style map
doc.append(KML.StyleMap(
KML.Pair(
KML.key('normal'),
KML.styleUrl('#icon-503-777777-normal')
),
KML.Pair(
KML.key('highlight'),
KML.styleUrl('#icon-503-777777-highlight')
),
id='icon-503-777777'))
# Send KML file to string and replace spurious \
kml = KML.kml(doc)
kml = etree.tostring(kml, pretty_print=True).decode('utf-8', errors='strict').replace('\\', '')
# Add encoding line
final = ["<?xml version='1.0' encoding='UTF-8'?>"]
# Unescape the CDATA description HTML
for line in re.split('\n', kml):
if re.search('\<description\>', line):
final.append(unescape(line))
else:
final.append(line)
# Write the file
set_directory('{}/gtfs/test'.format(REPORT_PATH))
writer = open('{}/gtfs/test/shape_{}.kml'.format(REPORT_PATH, shape), 'w')
writer.write('\n'.join(final))
示例10: print
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import key [as 别名]
lon.append("-" + coordinates[2][:-7])
else:
lon.append(coordinates[2][:-7])
hits.append(pagehits[0][:-2])
# print(URLs.index(URL)) # to count iterations
### KML file
### Defines a document style that hides names until mouse-over.
### With 12,000+ points, this makes viewing the file much smoother.
### Based on http://stackoverflow.com/questions/13378030/displaying-names-on-the-map-using-kml
kmlobj = KML.kml(
KML.Document(
KML.Style(KML.LabelStyle(KML.scale(0)), id="sn_hide"),
KML.Style(KML.LabelStyle(KML.scale(1)), id="sh_style"),
KML.StyleMap(
KML.Pair(KML.key("normal"), KML.styleUrl("#sn_hide")),
KML.Pair(KML.key("highlight"), KML.styleUrl("#sh_style")),
id="msn_hide",
),
)
)
### Places the results of the loops into the KML document as points.
for i in range(0, len(lat)):
if lat[i] != "":
kmlobj.Document.append(
KML.Placemark(
KML.Style(
KML.IconStyle(
KML.scale(0.5),
KML.Icon(KML.href("http://crec.unl.edu/images/Icons/OA%20Mountain%201%20Red.png")),
)