我試圖使用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