pythonkmlgoogle-earthsimplekml

AttributeError: 'Kml' object has no attribute 'style'


I am learning how to use simplekml and i am having a hard time adding a particular icon on a point.

this is my code:

import simplekml
points_kml = simplekml.Kml()
points_kml.newpoint(name="Kirstenbosch", coords=[(18.432314,-33.988862)])
points_kml.style.iconstyle.icon.href = 'http://maps.google.com/mapfiles/kml/paddle/ltblu-circle.png'
points_kml.save("botanicalgarden.kml")

and this is what i receive in return:

  File c:\users\marcelo\downloads\untitled0.py:4
    points_kml.style.iconstyle.icon.href = 'http://maps.google.com/mapfiles/kml/paddle/ltblu-circle.png'

AttributeError: 'Kml' object has no attribute 'style'

I double checked the documentation and the icon link but everything is exactly how it shows in the documentation...

I just wanted a kml file with a single point and a particular icon.


Solution

  • The error is telling you what you need to know. The Kml object has no style on it.

    Looking at these docs you might be trying to reference a point? You're creating one but you never save it to anything. An example from those docs

    pnt = kml.newpoint(name="Kirstenbosch", description="A botanical Garden",
                       coords=[(18.432314,-33.988862)])  # lon, lat optional height
    

    Some code from those docs touching the style from a point

    pnt.style.iconstyle.icon.href = None