python SimpleXML更改newpoint的形状

2024-06-28 19:02:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将默认的黄色图钉放置标记更改为矩形或像素。 运行下面的代码后,我仍然得到默认的黄色图钉放置标记

import simplekml
#from simplekml import Shape,Color
kml = simplekml.Kml()
pt2=kml.newpoint(name="test", coords=[(18.432314,-33.988862)])
#both code below are not working.
pt2.style.iconstyle.icon.shape='rectangle'
pt2.style.iconstyle.shape='rectangle'
pt2.style.iconstyle.color='ffffff00'
kml.save("test.kml")

Tags: 代码标记testimportstyle像素kmlshape
1条回答
网友
1楼 · 发布于 2024-06-28 19:02:36

要更改图标的形状,请更改图标URL的iconstyle的href属性。可以查看在Google Earth中使用的图标列表here

在上面发布的代码中,“shape”既不是icon的属性,也不是iconstyle的一部分。icon和iconstyle属性的结构由KML spec定义

已更新代码以使用自定义图标样式输出KML:

import simplekml

kml = simplekml.Kml()
pt2 = kml.newpoint(name="test", coords=[(18.432314,-33.988862)])
# use square icon
pt2.style.iconstyle.icon.href = 'http://maps.google.com/mapfiles/kml/shapes/placemark_square.png'
# set color of icon to be cyan (RGB=#00ffff)
pt2.style.iconstyle.color ='ffffff00' # aabbggrr
print("Output: test.kml")
kml.save("test.kml")

相关问题 更多 >