我正在使用 simplekml 1.3.5(它是用于生成 KML 的 Python 库)编写一个用于气候数据可视化的简单脚本。
import simplekml
kml_filename ='sample.kml'
kml = simplekml.Kml(open=1)
model = kml.newmodel(name="test_model")
model.altitudemode = simplekml.AltitudeMode.absolute
model.location.altitude = 500
model.location.latitude = 36.939055000000025
model.location.longitude = 140.037
model.orientation.heading = 90
model.orientation.tilt = 0
model.orientation.roll = 0
model.scale.x = 1000
model.scale.y = 1000
model.scale.z = 1000
model.link.href = "images/canvas.dae"
model.resourcemap.newalias(targethref="instance.png", sourcehref="mapping.png")
kml.save(kml_filename)
此代码生成以下 KML。
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">
<Document id="1672">
<open>1</open>
<Placemark id="1674">
<name>test_model</name>
<Model id="1673">
<altitudeMode>absolute</altitudeMode>
<Location>
<longitude>140.037</longitude>
<latitude>36.939055000000025</latitude>
<altitude>500</altitude>
</Location>
<Orientation>
<heading>90</heading>
<tilt>0</tilt>
<roll>0</roll>
</Orientation>
<Scale>
<x>1000</x>
<y>1000</y>
<z>1000</z>
</Scale>
<Link id="1678">
<href>images/canvas.dae</href>
</Link>
<ResourceMap>
<targetHref>instance.png</targetHref>
<sourceHref>mapping.png</sourceHref>
</ResourceMap>
</Model>
</Placemark>
</Document>
</kml>
它看起来几乎不错。但是ResourceMap 标签中没有输出Alias标签。我期望以下输出。
<ResourceMap>
<Alias>
<targetHref>instance.png</targetHref>
<sourceHref>mapping.png</sourceHref>
</Alias>
</ResourceMap>
谷歌地球没有显示没有这个标签的纹理。(并手动添加标签,可以显示。)
如何使用 simplekml 在 KML 中输出标签?