我试图使用simplekml将一堆带地理标记的照片放入KML文件(实际上是KMZ文件),以便在Google地球中进行查看。我已经获得了要显示的位置,但是当我尝试将图像放入“描述”中时,因此当我单击图像出现的位置时,它不起作用。只有一张空白图片。我试图通过使用显示here的addfile()命令来完成。我的代码如下所示:在simplekml中显示本地图像
import os, simplekml
path = r'C:\Users\as\Desktop\testpics'
kml = simplekml.Kml()
for (dirpath, dirnames, filenames) in os.walk(path):
for filename in filenames:
fullpath = os.path.join(dirpath, filename)
try:
Lat, Long, Alt = GetLatLong(fullpath) #Didn't include this function, but it appears to work
except:
Lat, Long, Alt = (None, None, None)
if Lat: #Only adds to kml if it has Lat value.
x, y = (FormatLatLong(Lat), FormatLatLong(Long)) #puts into decimal coords
point = kml.newpoint(name = filename , coords = [(y,x)])
picpath = kml.addfile(fullpath)
point.description = '<img src="' + picpath +'" alt="picture" width="400" height="300" align="left" />'
kml.savekmz("kmltest2.kmz", format = False)
正如你所看到的,我已经差不多剪切和粘贴使用“addfile”从上面的页面上的说明进行操作。 point.description行似乎是事情出错的地方。
图片被添加到kmz存档,但它们没有出现在位置的气泡中。我认为这可能是因为我在Windows 7上这样做,并且斜杠是倒退的,但我尝试手动将files \ image.jpg更改为files/image.jpg,但没有修复它。产生的KMZ文件对于doc.kml看起来是这样的:
<kml xmlns="http://www.opengis.net/kml/2.2"xmlns:gx="http://www.google.com/kml/ext/2.2">
<Document id="feat_1">
<Placemark id="feat_2">
<name>DSC00001.JPG</name>
<description><img src="files/DSC00001.JPG" alt="picture" width="400" height="300" align="left" /></description>
<Point id="geom_0"><coordinates>18.9431816667,9.44355222222,0.0</coordinates>
</Point></Document></kml>
(我已经删除了所有,但分之一) 非常感谢,亚历克斯
我也试过选项1(HTTP: //support.google.com/earth/bin/answer.py?hl=zh_CN&answer=1061393),未修复该问题。 – 2013-03-13 23:35:00