5

simplekmlを使用して、ジオタグ付きの写真をKMLファイル(実際にはKMZファイル)に入れてGoogleEarthで表示しようとしています。表示する場所を取得しましたが、「説明」に画像を入れようとすると、画像が表示される場所をクリックしても機能しません。空白の画像があります。ここに示すaddfile()コマンドを使用してこれを実行しようとしています。私のコードは次のようになります。

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に手動で変更しようとしましたが、修正されませんでした。生成されたKMZdoc.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>&lt;img src="files/DSC00001.JPG" alt="picture" width="400" height="300" align="left" /&gt;</description>
    <Point id="geom_0"><coordinates>18.9431816667,9.44355222222,0.0</coordinates>
    </Point></Document></kml>

(1つを除いてすべて削除しました)どうもありがとう、アレックス

4

1 に答える 1

2

作成した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>&lt;img src="files/DSC00001.JPG" alt="picture" width="400" height="300" align="left" /&gt;</description>
    <Point id="geom_0"><coordinates>18.9431816667,9.44355222222,0.0</coordinates>
    </Point></Placemark></Document></kml>

プレースマークタグを配置した後の上記のコードが機能しない場合は、説明タグの代わりにバルーンスタイルを試してください。以下のコードを試してください。

<kml xmlns="http://www.opengis.net/kml/2.2"
     xmlns:gx="http://www.google.com/kml/ext/2.2" 
     xmlns:kml="http://www.opengis.net/kml/2.2" 
     xmlns:atom="http://www.w3.org/2005/Atom"
>
<Document id="feat_1">
<Placemark id="feat_2">
<name>DSC00001.JPG</name>
<Style>
<BalloonStyle>
<text><![CDATA[
 <table width=100% cellpadding=0 cellspacing=0>
  <tr><td><img width=100% src='files/DSC00001.jpg' /></td></tr></table>]]>
</text>
</BalloonStyle>
</Style> 
<Point id="geom_0">
<coordinates>18.9431816667,9.44355222222</coordinates>
</Point>
</Placemark>
</Document>
</kml>
于 2013-03-14T11:08:53.930 に答える