Ale*_*x S 6 python maps kml google-earth simplekml
我正在尝试使用simplekml将一堆地理标记照片放入 KML 文件(实际上是 KMZ 文件)中,以便在 Google Earth 中查看。我已经获得了要显示的位置,但是当我尝试将图像放入“描述”中时,因此当我单击图像出现的位置时,它不起作用。只有一张空白图像。我正在尝试使用此处显示的 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)
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我几乎从上面页面的说明中剪切并粘贴了使用“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>
Run Code Online (Sandbox Code Playgroud)
(我已经删除了除其中一点之外的所有内容)非常感谢,亚历克斯
可能是因为您编写的 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></Placemark></Document></kml>
Run Code Online (Sandbox Code Playgroud)
如果放置地点标记标签后上述代码不起作用,请尝试使用气球样式而不是描述标签尝试使用以下代码
<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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3869 次 |
| 最近记录: |