本文整理汇总了Python中pykml.factory.KML_ElementMaker.text方法的典型用法代码示例。如果您正苦于以下问题:Python KML_ElementMaker.text方法的具体用法?Python KML_ElementMaker.text怎么用?Python KML_ElementMaker.text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pykml.factory.KML_ElementMaker
的用法示例。
在下文中一共展示了KML_ElementMaker.text方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_getXmlWithCDATA
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import text [as 别名]
def test_getXmlWithCDATA(self):
'''tests the format_as_cdata function'''
from pykml.util import format_xml_with_cdata
kmlobj = KML.kml(
KML.Document(
KML.Placemark(
KML.name('foobar'),
KML.styleUrl('#big_label'),
KML.description('<html>'),
KML.text('<html>'),
KML.linkDescription('<html>'),
KML.displayName('<html>')
)
)
)
self.assertEqual(
etree.tostring(format_xml_with_cdata(kmlobj)),
'<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>'
'<Placemark>'
'<name>foobar</name>'
'<styleUrl>#big_label</styleUrl>'
'<description><![CDATA[<html>]]></description>'
'<text><![CDATA[<html>]]></text>'
'<linkDescription><![CDATA[<html>]]></linkDescription>'
'<displayName><![CDATA[<html>]]></displayName>'
'</Placemark>'
'</Document>'
'</kml>'
)
示例2: buildKML
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import text [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: get_balloon_style
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import text [as 别名]
def get_balloon_style():
"""
A separate instance of KML.BalloonStyle() needs to be created for each
KML.Style(). The KML.text() will be formatted as CDATA
"""
return KML.BalloonStyle(
KML.text("""
<table Border=1>
<tr><th>Earthquake ID</th><td>$[id_]</td></tr>
<tr><th>Magnitude</th><td>$[mag_]</td></tr>
<tr><th>Depth</th><td>$[depth_]</td></tr>
<tr><th>Datetime</th><td>$[time_]</td></tr>
<tr><th>Coordinates</th><td>($[longitude_],$[latitude_])</td></tr>
<tr><th>Region</th><td>$[place_]</td></tr>
</table>"""),
)
示例4: test_getXmlWithCDATA
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import text [as 别名]
def test_getXmlWithCDATA(self):
"""tests the format_as_cdata function"""
from pykml.util import format_xml_with_cdata
kml_obj = KML.kml(
KML.Document(
KML.Placemark(
KML.name('foobar'),
KML.styleUrl('#big_label'),
KML.description('<html>'),
KML.text('<html>'),
KML.linkDescription('<html>'),
KML.displayName('<html>')
)
)
)
root = format_xml_with_cdata(kml_obj)
data = etree.tostring(root, encoding='utf-8', xml_declaration=True)
expected = \
'<?xml version="1.0" encoding="UTF-8"?>' \
'<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>' \
'<Placemark>' \
'<name>foobar</name>' \
'<styleUrl>#big_label</styleUrl>' \
'<description><![CDATA[<html>]]></description>' \
'<text><![CDATA[<html>]]></text>' \
'<linkDescription><![CDATA[<html>]]></linkDescription>' \
'<displayName><![CDATA[<html>]]></displayName>' \
'</Placemark>' \
'</Document>' \
'</kml>'
expected = expected.encode('utf-8')
self.assertXmlEquivalentOutputs(data, expected)
示例5: _convert_
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import text [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",
#.........这里部分代码省略.........
示例6: writeKML
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import text [as 别名]
def writeKML(fileName,images):
'''Writes the search results out as a kml file containing placemarks'''
ct = 0
kmlfile = open(fileName,'w')
placemarks = []
print "\nWriting " + repr(len(images)) + " images to kml"
#make a placemark for each image
for image in images:
attr = None
try:
attr = ParsePlacemark("http://eol.jsc.nasa.gov/scripts/sseop/PhotoKML.pl?photo=%(Mission)s-%(Roll)s-%(Frame)s"%image)
except Exception:
print "Failed to open URL<%(Page)s>: http://eol.jsc.nasa.gov/scripts/sseop/PhotoKML.pl?photo=%(Mission)s-%(Roll)s-%(Frame)s"%image
print Exception
if attr == None:
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(
#.........这里部分代码省略.........
示例7: makeExtendedDataElements
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import text [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
# create a KML document with a folder and a default style
stylename = "earthquake-balloon-style"
balloonstyle = KML.BalloonStyle(
KML.text("""
<table Border=1>
<tr><th>Earthquake ID</th><td>$[Eqid_]</td></tr>
<tr><th>Magnitude</th><td>$[Magnitude_]</td></tr>
<tr><th>Depth</th><td>$[Depth_]</td></tr>
<tr><th>Datetime</th><td>$[Datetime_]</td></tr>
<tr><th>Coordinates</th><td>($[Lat_],$[Lat_])</td></tr>
<tr><th>Region</th><td>$[Region_]</td></tr>
</table>"""
),
)
doc = KML.Document()
iconstyles = [
[2,'ff000000'],
[3,'ffff0000'],
[4,'ff00ff55'],
[5,'ffff00aa'],
[6,'ff00ffff'],
[7,'ff0000ff'],
示例8: create_style
# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import text [as 别名]
def create_style(id_name, poly_colour, line_colour="FF000000", line_width="2"):
# create a KML document with a folder and a default style
stylename = "ballooon_style"
balloon_text = """
<font size="5"><b>$[name]</b></font><br>
<br>
<table width="500" border="1" cellspacing="0" cellpadding="6">
<col width="150">
<col width="350">
<tr align="left" valign="top">
<td><b>Dates:</b></td>
<td>$[dates]</td>
</tr>
<tr align="left" valign="top">
<td><b>Status:</b></td>
<td>$[status]</td>
</tr>
<tr align="left" valign="top">
<td><b>History:</td>
<td>$[history]</td>
</tr>
<tr align="left" valign="top">
<td><b>1912 Address:</td>
<td>$[addrss]</td>
</tr>
<tr align="left" valign="top">
<td><b>Sources:</td>
<td>$[sources]</td>
</tr>
</table><br>
<table width="500" border="1" cellspacing="0" cellpadding="6">
<tr align="center" valign="top">
<td><b>Photos</b></td>
</tr>
<tr align="left" valign="top">
<td>$[photos]</td>
</tr>
</table>"""
out_style = KML.Style(
KML.IconStyle(
KML.scale(1.1),
KML.Icon(
KML.href("http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png"),
),
KML.hotSpot(x="20",y="2",xunits="pixels",yunits="pixels"),
),
KML.LineStyle(
KML.color(line_colour),
KML.width(line_width),
),
KML.PolyStyle(
KML.color(poly_colour),
),
KML.BalloonStyle(
KML.text(balloon_text),
),
id=id_name,
)
#print "out_style: " + str(out_style)
return out_style